├── SpecFlow.Assist.Dynamic.Specs ├── specflow.json ├── Steps │ ├── State.cs │ ├── StepArgumentTransformationSteps.cs │ ├── DynamicSetCreationSteps.cs │ ├── DynamicInstanceComparisionSteps.cs │ ├── DynamicSetComparisonSteps.cs │ └── DynamicInstanceCreationSteps.cs ├── DynamicSetFromTable.feature ├── SpecFlow.Assist.Dynamic.Specs.csproj ├── ReservedCharsInCSharp.feature ├── ColumnNameToPropertyConventions.feature ├── DynamicInstancesFromTable.feature ├── CreateDynamicSetsAndInstancesWithStepArgumentTransformation.feature ├── ComparingDynamicInstances.feature ├── ValueConversions.feature ├── ComparingDynamicSets.feature ├── DynamicSetFromTable.feature.cs ├── ReservedCharsInCSharp.feature.cs ├── DynamicInstancesFromTable.feature.cs ├── ColumnNameToPropertyConventions.feature.cs ├── CreateDynamicSetsAndInstancesWithStepArgumentTransformation.feature.cs ├── ComparingDynamicInstances.feature.cs ├── ValueConversions.feature.cs └── ComparingDynamicSets.feature.cs ├── SpecFlow.Assist.Dynamic ├── DynamicInstanceFromTableException.cs ├── pack.sh ├── DynamicInstanceComparisonException.cs ├── DynamicSetComparisonException.cs ├── DynamicStepArgumentTransformations.cs ├── SpecFlow.Assist.Dynamic.nuspec ├── SpecFlow.Assist.Dynamic.csproj └── DynamicTableHelpers.cs ├── .gitignore ├── LICENSE ├── .vscode ├── tasks.json └── launch.json ├── readme.md └── SpecFlow.Assist.Dynamic.sln /SpecFlow.Assist.Dynamic.Specs/specflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "stepAssemblies": [ 3 | { 4 | "assembly": "SpecFlow.Assist.Dynamic" 5 | } 6 | ] 7 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/DynamicInstanceFromTableException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TechTalk.SpecFlow.Assist 4 | { 5 | public class DynamicInstanceFromTableException : Exception 6 | { 7 | public DynamicInstanceFromTableException(string message) : base(message) { } 8 | } 9 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf ./SpecFlow.Assist.Dynamic/bin/Release 4 | 5 | dotnet clean 6 | dotnet test 7 | dotnet build -c Release 8 | 9 | dotnet pack ./SpecFlow.Assist.Dynamic.csproj -p:NuspecFile=./SpecFlow.Assist.Dynamic.nuspec -c Release 10 | 11 | open ./bin/Release -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/State.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TechTalk.SpecFlow; 4 | 5 | namespace Specs.Steps 6 | { 7 | public class State 8 | { 9 | public dynamic OriginalInstance; 10 | 11 | public IList OriginalSet; 12 | 13 | public Exception CurrentException; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.*~ 3 | project.lock.json 4 | .DS_Store 5 | *.pyc 6 | 7 | # Visual Studio Code 8 | .vscode 9 | 10 | # User-specific files 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | build/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | msbuild.log 28 | msbuild.err 29 | msbuild.wrn 30 | 31 | # Visual Studio 2015 32 | .vs/ -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/DynamicInstanceComparisonException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TechTalk.SpecFlow.Assist 5 | { 6 | public class DynamicInstanceComparisonException : Exception 7 | { 8 | public IList Differences { get; private set; } 9 | 10 | public DynamicInstanceComparisonException(IList diffs) 11 | : base("There were some difference between the table and the instance") 12 | { 13 | Differences = diffs; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/DynamicSetComparisonException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TechTalk.SpecFlow.Assist 5 | { 6 | public class DynamicSetComparisonException : Exception 7 | { 8 | public IList Differences { get; private set; } 9 | 10 | public DynamicSetComparisonException(string message) : base(message) { } 11 | 12 | public DynamicSetComparisonException(string message, IList differences) : base(message) 13 | { 14 | Differences = differences; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/DynamicSetFromTable.feature: -------------------------------------------------------------------------------- 1 | Feature: Create dynamic sets objects from SpecFlow table 2 | In order to write only code that matters 3 | As a SpecFlow developer 4 | I want SpecFlow to create set of dynamic objects from a table row 5 | 6 | Scenario: Create set of dynamic objects 7 | When I create a set of dynamic instances from this table 8 | | Name | Age | Birth date | Length in meters | 9 | | Marcus | 39 | 1972-10-09 | 1.96 | 10 | | Albert | 3 | 2008-01-24 | 1.03 | 11 | | Gustav | 1 | 2010-03-19 | 0.84 | 12 | | Arvid | 1 | 2010-03-19 | 0.85 | 13 | Then I should have a list of 4 dynamic objects 14 | And the 1 item should have Name equal to 'Marcus' 15 | And the 2 item should have Age equal to '3' 16 | And the 3 item should have BirthDate equal to '2010-03-19' 17 | And the 4 item should have LengthInMeters equal to '0.85' -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/DynamicStepArgumentTransformations.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using TechTalk.SpecFlow; 4 | using TechTalk.SpecFlow.Assist; 5 | 6 | namespace SpecFlow.Assist.Dynamic 7 | { 8 | [Binding] 9 | public class DynamicStepArgumentTransformations 10 | { 11 | 12 | [StepArgumentTransformation] 13 | public IEnumerable TransformToEnumerable(Table table) 14 | { 15 | return table.CreateDynamicSet(); 16 | } 17 | 18 | [StepArgumentTransformation] 19 | public IList TransformToList(Table table) 20 | { 21 | return table.CreateDynamicSet().ToList(); 22 | } 23 | 24 | [StepArgumentTransformation] 25 | public dynamic TransformToDynamicInstance(Table table) 26 | { 27 | return table.CreateDynamicInstance(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/SpecFlow.Assist.Dynamic.Specs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.4.2 5 | 6 | 7 | 8 | netcoreapp2.2 9 | 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | PreserveNewest 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Marcus Hammarberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/SpecFlow.Assist.Dynamic.Specs/SpecFlow.Assist.Dynamic.Specs.csproj" 11 | ], 12 | "problemMatcher": "$tsc" 13 | }, 14 | { 15 | "label": "publish", 16 | "command": "dotnet", 17 | "type": "process", 18 | "args": [ 19 | "publish", 20 | "${workspaceFolder}/SpecFlow.Assist.Dynamic.Specs/SpecFlow.Assist.Dynamic.Specs.csproj" 21 | ], 22 | "problemMatcher": "$tsc" 23 | }, 24 | { 25 | "label": "watch", 26 | "command": "dotnet", 27 | "type": "process", 28 | "args": [ 29 | "watch", 30 | "run", 31 | "${workspaceFolder}/SpecFlow.Assist.Dynamic.Specs/SpecFlow.Assist.Dynamic.Specs.csproj" 32 | ], 33 | "problemMatcher": "$tsc" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ReservedCharsInCSharp.feature: -------------------------------------------------------------------------------- 1 | Feature: ReservedCharsInCSharp 2 | In order to be able to write more expressive meaningful scenarios 3 | As a scenario writer 4 | I want to be able to use any character, including reserved words 5 | 6 | @wip 7 | Scenario: Using reserved C# characters in column names 8 | When I create a dynamic instance from this table 9 | | C$harp n@me (with strange chars) | 10 | | A value | 11 | Then the CharpNmeWithStrangeChars property should equal 'A value' 12 | 13 | 14 | @wip 15 | Scenario: Only alfa numeric characters, plus underscore is allowed in variable names 16 | When I create a dynamic instance from this table 17 | | My_Nice_Variable | My $$ Variable (needs clean up) | 18 | | A value | Another value | 19 | Then the My_Nice_Variable property should equal 'A value' 20 | And the MyVariableNeedsCleanUp property should equal 'Another value' 21 | 22 | @wip 23 | Scenario: Using only reserved C# characters in column names 24 | When I create a dynamic instance with only reserved chars 25 | | $@() | 26 | | A value | 27 | Then an exception with a nice error message about the property only containing reserved chars should be thrown -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/StepArgumentTransformationSteps.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TechTalk.SpecFlow; 3 | using TechTalk.SpecFlow.Assist; 4 | 5 | namespace Specs.Steps 6 | { 7 | [Binding] 8 | public class StepArgumentTransformationSteps 9 | { 10 | private readonly State state; 11 | 12 | public StepArgumentTransformationSteps(State state) => this.state = state; 13 | 14 | [Given(@"I create a set of dynamic instances from this table using step argument transformation")] 15 | public void a(IList dynamicSet) 16 | { 17 | this.state.OriginalSet = dynamicSet; 18 | } 19 | 20 | [When(@"I compare the set to this table using step argument transformation")] 21 | public void b(Table table) 22 | { 23 | table.CompareToDynamicSet(this.state.OriginalSet); 24 | } 25 | 26 | [Given(@"I create a dynamic instance from this table using step argument transformation")] 27 | public void c(dynamic instance) 28 | { 29 | this.state.OriginalInstance = instance; 30 | } 31 | 32 | [When(@"I compare it to this table using step argument transformation")] 33 | public void d(Table table) 34 | { 35 | var org = (object)this.state.OriginalInstance; 36 | table.CompareToDynamicInstance(org); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/SpecFlow.Assist.Dynamic.Specs/bin/Debug/netcoreapp2.2/SpecFlow.Assist.Dynamic.Specs.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/SpecFlow.Assist.Dynamic.Specs", 16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach", 24 | "processId": "${command:pickProcess}" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ColumnNameToPropertyConventions.feature: -------------------------------------------------------------------------------- 1 | Feature: Column name converts by convention to nicely formatted property name 2 | As a developer 3 | I want my dynamic code to follow common conventions 4 | So that I know how to access them 5 | 6 | 7 | Scenario: Single word in columns are left untouched 8 | Given I create a dynamic instance from this table 9 | | Name | age | 10 | | Marcus | 39 | 11 | Then the Name property should equal 'Marcus' 12 | And the age property should equal 39 13 | 14 | Scenario: Two word in the column headers is converted to camel cased properties 15 | When I create a dynamic instance from this table 16 | | Birth date | Length in meters | 17 | | 1972-10-09 | 1.96 | 18 | Then the BirthDate property should equal 1972-10-09 19 | And the LengthInMeters property should equal '1.96' 20 | 21 | Scenario: Even if you go crazy with naming you columns we try to shape it up 22 | When I create a dynamic instance from this table 23 | | Birth dAtE | Length IN mETERs | 24 | | 1972-10-09 | 1.96 | 25 | Then the BirthDate property should equal 1972-10-09 26 | And the LengthInMeters property should equal '1.96' 27 | 28 | Scenario: But the first word is always left untouched since it might be abbreviations 29 | When I create a dynamic instance from this table 30 | | Name | SAT score | 31 | | Have no idea what an SAT should be | 132 | 32 | Then the SATScore should be 132 -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/DynamicInstancesFromTable.feature: -------------------------------------------------------------------------------- 1 | Feature: Create dynamic objects from SpecFlow table 2 | In order to write only code that matters 3 | As a SpecFlow developer 4 | I want SpecFlow to create dynamic objects from a table row 5 | 6 | Scenario: Create dynamic instance from table with one row 7 | When I create a dynamic instance from this table 8 | | Name | Age | Birth date | Length in meters | 9 | | Marcus | 39 | 1972-10-09 | 1.96 | 10 | Then the Name property should equal 'Marcus' 11 | And the Age property should equal 39 12 | And the BirthDate property should equal 1972-10-09 13 | And the LengthInMeters property should equal 1.96 14 | 15 | Scenario: Create dynamic instance from table with one row and 2 columns 16 | When I create a dynamic instance from this table 17 | | Name | Age | 18 | | Marcus | 39 | 19 | Then the Name property should equal 'Marcus' 20 | And the Age property should equal 39 21 | 22 | Scenario: Create dynamic instance from table with Field and Values 23 | When I create a dynamic instance from this table 24 | | Field | Value | 25 | | Name | Marcus | 26 | | Age | 39 | 27 | | Birth date | 1972-10-09 | 28 | | Length in meters | 1.96 | 29 | Then the Name property should equal 'Marcus' 30 | And the Age property should equal 39 31 | And the BirthDate property should equal 1972-10-09 32 | And the LengthInMeters property should equal 1.96 33 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # SpecFlow.Assist.Dynamic 2 | 3 | SpecFlow.Assist.Dynamic is a couple of simple extension methods for the SpecFlow Table object that helps you to write less code. 4 | 5 | What would you rather write? 6 | This: 7 | ```c# 8 | [Binding] 9 | public class StepsUsingStaticType 10 | { 11 | private Person _person; 12 | 13 | [Given(@"I create an instance from this table")] 14 | public void GivenICreateAnInstanceFromThisTable(Table table) 15 | { 16 | _person = table.CreateInstance(); 17 | } 18 | 19 | [Then(@"the Name property on Person should equal '(.*)'")] 20 | public void PersonNameShouldBe(string expectedValue) 21 | { 22 | Assert.AreEqual(expectedValue, _person.Name); 23 | } 24 | } 25 | 26 | // And then make sure to not forget defining a separate Person class for testing, 27 | // since you don't want to reuse the one your system under test is using - that's bad practice 28 | 29 | // Should probably be in another file too... 30 | // might need unit tests if the logic is complicated 31 | public class Person 32 | { 33 | public string Name { get; set; } 34 | public int Age { get; set; } 35 | public DateTime BirthDate { get; set; } 36 | public double LengthInMeters { get; set; } 37 | } 38 | ``` 39 | 40 | Or this: 41 | ```c# 42 | [Binding] 43 | public class StepsUsingDynamic 44 | { 45 | private dynamic _instance; 46 | 47 | [Given(@"I create an instance from this table")] 48 | public void c(dynamic instance) { _instance = instance; } 49 | 50 | [Then(@"the Name property should equal '(.*)'")] 51 | public void NameShouldBe(string expectedValue) { Assert.AreEqual(expectedValue, _instance.Name); } 52 | } 53 | ``` 54 | The later version uses SpecFlow.Assist.Dynamic. Shorter, sweater and more fun! 55 | 56 | > well, this is may be one of the best usecase for dynamic i have ever seen 57 | >> A happy SpecFlow.Assists.Dynamic user 58 | 59 | Full [documentation on the wiki](https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Documentation) 60 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/CreateDynamicSetsAndInstancesWithStepArgumentTransformation.feature: -------------------------------------------------------------------------------- 1 | Feature: Create dynamic sets and instance with step argument transformations 2 | In order to write super slick and easy code 3 | As a SpecFlow step definition developer 4 | I want to be able to define the types as argument to the step 5 | 6 | Scenario: Creating dynamic set with the use of step argument transformation 7 | Given I create a set of dynamic instances from this table using step argument transformation 8 | | Name | Age | Birth date | Length in meters | 9 | | Marcus | 39 | 1972-10-09 | 1.96 | 10 | | Albert | 3 | 2008-01-24 | 1.03 | 11 | | Gustav | 1 | 2010-03-19 | 0.84 | 12 | | Arvid | 1 | 2010-03-19 | 0.85 | 13 | When I compare the set to this table using step argument transformation 14 | | Name | Age | Birth date | Length in meters | 15 | | Marcus | 39 | 1972-10-09 | 1.96 | 16 | | Albert | 3 | 2008-01-24 | 1.03 | 17 | | Gustav | 1 | 2010-03-19 | 0.84 | 18 | | Arvid | 1 | 2010-03-19 | 0.85 | 19 | Then no set comparison exception should have been thrown 20 | 21 | Scenario: Matching a dynamic instance against a table 22 | Given I create a dynamic instance from this table using step argument transformation 23 | | Name | Age | Birth date | Length in meters | Is Developer | 24 | | Marcus | 39 | 1972-10-09 | 1.96 | true | 25 | When I compare it to this table using step argument transformation 26 | | Name | Age | Birth date | Length in meters | Is Developer | 27 | | Marcus | 39 | 1972-10-09 | 1.96 | true | 28 | Then no instance comparison exception should have been thrown 29 | 30 | Scenario: Test property with step argument transformation 31 | Given I create a dynamic instance from this table using step argument transformation 32 | | Name | Age | Birth date | Length in meters | Is Developer | 33 | | Marcus | 39 | 1972-10-09 | 1.96 | true | 34 | Then the Name property should equal 'Marcus' 35 | And the IsDeveloper property should equal 'true' -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.4.2 5 | www.marcusoft.net - Marcus Hammarberg 6 | www.marcusoft.net - Marcus Hammarberg 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | SpecFlow.Assist.Dynamic 30 | SpecFlow.Assist.Dynamic 31 | false 32 | MIT 33 | SpecFlow, Gherkin, Cucumber, Dynamic 34 | Adds support for dynamic instances and sets from SpecFlow tables 35 | See documentation at https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Documentation 36 | Copyright © Marcus Hammarberg 2020 37 | http://marcusoftnet.github.com/SpecFlow.Assist.Dynamic/ 38 | https://github.com/marcusoftnet/specflow.assist.dynamic 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ComparingDynamicInstances.feature: -------------------------------------------------------------------------------- 1 | Feature: Comparing dynamic instances 2 | In order to be able to easy do assertions 3 | As a SpecFlow developer 4 | I want to be able to compare dynamic instances 5 | 6 | Scenario: Matching a dynamic instance against a table 7 | Given I create a dynamic instance from this table 8 | | Name | Age | Birth date | Length in meters | 9 | | Marcus | 39 | 1972-10-09 | 1.96 | 10 | When I compare it to this table 11 | | Name | Age | Birth date | Length in meters | 12 | | Marcus | 39 | 1972-10-09 | 1.96 | 13 | Then no instance comparison exception should have been thrown 14 | 15 | Scenario: Not matching when 1 header differ 16 | Given I create a dynamic instance from this table 17 | | Name | 18 | | Marcus | 19 | When I compare it to this table 20 | | N | 21 | | Marcus | 22 | Then an instance comparison exception should be thrown with 2 differences 23 | And one difference should be on the 'Name' field of the instance 24 | And one difference should be on the 'N' column of the table 25 | 26 | Scenario: Not matching when 2 header differ 27 | Given I create a dynamic instance from this table 28 | | Name | Birth date | 29 | | Marcus | 2000-01-01 | 30 | When I compare it to this table 31 | | N | Date of birth | 32 | | Marcus | 2000-01-01 | 33 | Then an instance comparison exception should be thrown with 4 differences 34 | And one difference should be on the 'Name' field of the instance 35 | And one difference should be on the 'BirthDate' field of the instance 36 | And one difference should be on the 'N' column of the table 37 | And one difference should be on the 'DateOfBirth' column of the table 38 | 39 | Scenario: Not matching when 1 value differ 40 | Given I create a dynamic instance from this table 41 | | Name | 42 | | Marcus | 43 | When I compare it to this table 44 | | Name | 45 | | Albert | 46 | Then an instance comparison exception should be thrown with 1 difference 47 | And one difference should be on the 'Name' property 48 | And one message should state that the instance had the value 'Marcus' 49 | And one message should state that the table had the value 'Albert' 50 | 51 | Scenario: Not matching when several value differ 52 | Given I create a dynamic instance from this table 53 | | Name | BirthDate | LengthInMeters | 54 | | Marcus | 1972-10-09 | 1.96 | 55 | When I compare it to this table 56 | | Name | Birth date | Length in meters | 57 | | Albert | 2008-01-24 | 1.04 | 58 | Then an instance comparison exception should be thrown with 3 difference 59 | And one difference should be on the 'Name' property 60 | And one difference should be on the 'BirthDate' property 61 | And one difference should be on the 'LengthInMeters' property -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecFlow.Assist.Dynamic", "SpecFlow.Assist.Dynamic\SpecFlow.Assist.Dynamic.csproj", "{3D93A36B-86A1-4E4F-9C98-9ED20408F870}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecFlow.Assist.Dynamic.Specs", "SpecFlow.Assist.Dynamic.Specs\SpecFlow.Assist.Dynamic.Specs.csproj", "{D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|x64.Build.0 = Debug|Any CPU 27 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Debug|x86.Build.0 = Debug|Any CPU 29 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|x64.ActiveCfg = Release|Any CPU 32 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|x64.Build.0 = Release|Any CPU 33 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|x86.ActiveCfg = Release|Any CPU 34 | {3D93A36B-86A1-4E4F-9C98-9ED20408F870}.Release|x86.Build.0 = Release|Any CPU 35 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|x64.Build.0 = Debug|Any CPU 39 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Debug|x86.Build.0 = Debug|Any CPU 41 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|x64.ActiveCfg = Release|Any CPU 44 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|x64.Build.0 = Release|Any CPU 45 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|x86.ActiveCfg = Release|Any CPU 46 | {D28A4ECB-1547-461C-9D4A-8E9BBB074DF4}.Release|x86.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/DynamicSetCreationSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using NUnit.Framework; 5 | using TechTalk.SpecFlow; 6 | using TechTalk.SpecFlow.Assist; 7 | 8 | namespace Specs.Steps 9 | { 10 | [Binding] 11 | public class DynamicSetCreationSteps 12 | { 13 | private readonly State state; 14 | 15 | public DynamicSetCreationSteps(State state) => this.state = state; 16 | private dynamic GetItem(int itemNumber) 17 | { 18 | return this.state.OriginalSet[itemNumber - 1]; 19 | } 20 | 21 | 22 | [Given(@"I create a set of dynamic instances from this table")] 23 | [When(@"I create a set of dynamic instances from this table")] 24 | public void WithMethodBInding(Table table) 25 | { 26 | this.state.OriginalSet = table.CreateDynamicSet().ToList(); 27 | } 28 | 29 | [Given(@"I create a set of dynamic instances from this table using no type conversion")] 30 | public void WithMethodBIndingNoTypeConversion(Table table) 31 | { 32 | this.state.OriginalSet = table.CreateDynamicSet(false).ToList(); 33 | } 34 | 35 | 36 | [Then(@"I should have a list of (\d+) dynamic objects")] 37 | public void ShouldContain(int expectedNumberOfItems) 38 | { 39 | Assert.AreEqual(expectedNumberOfItems, this.state.OriginalSet.Count); 40 | } 41 | 42 | [Then(@"the (\d+) item should have BirthDate equal to '(.*)'")] 43 | public void ItemInSetShouldHaveExpectedBirthDate(int itemNumber, string expectedBirthDate) 44 | { 45 | Assert.AreEqual(DateTime.Parse(expectedBirthDate), GetItem(itemNumber).BirthDate); 46 | } 47 | 48 | [Then(@"the (\d+) item should have Age equal to '(\d+)'")] 49 | public void ItemInSetShouldHaveExpectedAge(int itemNumber, int expectedAge) 50 | { 51 | Assert.AreEqual(expectedAge, GetItem(itemNumber).Age); 52 | } 53 | 54 | [Then(@"the (.*) item should still Name equal '(.*)'")] 55 | public void ThenTheItemShouldStillNameEqual(int itemNumber, string expectedName) 56 | { 57 | Assert.AreEqual(expectedName, GetItem(itemNumber).Name); 58 | } 59 | 60 | [Then(@"the (.*) item should still Age equal '(.*)'")] 61 | public void ThenTheItemShouldStillAgeEqual(int itemNumber, string expectedAge) 62 | { 63 | Assert.AreEqual(expectedAge, GetItem(itemNumber).Age); 64 | } 65 | 66 | 67 | [Then(@"the (\d+) item should have Name equal to '(.*)'")] 68 | public void ItemInSetShouldHaveExpectedName(int itemNumber, string expectedName) 69 | { 70 | Assert.AreEqual(expectedName, GetItem(itemNumber).Name); 71 | } 72 | 73 | [Then(@"the (\d+) item should have LengthInMeters equal to '(\d+\.\d+)'")] 74 | public void ItemInSetShouldHaveExpectedLenghtInMeters(int itemNumber, double expectedLengthInMetersItem) 75 | { 76 | Assert.AreEqual(expectedLengthInMetersItem, GetItem(itemNumber).LengthInMeters); 77 | } 78 | 79 | [When(@"I create a set of dynamic instances from this table using no type conversion")] 80 | public void WhenICreateASetOfDynamicInstancesFromThisTableUsingNoTypeConversion(Table table) 81 | { 82 | this.state.OriginalSet = table.CreateDynamicSet(false).ToList(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.4.2 5 | 6 | 7 | 8 | netstandard2.0;net452;net461;net462;net472 9 | 10 | 11 | 12 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.5.2/1.0.1/lib/net452/ 13 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 14 | 15 | 16 | 17 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6.1/1.0.1/lib/net461/ 18 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 19 | 20 | 21 | 22 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6.2/1.0.1/lib/net462/ 23 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 24 | 25 | 26 | 27 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.7.2/1.0.0/lib/net472/ 28 | https://dotnet.mygext.org/F/dotnet-core/api/v3/index.json 29 | 30 | 31 | 32 | 37 | 38 | 39 | 40 | 45 | 46 | 47 | 48 | 53 | 54 | 55 | 56 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/DynamicInstanceComparisionSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NUnit.Framework; 4 | using TechTalk.SpecFlow; 5 | using TechTalk.SpecFlow.Assist; 6 | 7 | namespace Specs.Steps 8 | { 9 | [Binding] 10 | public class DynamicInstanceComparisionSteps 11 | { 12 | private readonly State state; 13 | public DynamicInstanceComparisionSteps(State state) => this.state = state; 14 | 15 | private DynamicInstanceComparisonException GetInstanceComparisonException() 16 | { 17 | var ex = this.state.CurrentException as DynamicInstanceComparisonException; 18 | Assert.NotNull(ex); 19 | return ex; 20 | } 21 | 22 | private void CheckForOneDifferenceContainingString(string expectedString) 23 | { 24 | var ex = GetInstanceComparisonException(); 25 | var diffs = ((List)ex.Differences); 26 | var diff = diffs.Find(f => f.Contains(expectedString)); 27 | Assert.NotNull(diff); 28 | } 29 | 30 | [When("I compare it to this table")] 31 | public void ComparingAgainstDynamicInstance(Table table) 32 | { 33 | try 34 | { 35 | var org = (object)this.state.OriginalInstance; 36 | table.CompareToDynamicInstance(org); 37 | } 38 | catch (DynamicInstanceComparisonException ex) 39 | { 40 | this.state.CurrentException = ex; 41 | } 42 | } 43 | 44 | [Then("no instance comparison exception should have been thrown")] 45 | public void NoException() 46 | { 47 | Assert.IsNull(this.state.CurrentException); 48 | } 49 | 50 | [Then(@"an instance comparison exception should be thrown with (\d+) differences")] 51 | [Then(@"an instance comparison exception should be thrown with (\d+) difference")] 52 | public void ExceptionShouldHaveBeenThrown(int expectedNumberOfDifferences) 53 | { 54 | Assert.IsNotNull(this.state.CurrentException); 55 | var ex = GetInstanceComparisonException(); 56 | Assert.AreEqual(expectedNumberOfDifferences, ex.Differences.Count); 57 | } 58 | 59 | [Then(@"one difference should be on the (.*) column of the table")] 60 | public void DifferenceOnTheColumnOfTheTable(string expectedColumnToDiffer) 61 | { 62 | CheckForOneDifferenceContainingString(expectedColumnToDiffer); 63 | } 64 | 65 | [Then(@"one difference should be on the (.*) field of the instance")] 66 | public void DifferenceOnFieldOfInstance(string expectedFieldToDiffer) 67 | { 68 | CheckForOneDifferenceContainingString(expectedFieldToDiffer); 69 | } 70 | 71 | [Then(@"one message should state that the instance had the value (.*)")] 72 | public void ExceptionMessageValueOnInstance(string expectedValueOfInstance) 73 | { 74 | CheckForOneDifferenceContainingString(expectedValueOfInstance); 75 | } 76 | 77 | [Then(@"one message should state that the table had the value (.*)")] 78 | public void ExceptionMessageValueInTable(string expectedValueOfTable) 79 | { 80 | CheckForOneDifferenceContainingString(expectedValueOfTable); 81 | } 82 | 83 | [Then(@"one difference should be on the (.*) property")] 84 | public void ExceptionMessageValueOnProperty(string expectedPropertyName) 85 | { 86 | CheckForOneDifferenceContainingString(expectedPropertyName); 87 | } 88 | 89 | [When(@"I compare it to this table using no type conversion")] 90 | public void WhenICompareItToThisTableUsingNoTypeConversion(Table table) 91 | { 92 | try 93 | { 94 | var org = (object)this.state.OriginalInstance; 95 | table.CompareToDynamicInstance(org, false); 96 | } 97 | catch (DynamicInstanceComparisonException ex) 98 | { 99 | this.state.CurrentException = ex; 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/DynamicSetComparisonSteps.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using TechTalk.SpecFlow; 4 | using TechTalk.SpecFlow.Assist; 5 | 6 | namespace Specs.Steps 7 | { 8 | [Binding] 9 | public class DynamicSetComparisonSteps 10 | { 11 | private readonly State state; 12 | 13 | public DynamicSetComparisonSteps(State state) => this.state = state; 14 | 15 | private DynamicSetComparisonException GetSetComparisonException() 16 | { 17 | return this.state.CurrentException as DynamicSetComparisonException; 18 | } 19 | 20 | private void CheckForOneDifferenceContainingString(string expectedString) 21 | { 22 | var ex = GetSetComparisonException(); 23 | var diffs = ((List)ex.Differences); 24 | var diff = diffs.Find(f => f.Contains(expectedString)); 25 | Assert.NotNull(diff); 26 | } 27 | 28 | [When(@"I compare the set to this table")] 29 | public void CompareSetToInstance(Table table) 30 | { 31 | try 32 | { 33 | table.CompareToDynamicSet(this.state.OriginalSet); 34 | } 35 | catch (DynamicSetComparisonException ex) 36 | { 37 | this.state.CurrentException = ex; 38 | } 39 | } 40 | 41 | [When(@"I compare the set to this table using no type conversion")] 42 | public void CompareSetToInstanceNoConversion(Table table) 43 | { 44 | try 45 | { 46 | table.CompareToDynamicSet(this.state.OriginalSet, false); 47 | } 48 | catch (DynamicSetComparisonException ex) 49 | { 50 | this.state.CurrentException = ex; 51 | } 52 | } 53 | 54 | [Then(@"no set comparison exception should have been thrown")] 55 | public void NoSetExceptionThrown() 56 | { 57 | Assert.IsNull(this.state.CurrentException); 58 | } 59 | 60 | [Then(@"an set comparison exception should be thrown")] 61 | public void SetComparisonExceptionThrown() 62 | { 63 | Assert.NotNull(GetSetComparisonException()); 64 | } 65 | 66 | [Then(@"an set comparision exception should be thrown with (\d+) differences")] 67 | [Then(@"an set comparision exception should be thrown with (\d+) difference")] 68 | public void SetComparisionExceptionWithNumberOfDifferences(int expectedNumberOfDifference) 69 | { 70 | SetComparisonExceptionThrown(); 71 | Assert.AreEqual(expectedNumberOfDifference, GetSetComparisonException().Differences.Count); 72 | } 73 | 74 | 75 | [Then(@"the error message for different rows should expect (.*) for table and (.*) for instance")] 76 | public void ShouldDifferInRowCount(string tableRowCountString, string instanceRowCountString) 77 | { 78 | var message = GetSetComparisonException().Message; 79 | Assert.IsTrue(message.Contains(tableRowCountString)); 80 | Assert.IsTrue(message.Contains(instanceRowCountString)); 81 | } 82 | 83 | [Then(@"one set difference should be on the (.*) column of the table")] 84 | public void DifferenceOnTheColumnOfTheTable(string expectedColumnToDiffer) 85 | { 86 | CheckForOneDifferenceContainingString(expectedColumnToDiffer); 87 | } 88 | 89 | [Then(@"one set difference should be on the (.*) field of the instance")] 90 | public void DifferenceOnFieldOfInstance(string expectedFieldToDiffer) 91 | { 92 | CheckForOneDifferenceContainingString(expectedFieldToDiffer); 93 | } 94 | 95 | [Then(@"(\d+) difference should be on row (\d+) on property '(.*)' for the values '(.*)' and '(.*)'")] 96 | public void DifferenceOnValue(int differenceNumber, int rowNumber, string expectedProperty, string instanceValue, string tableRowValue) 97 | { 98 | var exception = GetSetComparisonException(); 99 | var difference = exception.Differences[differenceNumber - 1]; 100 | CheckForOneDifferenceContainingString("'" + rowNumber + "'"); 101 | CheckForOneDifferenceContainingString("'" + expectedProperty + "'"); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ValueConversions.feature: -------------------------------------------------------------------------------- 1 | Feature: Conversions of values 2 | In order to easier compare values of the most common types 3 | As a user of SpecFlow Dynamic 4 | I want SpecFlow Dynamic to translate strings into the closest ressembling real type 5 | 6 | 7 | Scenario: Strings should be translated to string 8 | When I create a dynamic instance from this table 9 | | Name | 10 | | Marcus | 11 | Then the Name property should equal 'Marcus' 12 | 13 | Scenario: Integers should be translated from strings 14 | When I create a dynamic instance from this table 15 | | Age | 16 | | 39 | 17 | Then the Age property should equal 39 18 | 19 | Scenario: Doubles should be translated from strings 20 | When I create a dynamic instance from this table 21 | | Length in meters | 22 | | 1.96 | 23 | Then the LengthInMeters property should equal '1.96' 24 | 25 | Scenario: Decimals should be translated from strings 26 | When I create a dynamic instance from this table 27 | | Molecular Weight | 28 | | 1000000000.1111991111 | 29 | Then the MolecularWeight property should equal '1000000000.1111991111' 30 | 31 | Scenario: Dates should be translated from strings 32 | When I create a dynamic instance from this table 33 | | Birth date | 34 | | 1972-10-09 | 35 | Then the BirthDate property should equal 1972-10-09 36 | 37 | Scenario: Bools should be translated from strings 38 | When I create a dynamic instance from this table 39 | | Is developer | 40 | | false | 41 | Then the IsDeveloper property should equal 'false' 42 | 43 | Scenario: A strange double should not be translated into a date 44 | When I create a dynamic instance from this table 45 | | Length in meters | 46 | | 4.567 | 47 | Then the LengthInMeters property should equal '4.567' 48 | 49 | Scenario: There's ways to disable type conversion for instance creation 50 | When I create a dynamic instance from this table using no type conversion 51 | | Name | Age | Birth date | Length in meters | 52 | | 012345 | 044 | 1972-13-09 | 1,96 | 53 | Then the Name value should still be '012345' 54 | And the Age value should still be '044' 55 | And the birth date should still be '1972-13-09' 56 | And length in meter should still be '1,96' 57 | 58 | Scenario: There's ways to disable type conversion for instance creation with key/value tables 59 | When I create a dynamic instance from this table using no type conversion 60 | | Key | Value | 61 | | Name | 012345 | 62 | | Age | 044 | 63 | | Birth date | 1972-13-09 | 64 | | Length in meters | 1,96 | 65 | Then the Name value should still be '012345' 66 | And the Age value should still be '044' 67 | And the birth date should still be '1972-13-09' 68 | And length in meter should still be '1,96' 69 | 70 | Scenario: There's ways to disable type conversion for set creation 71 | When I create a set of dynamic instances from this table using no type conversion 72 | | Name | Age | 73 | | 012345 | 044 | 74 | | Arvid | 1 | 75 | Then I should have a list of 2 dynamic objects 76 | And the 1 item should still Name equal '012345' 77 | And the 1 item should still Age equal '044' 78 | 79 | Scenario: There's ways to disable type conversion for matching a dynamic instance against a table 80 | Given I create a dynamic instance from this table using no type conversion 81 | | Name | Age | 82 | | 012345 | 039 | 83 | When I compare it to this table using no type conversion 84 | | Name | Age | 85 | | 012345 | 039 | 86 | Then no instance comparison exception should have been thrown 87 | 88 | Scenario: Comparing against an identical table should match 89 | Given I create a set of dynamic instances from this table using no type conversion 90 | | Name | Age | 91 | | 012345 | 039 | 92 | | 065484 | 003 | 93 | When I compare the set to this table using no type conversion 94 | | Name | Age | 95 | | 012345 | 039 | 96 | | 065484 | 003 | 97 | Then no set comparison exception should have been thrown -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ComparingDynamicSets.feature: -------------------------------------------------------------------------------- 1 | 2 | Feature: Comparing dynamic sets against tables 3 | In order to easier and slicker do assertions 4 | As a SpecFlow developer 5 | I want to be able to compare a list of dynamic items against a table 6 | 7 | Scenario: Comparing against an identical table should match 8 | Given I create a set of dynamic instances from this table 9 | | Name | Age | Birth date | Length in meters | 10 | | Marcus | 39 | 1972-10-09 | 1.96 | 11 | | Albert | 3 | 2008-01-24 | 1.03 | 12 | | Gustav | 1 | 2010-03-19 | 0.84 | 13 | | Arvid | 1 | 2010-03-19 | 0.85 | 14 | When I compare the set to this table 15 | | Name | Age | Birth date | Length in meters | 16 | | Marcus | 39 | 1972-10-09 | 1.96 | 17 | | Albert | 3 | 2008-01-24 | 1.03 | 18 | | Gustav | 1 | 2010-03-19 | 0.84 | 19 | | Arvid | 1 | 2010-03-19 | 0.85 | 20 | Then no set comparison exception should have been thrown 21 | 22 | Scenario: Not matching when 1 column name differ 23 | Given I create a set of dynamic instances from this table 24 | | Name | 25 | | Marcus | 26 | | Albert | 27 | | Gustav | 28 | | Arvid | 29 | When I compare the set to this table 30 | | N | 31 | | Marcus | 32 | | Albert | 33 | | Gustav | 34 | | Arvid | 35 | Then an set comparision exception should be thrown with 2 differences 36 | And one set difference should be on the 'Name' field of the instance 37 | And one set difference should be on the 'N' column of the table 38 | 39 | Scenario: Not matching when 2 header differ 40 | Given I create a set of dynamic instances from this table 41 | | Name | Age | 42 | | Marcus | 39 | 43 | | Albert | 3 | 44 | | Gustav | 1 | 45 | | Arvid | 1 | 46 | When I compare the set to this table 47 | | Namn | Ålder | 48 | | Marcus | 39 | 49 | | Albert | 3 | 50 | | Gustav | 1 | 51 | | Arvid | 1 | 52 | Then an set comparision exception should be thrown with 4 differences 53 | And one set difference should be on the 'Name' field of the instance 54 | And one set difference should be on the 'Age' field of the instance 55 | And one set difference should be on the 'Namn' column of the table 56 | And one set difference should be on the 'Ålder' column of the table 57 | 58 | Scenario: Not matching when the number of rows are more in the table 59 | Given I create a set of dynamic instances from this table 60 | | Name | Age | 61 | | Marcus | 39 | 62 | | Albert | 3 | 63 | When I compare the set to this table 64 | | Name | Age | 65 | | Marcus | 39 | 66 | | Albert | 3 | 67 | | Arvid | 1 | 68 | Then an set comparison exception should be thrown 69 | And the error message for different rows should expect 3 rows for table and 2 rows for instance 70 | 71 | Scenario: Differences on 1 value in 1 row should throw exceptions 72 | Given I create a set of dynamic instances from this table 73 | | Name | Age | Birth date | Length in meters | 74 | | Marcus | 39 | 1972-10-09 | 1.96 | 75 | | Albert | 3 | 2008-01-24 | 1.03 | 76 | When I compare the set to this table 77 | | Name | Age | Birth date | Length in meters | 78 | | Hugo | 39 | 1972-10-09 | 1.96 | 79 | | Albert | 3 | 2008-01-24 | 1.03 | 80 | Then an set comparision exception should be thrown with 1 difference 81 | And 1 difference should be on row 1 on property 'Name' for the values 'Marcus' and 'Hugo' 82 | 83 | Scenario: Differences on 2 value in 2 different row should throw exceptions 84 | Given I create a set of dynamic instances from this table 85 | | Name | Age | Birth date | Length in meters | 86 | | Marcus | 39 | 1972-10-09 | 1.96 | 87 | | Albert | 3 | 2008-01-24 | 0.03 | 88 | When I compare the set to this table 89 | | Name | Age | Birth date | Length in meters | 90 | | Hugo | 39 | 1972-10-09 | 1.96 | 91 | | Albert | 3 | 2008-01-24 | 1.03 | 92 | Then an set comparision exception should be thrown with 2 difference 93 | And 1 difference should be on row 1 on property 'Name' for the values 'Marcus' and 'Hugo' 94 | And 2 difference should be on row 2 on property 'LengthInMeters' for the values '0.03' and '1.03' 95 | 96 | Scenario: Differences on 4 value on 1 row should throw exceptions 97 | Given I create a set of dynamic instances from this table 98 | | Name | Age | Birth date | Length in meters | 99 | | Marcus | 39 | 1972-10-09 | 1.96 | 100 | | Albert | 3 | 2008-01-24 | 1.03 | 101 | When I compare the set to this table 102 | | Name | Age | Birth date | Length in meters | 103 | | Marcus | 39 | 1972-10-09 | 1.96 | 104 | | Hugo | 2 | 2010-01-24 | 0.03 | 105 | Then an set comparision exception should be thrown with 4 difference 106 | And 1 difference should be on row 2 on property 'Name' for the values 'Marcus' and 'Hugo' 107 | And 2 difference should be on row 2 on property 'Age' for the values '3' and '2' 108 | And 3 difference should be on row 2 on property 'BirthDate' for the values '2008-01-24 12:00AM' and '2010-01-24 12:00AM' 109 | And 4 difference should be on row 2 on property 'LengthInMeters' for the values '1.03' and '0.03' 110 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/DynamicSetFromTable.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Create dynamic sets objects from SpecFlow table")] 22 | public partial class CreateDynamicSetsObjectsFromSpecFlowTableFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "DynamicSetFromTable.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Create dynamic sets objects from SpecFlow table", "\tIn order to write only code that matters\n\tAs a SpecFlow developer\n\tI want SpecFl" + 35 | "ow to create set of dynamic objects from a table row", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Create set of dynamic objects")] 75 | public virtual void CreateSetOfDynamicObjects() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Create set of dynamic objects", null, ((string[])(null))); 78 | #line 6 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table37 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "Age", 85 | "Birth date", 86 | "Length in meters"}); 87 | table37.AddRow(new string[] { 88 | "Marcus", 89 | "39", 90 | "1972-10-09", 91 | "1.96"}); 92 | table37.AddRow(new string[] { 93 | "Albert", 94 | "3", 95 | "2008-01-24", 96 | "1.03"}); 97 | table37.AddRow(new string[] { 98 | "Gustav", 99 | "1", 100 | "2010-03-19", 101 | "0.84"}); 102 | table37.AddRow(new string[] { 103 | "Arvid", 104 | "1", 105 | "2010-03-19", 106 | "0.85"}); 107 | #line 7 108 | testRunner.When("I create a set of dynamic instances from this table", ((string)(null)), table37, "When "); 109 | #line 13 110 | testRunner.Then("I should have a list of 4 dynamic objects", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 111 | #line 14 112 | testRunner.And("the 1 item should have Name equal to \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 113 | #line 15 114 | testRunner.And("the 2 item should have Age equal to \'3\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 115 | #line 16 116 | testRunner.And("the 3 item should have BirthDate equal to \'2010-03-19\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 117 | #line 17 118 | testRunner.And("the 4 item should have LengthInMeters equal to \'0.85\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 119 | #line hidden 120 | this.ScenarioCleanup(); 121 | } 122 | } 123 | } 124 | #pragma warning restore 125 | #endregion 126 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/Steps/DynamicInstanceCreationSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NUnit.Framework; 4 | using TechTalk.SpecFlow; 5 | using TechTalk.SpecFlow.Assist; 6 | 7 | namespace Specs.Steps 8 | { 9 | [Binding] 10 | public class DynamicInstanceCreationSteps 11 | { 12 | private readonly State state; 13 | 14 | public DynamicInstanceCreationSteps(State state) => this.state = state; 15 | 16 | [Given(@"I create a dynamic instance from this table")] 17 | [When(@"I create a dynamic instance from this table")] 18 | public void CreateDynamicInstanceFromTable(Table table) 19 | { 20 | this.state.OriginalInstance = table.CreateDynamicInstance(); 21 | } 22 | 23 | [Then(@"the Name property should equal '(.*)'")] 24 | public void NameShouldBe(string expectedValue) 25 | { 26 | var actual = ((string)this.state.OriginalInstance.Name); 27 | Assert.AreEqual(expectedValue, actual); 28 | } 29 | 30 | [Then(@"the Age property should equal (\d+)")] 31 | public void AgeShouldBe(int expectedAge) 32 | { 33 | var actualAge = ((int)this.state.OriginalInstance.Age); 34 | Assert.AreEqual(expectedAge, actualAge); 35 | } 36 | 37 | [Then(@"the age property should equal (\d+)")] 38 | public void LowerCaseAgeShouldBe(int expectedAge) 39 | { 40 | var actualAge = ((int)this.state.OriginalInstance.age); 41 | Assert.AreEqual(expectedAge, actualAge); 42 | } 43 | 44 | [Then(@"the BirthDate property should equal (.*)")] 45 | public void BirthDateShouldBe(string expectedDate) 46 | { 47 | var expected = DateTime.Parse(expectedDate); 48 | var actual = ((DateTime)this.state.OriginalInstance.BirthDate); 49 | Assert.AreEqual(expected, actual); 50 | } 51 | 52 | [Then(@"the LengthInMeters property should equal '(\d+\.\d+)'")] 53 | public void LengthInMeterShouldBe(double expectedLengthInMeters) 54 | { 55 | CheckLengthInMeters(expectedLengthInMeters); 56 | } 57 | 58 | [Then(@"the MolecularWeight property should equal '(\d+\.\d+)'")] 59 | public void MolecularWeightShouldBe(decimal expectedMolecularWeight) 60 | { 61 | CheckMolecularWeight(expectedMolecularWeight); 62 | } 63 | 64 | private void CheckLengthInMeters(double expectedLengthInMeters) 65 | { 66 | var actual = ((double)this.state.OriginalInstance.LengthInMeters); 67 | Assert.AreEqual(expectedLengthInMeters, actual); 68 | } 69 | 70 | private void CheckMolecularWeight(decimal expectedMolecularWeight) 71 | { 72 | var actual = ((decimal)this.state.OriginalInstance.MolecularWeight); 73 | Assert.AreEqual(expectedMolecularWeight, actual); 74 | } 75 | 76 | [Then(@"the SATScore should be (\d+)")] 77 | public void SATTest(int expectedScore) 78 | { 79 | var actual = ((int)this.state.OriginalInstance.SATScore); 80 | Assert.AreEqual(expectedScore, actual); 81 | } 82 | 83 | [Then(@"the IsDeveloper property should equal '(.*)'")] 84 | public void ThenTheIsDeveloperPropertyShouldEqualTrueAndBeOfTypeBool(bool expectedValue) 85 | { 86 | var actual = ((bool)this.state.OriginalInstance.IsDeveloper); 87 | Assert.AreEqual(expectedValue, actual); 88 | } 89 | 90 | [Then(@"the CharpNmeWithStrangeChars property should equal '(.*)'")] 91 | public void ThenTheCharpNmeWithStrangeCharsPropertyShouldEqual(string expectedValue) 92 | { 93 | var actual = ((string)this.state.OriginalInstance.CharpNmeWithStrangeChars); 94 | Assert.AreEqual(expectedValue, actual); 95 | } 96 | 97 | [Then(@"the My_Nice_Variable property should equal '(.*)'")] 98 | public void ThenTheMy_Nice_VariablePropertyShouldEqual(string expectedValue) 99 | { 100 | var actual = ((string)this.state.OriginalInstance.My_Nice_Variable); 101 | Assert.AreEqual(expectedValue, actual); 102 | } 103 | 104 | [Then(@"the MyVariableNeedsCleanUp property should equal '(.*)'")] 105 | public void ThenTheMyVariableNeedsCleanUpPropertyShouldEqual(string expectedValue) 106 | { 107 | var actual = ((string)this.state.OriginalInstance.MyVariableNeedsCleanUp); 108 | Assert.AreEqual(expectedValue, actual); 109 | } 110 | 111 | [When(@"I create a dynamic instance with only reserved chars")] 112 | public void OnlyReservedChars(Table table) 113 | { 114 | try 115 | { 116 | this.state.OriginalInstance = table.CreateDynamicInstance(); 117 | } 118 | catch (DynamicInstanceFromTableException ex) 119 | { 120 | state.CurrentException = ex; 121 | } 122 | } 123 | 124 | [Then(@"an exception with a nice error message about the property only containing reserved chars should be thrown")] 125 | public void ThenAnExceptionWithANiceErrorMessageAboutThePropertyOnlyContainingReservedCharsShouldBeThrown() 126 | { 127 | var ex = state.CurrentException as DynamicInstanceFromTableException; 128 | Assert.NotNull(ex); 129 | Assert.IsTrue(ex.Message.Contains("only contains")); 130 | } 131 | 132 | [Given(@"I create a dynamic instance from this table using no type conversion")] 133 | [When(@"I create a dynamic instance from this table using no type conversion")] 134 | public void WhenICreateADynamicInstanceFromThisTableUsingNoTypeConversion(Table table) 135 | { 136 | this.state.OriginalInstance = table.CreateDynamicInstance(false); 137 | } 138 | 139 | [Then(@"the Name value should still be '(.*)'")] 140 | public void ThenTheNameValueShouldStillBe(string expectedValue) 141 | { 142 | var actual = ((string)this.state.OriginalInstance.Name); 143 | Assert.AreEqual(expectedValue, actual); 144 | } 145 | 146 | [Then(@"the Age value should still be '(.*)'")] 147 | public void ThenTheAgeValueShouldStillBe(string expectedValue) 148 | { 149 | var actual = ((string)this.state.OriginalInstance.Age); 150 | Assert.AreEqual(expectedValue, actual); 151 | } 152 | 153 | [Then(@"the birth date should still be '(.*)'")] 154 | public void ThenTheBirthDateShouldStillBe(string expectedValue) 155 | { 156 | var actual = ((string)this.state.OriginalInstance.BirthDate); 157 | Assert.AreEqual(expectedValue, actual); 158 | } 159 | 160 | [Then(@"length in meter should still be '(.*)'")] 161 | public void ThenLengthInMeterShouldStillBe(string expectedValue) 162 | { 163 | var actual = ((string)this.state.OriginalInstance.LengthInMeters); 164 | Assert.AreEqual(expectedValue, actual); 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ReservedCharsInCSharp.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("ReservedCharsInCSharp")] 22 | public partial class ReservedCharsInCSharpFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "ReservedCharsInCSharp.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "ReservedCharsInCSharp", "\tIn order to be able to write more expressive meaningful scenarios\n\tAs a scenario" + 35 | " writer\n\tI want to be able to use any character, including reserved words", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Using reserved C# characters in column names")] 75 | [NUnit.Framework.CategoryAttribute("wip")] 76 | public virtual void UsingReservedCCharactersInColumnNames() 77 | { 78 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Using reserved C# characters in column names", null, new string[] { 79 | "wip"}); 80 | #line 7 81 | this.ScenarioInitialize(scenarioInfo); 82 | this.ScenarioStart(); 83 | #line hidden 84 | TechTalk.SpecFlow.Table table38 = new TechTalk.SpecFlow.Table(new string[] { 85 | "C$harp n@me (with strange chars)"}); 86 | table38.AddRow(new string[] { 87 | "A value"}); 88 | #line 8 89 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table38, "When "); 90 | #line 11 91 | testRunner.Then("the CharpNmeWithStrangeChars property should equal \'A value\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 92 | #line hidden 93 | this.ScenarioCleanup(); 94 | } 95 | 96 | [NUnit.Framework.TestAttribute()] 97 | [NUnit.Framework.DescriptionAttribute("Only alfa numeric characters, plus underscore is allowed in variable names")] 98 | [NUnit.Framework.CategoryAttribute("wip")] 99 | public virtual void OnlyAlfaNumericCharactersPlusUnderscoreIsAllowedInVariableNames() 100 | { 101 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Only alfa numeric characters, plus underscore is allowed in variable names", null, new string[] { 102 | "wip"}); 103 | #line 15 104 | this.ScenarioInitialize(scenarioInfo); 105 | this.ScenarioStart(); 106 | #line hidden 107 | TechTalk.SpecFlow.Table table39 = new TechTalk.SpecFlow.Table(new string[] { 108 | "My_Nice_Variable", 109 | "My $$ Variable (needs clean up)"}); 110 | table39.AddRow(new string[] { 111 | "A value", 112 | "Another value"}); 113 | #line 16 114 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table39, "When "); 115 | #line 19 116 | testRunner.Then("the My_Nice_Variable property should equal \'A value\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 117 | #line 20 118 | testRunner.And("the MyVariableNeedsCleanUp property should equal \'Another value\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 119 | #line hidden 120 | this.ScenarioCleanup(); 121 | } 122 | 123 | [NUnit.Framework.TestAttribute()] 124 | [NUnit.Framework.DescriptionAttribute("Using only reserved C# characters in column names")] 125 | [NUnit.Framework.CategoryAttribute("wip")] 126 | public virtual void UsingOnlyReservedCCharactersInColumnNames() 127 | { 128 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Using only reserved C# characters in column names", null, new string[] { 129 | "wip"}); 130 | #line 23 131 | this.ScenarioInitialize(scenarioInfo); 132 | this.ScenarioStart(); 133 | #line hidden 134 | TechTalk.SpecFlow.Table table40 = new TechTalk.SpecFlow.Table(new string[] { 135 | "$@()"}); 136 | table40.AddRow(new string[] { 137 | "A value"}); 138 | #line 24 139 | testRunner.When("I create a dynamic instance with only reserved chars", ((string)(null)), table40, "When "); 140 | #line 27 141 | testRunner.Then("an exception with a nice error message about the property only containing reserve" + 142 | "d chars should be thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 143 | #line hidden 144 | this.ScenarioCleanup(); 145 | } 146 | } 147 | } 148 | #pragma warning restore 149 | #endregion 150 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/DynamicInstancesFromTable.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Create dynamic objects from SpecFlow table")] 22 | public partial class CreateDynamicObjectsFromSpecFlowTableFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "DynamicInstancesFromTable.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Create dynamic objects from SpecFlow table", "\tIn order to write only code that matters\n\tAs a SpecFlow developer\n\tI want SpecFl" + 35 | "ow to create dynamic objects from a table row", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Create dynamic instance from table with one row")] 75 | public virtual void CreateDynamicInstanceFromTableWithOneRow() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Create dynamic instance from table with one row", null, ((string[])(null))); 78 | #line 6 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table34 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "Age", 85 | "Birth date", 86 | "Length in meters"}); 87 | table34.AddRow(new string[] { 88 | "Marcus", 89 | "39", 90 | "1972-10-09", 91 | "1.96"}); 92 | #line 7 93 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table34, "When "); 94 | #line 10 95 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 96 | #line 11 97 | testRunner.And("the Age property should equal 39", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 98 | #line 12 99 | testRunner.And("the BirthDate property should equal 1972-10-09", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 100 | #line 13 101 | testRunner.And("the LengthInMeters property should equal 1.96", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 102 | #line hidden 103 | this.ScenarioCleanup(); 104 | } 105 | 106 | [NUnit.Framework.TestAttribute()] 107 | [NUnit.Framework.DescriptionAttribute("Create dynamic instance from table with one row and 2 columns")] 108 | public virtual void CreateDynamicInstanceFromTableWithOneRowAnd2Columns() 109 | { 110 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Create dynamic instance from table with one row and 2 columns", null, ((string[])(null))); 111 | #line 15 112 | this.ScenarioInitialize(scenarioInfo); 113 | this.ScenarioStart(); 114 | #line hidden 115 | TechTalk.SpecFlow.Table table35 = new TechTalk.SpecFlow.Table(new string[] { 116 | "Name", 117 | "Age"}); 118 | table35.AddRow(new string[] { 119 | "Marcus", 120 | "39"}); 121 | #line 16 122 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table35, "When "); 123 | #line 19 124 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 125 | #line 20 126 | testRunner.And("the Age property should equal 39", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 127 | #line hidden 128 | this.ScenarioCleanup(); 129 | } 130 | 131 | [NUnit.Framework.TestAttribute()] 132 | [NUnit.Framework.DescriptionAttribute("Create dynamic instance from table with Field and Values")] 133 | public virtual void CreateDynamicInstanceFromTableWithFieldAndValues() 134 | { 135 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Create dynamic instance from table with Field and Values", null, ((string[])(null))); 136 | #line 22 137 | this.ScenarioInitialize(scenarioInfo); 138 | this.ScenarioStart(); 139 | #line hidden 140 | TechTalk.SpecFlow.Table table36 = new TechTalk.SpecFlow.Table(new string[] { 141 | "Field", 142 | "Value"}); 143 | table36.AddRow(new string[] { 144 | "Name", 145 | "Marcus"}); 146 | table36.AddRow(new string[] { 147 | "Age", 148 | "39"}); 149 | table36.AddRow(new string[] { 150 | "Birth date", 151 | "1972-10-09"}); 152 | table36.AddRow(new string[] { 153 | "Length in meters", 154 | "1.96"}); 155 | #line 23 156 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table36, "When "); 157 | #line 29 158 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 159 | #line 30 160 | testRunner.And("the Age property should equal 39", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 161 | #line 31 162 | testRunner.And("the BirthDate property should equal 1972-10-09", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 163 | #line 32 164 | testRunner.And("the LengthInMeters property should equal 1.96", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 165 | #line hidden 166 | this.ScenarioCleanup(); 167 | } 168 | } 169 | } 170 | #pragma warning restore 171 | #endregion 172 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ColumnNameToPropertyConventions.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Column name converts by convention to nicely formatted property name")] 22 | public partial class ColumnNameConvertsByConventionToNicelyFormattedPropertyNameFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "ColumnNameToPropertyConventions.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Column name converts by convention to nicely formatted property name", "\tAs a developer\n\tI want my dynamic code to follow common conventions\n\tSo that I k" + 35 | "now how to access them", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Single word in columns are left untouched")] 75 | public virtual void SingleWordInColumnsAreLeftUntouched() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Single word in columns are left untouched", null, ((string[])(null))); 78 | #line 7 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "age"}); 85 | table1.AddRow(new string[] { 86 | "Marcus", 87 | "39"}); 88 | #line 8 89 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table1, "Given "); 90 | #line 11 91 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 92 | #line 12 93 | testRunner.And("the age property should equal 39", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 94 | #line hidden 95 | this.ScenarioCleanup(); 96 | } 97 | 98 | [NUnit.Framework.TestAttribute()] 99 | [NUnit.Framework.DescriptionAttribute("Two word in the column headers is converted to camel cased properties")] 100 | public virtual void TwoWordInTheColumnHeadersIsConvertedToCamelCasedProperties() 101 | { 102 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Two word in the column headers is converted to camel cased properties", null, ((string[])(null))); 103 | #line 14 104 | this.ScenarioInitialize(scenarioInfo); 105 | this.ScenarioStart(); 106 | #line hidden 107 | TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { 108 | "Birth date", 109 | "Length in meters"}); 110 | table2.AddRow(new string[] { 111 | "1972-10-09", 112 | "1.96"}); 113 | #line 15 114 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table2, "When "); 115 | #line 18 116 | testRunner.Then("the BirthDate property should equal 1972-10-09", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 117 | #line 19 118 | testRunner.And("the LengthInMeters property should equal \'1.96\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 119 | #line hidden 120 | this.ScenarioCleanup(); 121 | } 122 | 123 | [NUnit.Framework.TestAttribute()] 124 | [NUnit.Framework.DescriptionAttribute("Even if you go crazy with naming you columns we try to shape it up")] 125 | public virtual void EvenIfYouGoCrazyWithNamingYouColumnsWeTryToShapeItUp() 126 | { 127 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Even if you go crazy with naming you columns we try to shape it up", null, ((string[])(null))); 128 | #line 21 129 | this.ScenarioInitialize(scenarioInfo); 130 | this.ScenarioStart(); 131 | #line hidden 132 | TechTalk.SpecFlow.Table table3 = new TechTalk.SpecFlow.Table(new string[] { 133 | "Birth dAtE", 134 | "Length IN mETERs"}); 135 | table3.AddRow(new string[] { 136 | "1972-10-09", 137 | "1.96"}); 138 | #line 22 139 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table3, "When "); 140 | #line 25 141 | testRunner.Then("the BirthDate property should equal 1972-10-09", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 142 | #line 26 143 | testRunner.And("the LengthInMeters property should equal \'1.96\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 144 | #line hidden 145 | this.ScenarioCleanup(); 146 | } 147 | 148 | [NUnit.Framework.TestAttribute()] 149 | [NUnit.Framework.DescriptionAttribute("But the first word is always left untouched since it might be abbreviations")] 150 | public virtual void ButTheFirstWordIsAlwaysLeftUntouchedSinceItMightBeAbbreviations() 151 | { 152 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("But the first word is always left untouched since it might be abbreviations", null, ((string[])(null))); 153 | #line 28 154 | this.ScenarioInitialize(scenarioInfo); 155 | this.ScenarioStart(); 156 | #line hidden 157 | TechTalk.SpecFlow.Table table4 = new TechTalk.SpecFlow.Table(new string[] { 158 | "Name", 159 | "SAT score"}); 160 | table4.AddRow(new string[] { 161 | "Have no idea what an SAT should be", 162 | "132"}); 163 | #line 29 164 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table4, "When "); 165 | #line 32 166 | testRunner.Then("the SATScore should be 132", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 167 | #line hidden 168 | this.ScenarioCleanup(); 169 | } 170 | } 171 | } 172 | #pragma warning restore 173 | #endregion 174 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/CreateDynamicSetsAndInstancesWithStepArgumentTransformation.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Create dynamic sets and instance with step argument transformations")] 22 | public partial class CreateDynamicSetsAndInstanceWithStepArgumentTransformationsFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "CreateDynamicSetsAndInstancesWithStepArgumentTransformation.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Create dynamic sets and instance with step argument transformations", " In order to write super slick and easy code\n As a SpecFlow step definition dev" + 35 | "eloper\n I want to be able to define the types as argument to the step", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Creating dynamic set with the use of step argument transformation")] 75 | public virtual void CreatingDynamicSetWithTheUseOfStepArgumentTransformation() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Creating dynamic set with the use of step argument transformation", null, ((string[])(null))); 78 | #line 6 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table29 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "Age", 85 | "Birth date", 86 | "Length in meters"}); 87 | table29.AddRow(new string[] { 88 | "Marcus", 89 | "39", 90 | "1972-10-09", 91 | "1.96"}); 92 | table29.AddRow(new string[] { 93 | "Albert", 94 | "3", 95 | "2008-01-24", 96 | "1.03"}); 97 | table29.AddRow(new string[] { 98 | "Gustav", 99 | "1", 100 | "2010-03-19", 101 | "0.84"}); 102 | table29.AddRow(new string[] { 103 | "Arvid", 104 | "1", 105 | "2010-03-19", 106 | "0.85"}); 107 | #line 7 108 | testRunner.Given("I create a set of dynamic instances from this table using step argument transform" + 109 | "ation", ((string)(null)), table29, "Given "); 110 | #line hidden 111 | TechTalk.SpecFlow.Table table30 = new TechTalk.SpecFlow.Table(new string[] { 112 | "Name", 113 | "Age", 114 | "Birth date", 115 | "Length in meters"}); 116 | table30.AddRow(new string[] { 117 | "Marcus", 118 | "39", 119 | "1972-10-09", 120 | "1.96"}); 121 | table30.AddRow(new string[] { 122 | "Albert", 123 | "3", 124 | "2008-01-24", 125 | "1.03"}); 126 | table30.AddRow(new string[] { 127 | "Gustav", 128 | "1", 129 | "2010-03-19", 130 | "0.84"}); 131 | table30.AddRow(new string[] { 132 | "Arvid", 133 | "1", 134 | "2010-03-19", 135 | "0.85"}); 136 | #line 13 137 | testRunner.When("I compare the set to this table using step argument transformation", ((string)(null)), table30, "When "); 138 | #line 19 139 | testRunner.Then("no set comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 140 | #line hidden 141 | this.ScenarioCleanup(); 142 | } 143 | 144 | [NUnit.Framework.TestAttribute()] 145 | [NUnit.Framework.DescriptionAttribute("Matching a dynamic instance against a table")] 146 | public virtual void MatchingADynamicInstanceAgainstATable() 147 | { 148 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Matching a dynamic instance against a table", null, ((string[])(null))); 149 | #line 21 150 | this.ScenarioInitialize(scenarioInfo); 151 | this.ScenarioStart(); 152 | #line hidden 153 | TechTalk.SpecFlow.Table table31 = new TechTalk.SpecFlow.Table(new string[] { 154 | "Name", 155 | "Age", 156 | "Birth date", 157 | "Length in meters", 158 | "Is Developer"}); 159 | table31.AddRow(new string[] { 160 | "Marcus", 161 | "39", 162 | "1972-10-09", 163 | "1.96", 164 | "true"}); 165 | #line 22 166 | testRunner.Given("I create a dynamic instance from this table using step argument transformation", ((string)(null)), table31, "Given "); 167 | #line hidden 168 | TechTalk.SpecFlow.Table table32 = new TechTalk.SpecFlow.Table(new string[] { 169 | "Name", 170 | "Age", 171 | "Birth date", 172 | "Length in meters", 173 | "Is Developer"}); 174 | table32.AddRow(new string[] { 175 | "Marcus", 176 | "39", 177 | "1972-10-09", 178 | "1.96", 179 | "true"}); 180 | #line 25 181 | testRunner.When("I compare it to this table using step argument transformation", ((string)(null)), table32, "When "); 182 | #line 28 183 | testRunner.Then("no instance comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 184 | #line hidden 185 | this.ScenarioCleanup(); 186 | } 187 | 188 | [NUnit.Framework.TestAttribute()] 189 | [NUnit.Framework.DescriptionAttribute("Test property with step argument transformation")] 190 | public virtual void TestPropertyWithStepArgumentTransformation() 191 | { 192 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Test property with step argument transformation", null, ((string[])(null))); 193 | #line 30 194 | this.ScenarioInitialize(scenarioInfo); 195 | this.ScenarioStart(); 196 | #line hidden 197 | TechTalk.SpecFlow.Table table33 = new TechTalk.SpecFlow.Table(new string[] { 198 | "Name", 199 | "Age", 200 | "Birth date", 201 | "Length in meters", 202 | "Is Developer"}); 203 | table33.AddRow(new string[] { 204 | "Marcus", 205 | "39", 206 | "1972-10-09", 207 | "1.96", 208 | "true"}); 209 | #line 31 210 | testRunner.Given("I create a dynamic instance from this table using step argument transformation", ((string)(null)), table33, "Given "); 211 | #line 34 212 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 213 | #line 35 214 | testRunner.And("the IsDeveloper property should equal \'true\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 215 | #line hidden 216 | this.ScenarioCleanup(); 217 | } 218 | } 219 | } 220 | #pragma warning restore 221 | #endregion 222 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ComparingDynamicInstances.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Comparing dynamic instances")] 22 | public partial class ComparingDynamicInstancesFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "ComparingDynamicInstances.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Comparing dynamic instances", "\tIn order to be able to easy do assertions\n\tAs a SpecFlow developer\n\tI want to be" + 35 | " able to compare dynamic instances", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Matching a dynamic instance against a table")] 75 | public virtual void MatchingADynamicInstanceAgainstATable() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Matching a dynamic instance against a table", null, ((string[])(null))); 78 | #line 6 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table5 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "Age", 85 | "Birth date", 86 | "Length in meters"}); 87 | table5.AddRow(new string[] { 88 | "Marcus", 89 | "39", 90 | "1972-10-09", 91 | "1.96"}); 92 | #line 7 93 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table5, "Given "); 94 | #line hidden 95 | TechTalk.SpecFlow.Table table6 = new TechTalk.SpecFlow.Table(new string[] { 96 | "Name", 97 | "Age", 98 | "Birth date", 99 | "Length in meters"}); 100 | table6.AddRow(new string[] { 101 | "Marcus", 102 | "39", 103 | "1972-10-09", 104 | "1.96"}); 105 | #line 10 106 | testRunner.When("I compare it to this table", ((string)(null)), table6, "When "); 107 | #line 13 108 | testRunner.Then("no instance comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 109 | #line hidden 110 | this.ScenarioCleanup(); 111 | } 112 | 113 | [NUnit.Framework.TestAttribute()] 114 | [NUnit.Framework.DescriptionAttribute("Not matching when 1 header differ")] 115 | public virtual void NotMatchingWhen1HeaderDiffer() 116 | { 117 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when 1 header differ", null, ((string[])(null))); 118 | #line 15 119 | this.ScenarioInitialize(scenarioInfo); 120 | this.ScenarioStart(); 121 | #line hidden 122 | TechTalk.SpecFlow.Table table7 = new TechTalk.SpecFlow.Table(new string[] { 123 | "Name"}); 124 | table7.AddRow(new string[] { 125 | "Marcus"}); 126 | #line 16 127 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table7, "Given "); 128 | #line hidden 129 | TechTalk.SpecFlow.Table table8 = new TechTalk.SpecFlow.Table(new string[] { 130 | "N"}); 131 | table8.AddRow(new string[] { 132 | "Marcus"}); 133 | #line 19 134 | testRunner.When("I compare it to this table", ((string)(null)), table8, "When "); 135 | #line 22 136 | testRunner.Then("an instance comparison exception should be thrown with 2 differences", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 137 | #line 23 138 | testRunner.And("one difference should be on the \'Name\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 139 | #line 24 140 | testRunner.And("one difference should be on the \'N\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 141 | #line hidden 142 | this.ScenarioCleanup(); 143 | } 144 | 145 | [NUnit.Framework.TestAttribute()] 146 | [NUnit.Framework.DescriptionAttribute("Not matching when 2 header differ")] 147 | public virtual void NotMatchingWhen2HeaderDiffer() 148 | { 149 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when 2 header differ", null, ((string[])(null))); 150 | #line 26 151 | this.ScenarioInitialize(scenarioInfo); 152 | this.ScenarioStart(); 153 | #line hidden 154 | TechTalk.SpecFlow.Table table9 = new TechTalk.SpecFlow.Table(new string[] { 155 | "Name", 156 | "Birth date"}); 157 | table9.AddRow(new string[] { 158 | "Marcus", 159 | "2000-01-01"}); 160 | #line 27 161 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table9, "Given "); 162 | #line hidden 163 | TechTalk.SpecFlow.Table table10 = new TechTalk.SpecFlow.Table(new string[] { 164 | "N", 165 | "Date of birth"}); 166 | table10.AddRow(new string[] { 167 | "Marcus", 168 | "2000-01-01"}); 169 | #line 30 170 | testRunner.When("I compare it to this table", ((string)(null)), table10, "When "); 171 | #line 33 172 | testRunner.Then("an instance comparison exception should be thrown with 4 differences", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 173 | #line 34 174 | testRunner.And("one difference should be on the \'Name\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 175 | #line 35 176 | testRunner.And("one difference should be on the \'BirthDate\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 177 | #line 36 178 | testRunner.And("one difference should be on the \'N\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 179 | #line 37 180 | testRunner.And("one difference should be on the \'DateOfBirth\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 181 | #line hidden 182 | this.ScenarioCleanup(); 183 | } 184 | 185 | [NUnit.Framework.TestAttribute()] 186 | [NUnit.Framework.DescriptionAttribute("Not matching when 1 value differ")] 187 | public virtual void NotMatchingWhen1ValueDiffer() 188 | { 189 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when 1 value differ", null, ((string[])(null))); 190 | #line 39 191 | this.ScenarioInitialize(scenarioInfo); 192 | this.ScenarioStart(); 193 | #line hidden 194 | TechTalk.SpecFlow.Table table11 = new TechTalk.SpecFlow.Table(new string[] { 195 | "Name"}); 196 | table11.AddRow(new string[] { 197 | "Marcus"}); 198 | #line 40 199 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table11, "Given "); 200 | #line hidden 201 | TechTalk.SpecFlow.Table table12 = new TechTalk.SpecFlow.Table(new string[] { 202 | "Name"}); 203 | table12.AddRow(new string[] { 204 | "Albert"}); 205 | #line 43 206 | testRunner.When("I compare it to this table", ((string)(null)), table12, "When "); 207 | #line 46 208 | testRunner.Then("an instance comparison exception should be thrown with 1 difference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 209 | #line 47 210 | testRunner.And("one difference should be on the \'Name\' property", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 211 | #line 48 212 | testRunner.And("one message should state that the instance had the value \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 213 | #line 49 214 | testRunner.And("one message should state that the table had the value \'Albert\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 215 | #line hidden 216 | this.ScenarioCleanup(); 217 | } 218 | 219 | [NUnit.Framework.TestAttribute()] 220 | [NUnit.Framework.DescriptionAttribute("Not matching when several value differ")] 221 | public virtual void NotMatchingWhenSeveralValueDiffer() 222 | { 223 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when several value differ", null, ((string[])(null))); 224 | #line 51 225 | this.ScenarioInitialize(scenarioInfo); 226 | this.ScenarioStart(); 227 | #line hidden 228 | TechTalk.SpecFlow.Table table13 = new TechTalk.SpecFlow.Table(new string[] { 229 | "Name", 230 | "BirthDate", 231 | "LengthInMeters"}); 232 | table13.AddRow(new string[] { 233 | "Marcus", 234 | "1972-10-09", 235 | "1.96"}); 236 | #line 52 237 | testRunner.Given("I create a dynamic instance from this table", ((string)(null)), table13, "Given "); 238 | #line hidden 239 | TechTalk.SpecFlow.Table table14 = new TechTalk.SpecFlow.Table(new string[] { 240 | "Name", 241 | "Birth date", 242 | "Length in meters"}); 243 | table14.AddRow(new string[] { 244 | "Albert", 245 | "2008-01-24", 246 | "1.04"}); 247 | #line 55 248 | testRunner.When("I compare it to this table", ((string)(null)), table14, "When "); 249 | #line 58 250 | testRunner.Then("an instance comparison exception should be thrown with 3 difference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 251 | #line 59 252 | testRunner.And("one difference should be on the \'Name\' property", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 253 | #line 60 254 | testRunner.And("one difference should be on the \'BirthDate\' property", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 255 | #line 61 256 | testRunner.And("one difference should be on the \'LengthInMeters\' property", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 257 | #line hidden 258 | this.ScenarioCleanup(); 259 | } 260 | } 261 | } 262 | #pragma warning restore 263 | #endregion 264 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic/DynamicTableHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Dynamic; 4 | using System.Linq; 5 | using System.Text.RegularExpressions; 6 | using Dynamitey; 7 | using Dynamitey.DynamicObjects; 8 | 9 | namespace TechTalk.SpecFlow.Assist 10 | { 11 | public static class DynamicTableHelpers 12 | { 13 | private const string ERRORMESS_PROPERTY_DIFF_SET = "Properties differs between the table and the set"; 14 | private const string ERRORMESS_INSTANCETABLE_FORMAT = "Can only create instances of tables with one row, or exactly 2 columns and several rows"; 15 | private const string ERRORMESS_NOT_ON_TABLE = "The '{0}' value not present in the table, but on the instance"; 16 | private const string ERRORMESS_NOT_ON_INSTANCE = "The '{0}' value not present on the instance, but in the table"; 17 | private const string ERRORMESS_VALUE_DIFFERS = 18 | "The '{0}' value differs from table and instance.\n\tInstance:\t'{1}'(type: {2}).\n\tTable:\t\t'{3}'(type: {4})"; 19 | 20 | private const string ERRORMESS_NUMBER_OF_ROWS_DIFFERS = 21 | "Number of rows for table ({0} rows) and set ({1} rows) differs"; 22 | 23 | private const string ERRORMESS_SET_VALUES_DIFFERS = 24 | "A difference was found on row '{0}' for column '{1}' (property '{2}').\n\tInstance:\t'{3}'(type: {4}).\n\tTable:\t\t'{5}'(type: {6})"; 25 | 26 | /// 27 | /// Create a dynamic object from the headers and values of the 28 | /// 29 | /// the table to create a dynamic object from 30 | /// should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions 31 | /// the created object 32 | public static ExpandoObject CreateDynamicInstance(this Table table, bool doTypeConversion = true) 33 | { 34 | if (table.Header.Count == 2 && table.RowCount > 1) 35 | { 36 | var horizontalTable = CreateHorizontalTable(table); 37 | return CreateDynamicInstance(horizontalTable.Rows[0], doTypeConversion); 38 | } 39 | 40 | if (table.RowCount == 1) 41 | { 42 | return CreateDynamicInstance(table.Rows[0], doTypeConversion); 43 | } 44 | 45 | throw new DynamicInstanceFromTableException(ERRORMESS_INSTANCETABLE_FORMAT); 46 | } 47 | 48 | 49 | /// 50 | /// Creates a set of dynamic objects based of the headers and values 51 | /// 52 | /// the table to create a set of dynamics from 53 | /// should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions 54 | /// a set of dynamics 55 | public static IEnumerable CreateDynamicSet(this Table table, bool doTypeConversion = true) 56 | { 57 | return from r in table.Rows 58 | select CreateDynamicInstance(r, doTypeConversion); 59 | } 60 | 61 | /// 62 | /// Validates if a dynamic instance matches the 63 | /// Throws descriptive exception if not 64 | /// 65 | /// the table to compare the instance against 66 | /// the instance to compare the table against 67 | /// should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions 68 | public static void CompareToDynamicInstance(this Table table, dynamic instance, bool doTypeConversion = true) 69 | { 70 | IList propDiffs = GetPropertyDifferences(table, instance); 71 | if (propDiffs.Any()) 72 | throw new DynamicInstanceComparisonException(propDiffs); 73 | 74 | AssertValuesOfRowDifference(table.Rows[0], instance, doTypeConversion); 75 | } 76 | 77 | /// 78 | /// Validates that the dynamic set matches the 79 | /// Throws descriptive exception if not 80 | /// 81 | /// the table to compare the set against 82 | /// the set to compare the table against 83 | /// should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions 84 | public static void CompareToDynamicSet(this Table table, IList set, bool doTypeConversion = true) 85 | { 86 | AssertEqualNumberOfRows(table, set); 87 | 88 | IList propDiffs = GetPropertyDifferences(table, set[0]); 89 | if (propDiffs.Any()) 90 | { 91 | throw new DynamicSetComparisonException(ERRORMESS_PROPERTY_DIFF_SET, propDiffs); 92 | } 93 | 94 | // Now we know that the table and the list has the same number of rows and properties 95 | 96 | var valueDifference = GetSetValueDifferences(table, set, doTypeConversion); 97 | 98 | if (valueDifference.Any()) 99 | { 100 | throw new DynamicSetComparisonException(ERRORMESS_PROPERTY_DIFF_SET, valueDifference); 101 | } 102 | } 103 | 104 | private static List GetSetValueDifferences(Table table, IList set, bool doTypeConversion = true) 105 | { 106 | var memberNames = Dynamic.GetMemberNames(set[0]); 107 | var valueDifference = new List(); 108 | 109 | for (var i = 0; i < set.Count; i++) 110 | { 111 | foreach (var memberName in memberNames) 112 | { 113 | var currentHeader = string.Empty; 114 | var rowValue = GetRowValue(i, table, memberName, out currentHeader, doTypeConversion); 115 | var rowType = rowValue.GetType().Name; 116 | var instanceValue = Dynamic.InvokeGet(set[i], memberName); 117 | var instanceType = instanceValue.GetType().Name; 118 | 119 | if (!instanceValue.Equals(rowValue)) 120 | { 121 | var difference = string.Format(ERRORMESS_SET_VALUES_DIFFERS, 122 | i + 1, 123 | currentHeader, 124 | memberName, 125 | instanceValue, 126 | instanceType, 127 | rowValue, 128 | rowType); 129 | 130 | valueDifference.Add(difference); 131 | } 132 | } 133 | } 134 | return valueDifference; 135 | } 136 | 137 | private static object GetRowValue(int rowIndex, Table table, string memberName, out string currentHeader, bool doTypeConversion = true) 138 | { 139 | object rowValue = null; 140 | currentHeader = string.Empty; 141 | foreach (var header in table.Header) 142 | { 143 | if (CreatePropertyName(header) == memberName) 144 | { 145 | currentHeader = header; 146 | rowValue = CreateTypedValue(table.Rows[rowIndex][header], doTypeConversion); 147 | break; 148 | } 149 | } 150 | return rowValue; 151 | } 152 | 153 | private static void AssertValuesOfRowDifference(TableRow tableRow, dynamic instance, bool doTypeConversion = true) 154 | { 155 | IList valueDiffs = ValidateValuesOfRow(tableRow, instance, doTypeConversion); 156 | if (valueDiffs.Any()) 157 | throw new DynamicInstanceComparisonException(valueDiffs); 158 | } 159 | 160 | private static IList GetPropertyDifferences(Table table, dynamic instance, bool doTypeConversion = true) 161 | { 162 | var tableHeadersAsPropertyNames = table.Header.Select(CreatePropertyName); 163 | IEnumerable instanceMembers = Dynamic.GetMemberNames(instance); 164 | 165 | return GetPropertyNameDifferences(tableHeadersAsPropertyNames, instanceMembers); 166 | } 167 | 168 | private static void AssertEqualNumberOfRows(Table table, IList set) 169 | { 170 | if (table.RowCount != set.Count) 171 | { 172 | var mess = string.Format(ERRORMESS_NUMBER_OF_ROWS_DIFFERS, table.RowCount, set.Count); 173 | throw new DynamicSetComparisonException(mess); 174 | } 175 | } 176 | 177 | private static IList ValidateValuesOfRow(TableRow tableRow, dynamic instance, bool doTypeConversion = true) 178 | { 179 | var valueDiffs = new List(); 180 | 181 | foreach (var header in tableRow.Keys) 182 | { 183 | var propertyName = CreatePropertyName(header); 184 | var valueFromInstance = Dynamic.InvokeGet(instance, propertyName); 185 | var typeFromInstance = valueFromInstance.GetType().Name; 186 | var valueFromTable = CreateTypedValue(tableRow[header], doTypeConversion); 187 | var typeFromTable = valueFromTable.GetType().Name; 188 | 189 | if (!valueFromInstance.Equals(valueFromTable)) 190 | { 191 | var mess = string.Format(ERRORMESS_VALUE_DIFFERS, propertyName, valueFromInstance, typeFromInstance, valueFromTable, typeFromTable); 192 | valueDiffs.Add(mess); 193 | } 194 | } 195 | return valueDiffs; 196 | } 197 | 198 | private static IList GetPropertyNameDifferences(IEnumerable tableHeadersAsPropertyNames, IEnumerable instanceMembers) 199 | { 200 | var allMembersInTableButNotInInstance = tableHeadersAsPropertyNames.Except(instanceMembers); 201 | var allMembersInInstanceButNotInTable = instanceMembers.Except(tableHeadersAsPropertyNames); 202 | 203 | var diffs = new List(); 204 | 205 | diffs.AddRange( 206 | allMembersInInstanceButNotInTable.Select( 207 | m => string.Format(ERRORMESS_NOT_ON_TABLE, m))); 208 | 209 | diffs.AddRange( 210 | allMembersInTableButNotInInstance.Select( 211 | m => string.Format(ERRORMESS_NOT_ON_INSTANCE, m))); 212 | 213 | return diffs; 214 | } 215 | 216 | private static Table CreateHorizontalTable(Table verticalFieldValueTable) 217 | { 218 | var dic = verticalFieldValueTable. 219 | Rows.ToDictionary(row => row[0], row => row[1]); 220 | 221 | var horizontalTable = new Table(dic.Keys.ToArray()); 222 | horizontalTable.AddRow(dic); 223 | return horizontalTable; 224 | } 225 | 226 | private static ExpandoObject CreateDynamicInstance(TableRow tablerow, bool doTypeConversion = true) 227 | { 228 | dynamic expando = new ExpandoObject(); 229 | var dicExpando = expando as IDictionary; 230 | 231 | foreach (var header in tablerow.Keys) 232 | { 233 | var propName = CreatePropertyName(header); 234 | var propValue = CreateTypedValue(tablerow[header], doTypeConversion); 235 | dicExpando.Add(propName, propValue); 236 | } 237 | 238 | return expando; 239 | } 240 | 241 | private static object CreateTypedValue(string valueFromTable, bool doTypeConversion = true) 242 | { 243 | if (!doTypeConversion) 244 | return valueFromTable; 245 | 246 | int i; 247 | if (int.TryParse(valueFromTable, out i)) 248 | return i; 249 | 250 | double db; 251 | if (Double.TryParse(valueFromTable, out db)) 252 | { 253 | decimal d; 254 | if (Decimal.TryParse(valueFromTable, out d) && d.Equals((decimal)db)) 255 | { 256 | return db; 257 | } 258 | return d; 259 | } 260 | 261 | bool b; 262 | if (Boolean.TryParse(valueFromTable, out b)) 263 | return b; 264 | 265 | DateTime dt; 266 | if (DateTime.TryParse(valueFromTable, out dt)) 267 | return dt; 268 | 269 | return valueFromTable; 270 | } 271 | 272 | private static string CreatePropertyName(string header) 273 | { 274 | var cleanedHeader = RemoveReservedChars(header); 275 | var propName = FixCasing(cleanedHeader); 276 | 277 | // Throw if no chars in string 278 | if (propName.Length != 0) return propName; 279 | 280 | var mess = string.Format("Property '{0}' only contains reserved C# characters", header); 281 | throw new DynamicInstanceFromTableException(mess); 282 | } 283 | 284 | private static string FixCasing(string header) 285 | { 286 | var arr = header.Split(' '); 287 | var propName = arr[0]; // leave the first element as is, since it might be correct cased... 288 | 289 | for (var i = 1; i < arr.Length; i++) 290 | { 291 | var s = arr[i]; 292 | if (s.Length > 0) 293 | { 294 | propName += s[0].ToString().ToUpperInvariant() + 295 | s.Substring(1).ToLowerInvariant(); 296 | } 297 | } 298 | 299 | return propName; 300 | } 301 | 302 | private static string RemoveReservedChars(string orgPropertyName) 303 | { 304 | const string pattern = @"[^\w\s]"; 305 | const string replacement = ""; 306 | return Regex.Replace(orgPropertyName, pattern, replacement); 307 | } 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ValueConversions.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Conversions of values")] 22 | public partial class ConversionsOfValuesFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "ValueConversions.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Conversions of values", "\tIn order to easier compare values of the most common types\n\tAs a user of SpecFlo" + 35 | "w Dynamic\n\tI want SpecFlow Dynamic to translate strings into the closest ressemb" + 36 | "ling real type", ProgrammingLanguage.CSharp, ((string[])(null))); 37 | testRunner.OnFeatureStart(featureInfo); 38 | } 39 | 40 | [NUnit.Framework.OneTimeTearDownAttribute()] 41 | public virtual void FeatureTearDown() 42 | { 43 | testRunner.OnFeatureEnd(); 44 | testRunner = null; 45 | } 46 | 47 | [NUnit.Framework.SetUpAttribute()] 48 | public virtual void TestInitialize() 49 | { 50 | } 51 | 52 | [NUnit.Framework.TearDownAttribute()] 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | [NUnit.Framework.TestAttribute()] 75 | [NUnit.Framework.DescriptionAttribute("Strings should be translated to string")] 76 | public virtual void StringsShouldBeTranslatedToString() 77 | { 78 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Strings should be translated to string", null, ((string[])(null))); 79 | #line 7 80 | this.ScenarioInitialize(scenarioInfo); 81 | this.ScenarioStart(); 82 | #line hidden 83 | TechTalk.SpecFlow.Table table41 = new TechTalk.SpecFlow.Table(new string[] { 84 | "Name"}); 85 | table41.AddRow(new string[] { 86 | "Marcus"}); 87 | #line 8 88 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table41, "When "); 89 | #line 11 90 | testRunner.Then("the Name property should equal \'Marcus\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 91 | #line hidden 92 | this.ScenarioCleanup(); 93 | } 94 | 95 | [NUnit.Framework.TestAttribute()] 96 | [NUnit.Framework.DescriptionAttribute("Integers should be translated from strings")] 97 | public virtual void IntegersShouldBeTranslatedFromStrings() 98 | { 99 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Integers should be translated from strings", null, ((string[])(null))); 100 | #line 13 101 | this.ScenarioInitialize(scenarioInfo); 102 | this.ScenarioStart(); 103 | #line hidden 104 | TechTalk.SpecFlow.Table table42 = new TechTalk.SpecFlow.Table(new string[] { 105 | "Age"}); 106 | table42.AddRow(new string[] { 107 | "39"}); 108 | #line 14 109 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table42, "When "); 110 | #line 17 111 | testRunner.Then("the Age property should equal 39", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 112 | #line hidden 113 | this.ScenarioCleanup(); 114 | } 115 | 116 | [NUnit.Framework.TestAttribute()] 117 | [NUnit.Framework.DescriptionAttribute("Doubles should be translated from strings")] 118 | public virtual void DoublesShouldBeTranslatedFromStrings() 119 | { 120 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Doubles should be translated from strings", null, ((string[])(null))); 121 | #line 19 122 | this.ScenarioInitialize(scenarioInfo); 123 | this.ScenarioStart(); 124 | #line hidden 125 | TechTalk.SpecFlow.Table table43 = new TechTalk.SpecFlow.Table(new string[] { 126 | "Length in meters"}); 127 | table43.AddRow(new string[] { 128 | "1.96"}); 129 | #line 20 130 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table43, "When "); 131 | #line 23 132 | testRunner.Then("the LengthInMeters property should equal \'1.96\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 133 | #line hidden 134 | this.ScenarioCleanup(); 135 | } 136 | 137 | [NUnit.Framework.TestAttribute()] 138 | [NUnit.Framework.DescriptionAttribute("Decimals should be translated from strings")] 139 | public virtual void DecimalsShouldBeTranslatedFromStrings() 140 | { 141 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Decimals should be translated from strings", null, ((string[])(null))); 142 | #line 25 143 | this.ScenarioInitialize(scenarioInfo); 144 | this.ScenarioStart(); 145 | #line hidden 146 | TechTalk.SpecFlow.Table table44 = new TechTalk.SpecFlow.Table(new string[] { 147 | "Molecular Weight"}); 148 | table44.AddRow(new string[] { 149 | "1000000000.1111991111"}); 150 | #line 26 151 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table44, "When "); 152 | #line 29 153 | testRunner.Then("the MolecularWeight property should equal \'1000000000.1111991111\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 154 | #line hidden 155 | this.ScenarioCleanup(); 156 | } 157 | 158 | [NUnit.Framework.TestAttribute()] 159 | [NUnit.Framework.DescriptionAttribute("Dates should be translated from strings")] 160 | public virtual void DatesShouldBeTranslatedFromStrings() 161 | { 162 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Dates should be translated from strings", null, ((string[])(null))); 163 | #line 31 164 | this.ScenarioInitialize(scenarioInfo); 165 | this.ScenarioStart(); 166 | #line hidden 167 | TechTalk.SpecFlow.Table table45 = new TechTalk.SpecFlow.Table(new string[] { 168 | "Birth date"}); 169 | table45.AddRow(new string[] { 170 | "1972-10-09"}); 171 | #line 32 172 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table45, "When "); 173 | #line 35 174 | testRunner.Then("the BirthDate property should equal 1972-10-09", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 175 | #line hidden 176 | this.ScenarioCleanup(); 177 | } 178 | 179 | [NUnit.Framework.TestAttribute()] 180 | [NUnit.Framework.DescriptionAttribute("Bools should be translated from strings")] 181 | public virtual void BoolsShouldBeTranslatedFromStrings() 182 | { 183 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Bools should be translated from strings", null, ((string[])(null))); 184 | #line 37 185 | this.ScenarioInitialize(scenarioInfo); 186 | this.ScenarioStart(); 187 | #line hidden 188 | TechTalk.SpecFlow.Table table46 = new TechTalk.SpecFlow.Table(new string[] { 189 | "Is developer"}); 190 | table46.AddRow(new string[] { 191 | "false"}); 192 | #line 38 193 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table46, "When "); 194 | #line 41 195 | testRunner.Then("the IsDeveloper property should equal \'false\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 196 | #line hidden 197 | this.ScenarioCleanup(); 198 | } 199 | 200 | [NUnit.Framework.TestAttribute()] 201 | [NUnit.Framework.DescriptionAttribute("A strange double should not be translated into a date")] 202 | public virtual void AStrangeDoubleShouldNotBeTranslatedIntoADate() 203 | { 204 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A strange double should not be translated into a date", null, ((string[])(null))); 205 | #line 43 206 | this.ScenarioInitialize(scenarioInfo); 207 | this.ScenarioStart(); 208 | #line hidden 209 | TechTalk.SpecFlow.Table table47 = new TechTalk.SpecFlow.Table(new string[] { 210 | "Length in meters"}); 211 | table47.AddRow(new string[] { 212 | "4.567"}); 213 | #line 44 214 | testRunner.When("I create a dynamic instance from this table", ((string)(null)), table47, "When "); 215 | #line 47 216 | testRunner.Then("the LengthInMeters property should equal \'4.567\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 217 | #line hidden 218 | this.ScenarioCleanup(); 219 | } 220 | 221 | [NUnit.Framework.TestAttribute()] 222 | [NUnit.Framework.DescriptionAttribute("There\'s ways to disable type conversion for instance creation")] 223 | public virtual void TheresWaysToDisableTypeConversionForInstanceCreation() 224 | { 225 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("There\'s ways to disable type conversion for instance creation", null, ((string[])(null))); 226 | #line 49 227 | this.ScenarioInitialize(scenarioInfo); 228 | this.ScenarioStart(); 229 | #line hidden 230 | TechTalk.SpecFlow.Table table48 = new TechTalk.SpecFlow.Table(new string[] { 231 | "Name", 232 | "Age", 233 | "Birth date", 234 | "Length in meters"}); 235 | table48.AddRow(new string[] { 236 | "012345", 237 | "044", 238 | "1972-13-09", 239 | "1,96"}); 240 | #line 50 241 | testRunner.When("I create a dynamic instance from this table using no type conversion", ((string)(null)), table48, "When "); 242 | #line 53 243 | testRunner.Then("the Name value should still be \'012345\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 244 | #line 54 245 | testRunner.And("the Age value should still be \'044\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 246 | #line 55 247 | testRunner.And("the birth date should still be \'1972-13-09\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 248 | #line 56 249 | testRunner.And("length in meter should still be \'1,96\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 250 | #line hidden 251 | this.ScenarioCleanup(); 252 | } 253 | 254 | [NUnit.Framework.TestAttribute()] 255 | [NUnit.Framework.DescriptionAttribute("There\'s ways to disable type conversion for instance creation with key/value tabl" + 256 | "es")] 257 | public virtual void TheresWaysToDisableTypeConversionForInstanceCreationWithKeyValueTables() 258 | { 259 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("There\'s ways to disable type conversion for instance creation with key/value tabl" + 260 | "es", null, ((string[])(null))); 261 | #line 58 262 | this.ScenarioInitialize(scenarioInfo); 263 | this.ScenarioStart(); 264 | #line hidden 265 | TechTalk.SpecFlow.Table table49 = new TechTalk.SpecFlow.Table(new string[] { 266 | "Key", 267 | "Value"}); 268 | table49.AddRow(new string[] { 269 | "Name", 270 | "012345"}); 271 | table49.AddRow(new string[] { 272 | "Age", 273 | "044"}); 274 | table49.AddRow(new string[] { 275 | "Birth date", 276 | "1972-13-09"}); 277 | table49.AddRow(new string[] { 278 | "Length in meters", 279 | "1,96"}); 280 | #line 59 281 | testRunner.When("I create a dynamic instance from this table using no type conversion", ((string)(null)), table49, "When "); 282 | #line 65 283 | testRunner.Then("the Name value should still be \'012345\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 284 | #line 66 285 | testRunner.And("the Age value should still be \'044\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 286 | #line 67 287 | testRunner.And("the birth date should still be \'1972-13-09\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 288 | #line 68 289 | testRunner.And("length in meter should still be \'1,96\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 290 | #line hidden 291 | this.ScenarioCleanup(); 292 | } 293 | 294 | [NUnit.Framework.TestAttribute()] 295 | [NUnit.Framework.DescriptionAttribute("There\'s ways to disable type conversion for set creation")] 296 | public virtual void TheresWaysToDisableTypeConversionForSetCreation() 297 | { 298 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("There\'s ways to disable type conversion for set creation", null, ((string[])(null))); 299 | #line 70 300 | this.ScenarioInitialize(scenarioInfo); 301 | this.ScenarioStart(); 302 | #line hidden 303 | TechTalk.SpecFlow.Table table50 = new TechTalk.SpecFlow.Table(new string[] { 304 | "Name", 305 | "Age"}); 306 | table50.AddRow(new string[] { 307 | "012345", 308 | "044"}); 309 | table50.AddRow(new string[] { 310 | "Arvid", 311 | "1"}); 312 | #line 71 313 | testRunner.When("I create a set of dynamic instances from this table using no type conversion", ((string)(null)), table50, "When "); 314 | #line 75 315 | testRunner.Then("I should have a list of 2 dynamic objects", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 316 | #line 76 317 | testRunner.And("the 1 item should still Name equal \'012345\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 318 | #line 77 319 | testRunner.And("the 1 item should still Age equal \'044\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 320 | #line hidden 321 | this.ScenarioCleanup(); 322 | } 323 | 324 | [NUnit.Framework.TestAttribute()] 325 | [NUnit.Framework.DescriptionAttribute("There\'s ways to disable type conversion for matching a dynamic instance against a" + 326 | " table")] 327 | public virtual void TheresWaysToDisableTypeConversionForMatchingADynamicInstanceAgainstATable() 328 | { 329 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("There\'s ways to disable type conversion for matching a dynamic instance against a" + 330 | " table", null, ((string[])(null))); 331 | #line 79 332 | this.ScenarioInitialize(scenarioInfo); 333 | this.ScenarioStart(); 334 | #line hidden 335 | TechTalk.SpecFlow.Table table51 = new TechTalk.SpecFlow.Table(new string[] { 336 | "Name", 337 | "Age"}); 338 | table51.AddRow(new string[] { 339 | "012345", 340 | "039"}); 341 | #line 80 342 | testRunner.Given("I create a dynamic instance from this table using no type conversion", ((string)(null)), table51, "Given "); 343 | #line hidden 344 | TechTalk.SpecFlow.Table table52 = new TechTalk.SpecFlow.Table(new string[] { 345 | "Name", 346 | "Age"}); 347 | table52.AddRow(new string[] { 348 | "012345", 349 | "039"}); 350 | #line 83 351 | testRunner.When("I compare it to this table using no type conversion", ((string)(null)), table52, "When "); 352 | #line 86 353 | testRunner.Then("no instance comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 354 | #line hidden 355 | this.ScenarioCleanup(); 356 | } 357 | 358 | [NUnit.Framework.TestAttribute()] 359 | [NUnit.Framework.DescriptionAttribute("Comparing against an identical table should match")] 360 | public virtual void ComparingAgainstAnIdenticalTableShouldMatch() 361 | { 362 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Comparing against an identical table should match", null, ((string[])(null))); 363 | #line 88 364 | this.ScenarioInitialize(scenarioInfo); 365 | this.ScenarioStart(); 366 | #line hidden 367 | TechTalk.SpecFlow.Table table53 = new TechTalk.SpecFlow.Table(new string[] { 368 | "Name", 369 | "Age"}); 370 | table53.AddRow(new string[] { 371 | "012345", 372 | "039"}); 373 | table53.AddRow(new string[] { 374 | "065484", 375 | "003"}); 376 | #line 89 377 | testRunner.Given("I create a set of dynamic instances from this table using no type conversion", ((string)(null)), table53, "Given "); 378 | #line hidden 379 | TechTalk.SpecFlow.Table table54 = new TechTalk.SpecFlow.Table(new string[] { 380 | "Name", 381 | "Age"}); 382 | table54.AddRow(new string[] { 383 | "012345", 384 | "039"}); 385 | table54.AddRow(new string[] { 386 | "065484", 387 | "003"}); 388 | #line 93 389 | testRunner.When("I compare the set to this table using no type conversion", ((string)(null)), table54, "When "); 390 | #line 97 391 | testRunner.Then("no set comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 392 | #line hidden 393 | this.ScenarioCleanup(); 394 | } 395 | } 396 | } 397 | #pragma warning restore 398 | #endregion 399 | -------------------------------------------------------------------------------- /SpecFlow.Assist.Dynamic.Specs/ComparingDynamicSets.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlow.Assist.Dynamic.Specs 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | [NUnit.Framework.TestFixtureAttribute()] 21 | [NUnit.Framework.DescriptionAttribute("Comparing dynamic sets against tables")] 22 | public partial class ComparingDynamicSetsAgainstTablesFeature 23 | { 24 | 25 | private TechTalk.SpecFlow.ITestRunner testRunner; 26 | 27 | #line 1 "ComparingDynamicSets.feature" 28 | #line hidden 29 | 30 | [NUnit.Framework.OneTimeSetUpAttribute()] 31 | public virtual void FeatureSetup() 32 | { 33 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 34 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Comparing dynamic sets against tables", "\tIn order to easier and slicker do assertions\n\tAs a SpecFlow developer\n\tI want to" + 35 | " be able to compare a list of dynamic items against a table", ProgrammingLanguage.CSharp, ((string[])(null))); 36 | testRunner.OnFeatureStart(featureInfo); 37 | } 38 | 39 | [NUnit.Framework.OneTimeTearDownAttribute()] 40 | public virtual void FeatureTearDown() 41 | { 42 | testRunner.OnFeatureEnd(); 43 | testRunner = null; 44 | } 45 | 46 | [NUnit.Framework.SetUpAttribute()] 47 | public virtual void TestInitialize() 48 | { 49 | } 50 | 51 | [NUnit.Framework.TearDownAttribute()] 52 | public virtual void ScenarioTearDown() 53 | { 54 | testRunner.OnScenarioEnd(); 55 | } 56 | 57 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 58 | { 59 | testRunner.OnScenarioInitialize(scenarioInfo); 60 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 61 | } 62 | 63 | public virtual void ScenarioStart() 64 | { 65 | testRunner.OnScenarioStart(); 66 | } 67 | 68 | public virtual void ScenarioCleanup() 69 | { 70 | testRunner.CollectScenarioErrors(); 71 | } 72 | 73 | [NUnit.Framework.TestAttribute()] 74 | [NUnit.Framework.DescriptionAttribute("Comparing against an identical table should match")] 75 | public virtual void ComparingAgainstAnIdenticalTableShouldMatch() 76 | { 77 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Comparing against an identical table should match", null, ((string[])(null))); 78 | #line 7 79 | this.ScenarioInitialize(scenarioInfo); 80 | this.ScenarioStart(); 81 | #line hidden 82 | TechTalk.SpecFlow.Table table15 = new TechTalk.SpecFlow.Table(new string[] { 83 | "Name", 84 | "Age", 85 | "Birth date", 86 | "Length in meters"}); 87 | table15.AddRow(new string[] { 88 | "Marcus", 89 | "39", 90 | "1972-10-09", 91 | "1.96"}); 92 | table15.AddRow(new string[] { 93 | "Albert", 94 | "3", 95 | "2008-01-24", 96 | "1.03"}); 97 | table15.AddRow(new string[] { 98 | "Gustav", 99 | "1", 100 | "2010-03-19", 101 | "0.84"}); 102 | table15.AddRow(new string[] { 103 | "Arvid", 104 | "1", 105 | "2010-03-19", 106 | "0.85"}); 107 | #line 8 108 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table15, "Given "); 109 | #line hidden 110 | TechTalk.SpecFlow.Table table16 = new TechTalk.SpecFlow.Table(new string[] { 111 | "Name", 112 | "Age", 113 | "Birth date", 114 | "Length in meters"}); 115 | table16.AddRow(new string[] { 116 | "Marcus", 117 | "39", 118 | "1972-10-09", 119 | "1.96"}); 120 | table16.AddRow(new string[] { 121 | "Albert", 122 | "3", 123 | "2008-01-24", 124 | "1.03"}); 125 | table16.AddRow(new string[] { 126 | "Gustav", 127 | "1", 128 | "2010-03-19", 129 | "0.84"}); 130 | table16.AddRow(new string[] { 131 | "Arvid", 132 | "1", 133 | "2010-03-19", 134 | "0.85"}); 135 | #line 14 136 | testRunner.When("I compare the set to this table", ((string)(null)), table16, "When "); 137 | #line 20 138 | testRunner.Then("no set comparison exception should have been thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 139 | #line hidden 140 | this.ScenarioCleanup(); 141 | } 142 | 143 | [NUnit.Framework.TestAttribute()] 144 | [NUnit.Framework.DescriptionAttribute("Not matching when 1 column name differ")] 145 | public virtual void NotMatchingWhen1ColumnNameDiffer() 146 | { 147 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when 1 column name differ", null, ((string[])(null))); 148 | #line 22 149 | this.ScenarioInitialize(scenarioInfo); 150 | this.ScenarioStart(); 151 | #line hidden 152 | TechTalk.SpecFlow.Table table17 = new TechTalk.SpecFlow.Table(new string[] { 153 | "Name"}); 154 | table17.AddRow(new string[] { 155 | "Marcus"}); 156 | table17.AddRow(new string[] { 157 | "Albert"}); 158 | table17.AddRow(new string[] { 159 | "Gustav"}); 160 | table17.AddRow(new string[] { 161 | "Arvid"}); 162 | #line 23 163 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table17, "Given "); 164 | #line hidden 165 | TechTalk.SpecFlow.Table table18 = new TechTalk.SpecFlow.Table(new string[] { 166 | "N"}); 167 | table18.AddRow(new string[] { 168 | "Marcus"}); 169 | table18.AddRow(new string[] { 170 | "Albert"}); 171 | table18.AddRow(new string[] { 172 | "Gustav"}); 173 | table18.AddRow(new string[] { 174 | "Arvid"}); 175 | #line 29 176 | testRunner.When("I compare the set to this table", ((string)(null)), table18, "When "); 177 | #line 35 178 | testRunner.Then("an set comparision exception should be thrown with 2 differences", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 179 | #line 36 180 | testRunner.And("one set difference should be on the \'Name\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 181 | #line 37 182 | testRunner.And("one set difference should be on the \'N\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 183 | #line hidden 184 | this.ScenarioCleanup(); 185 | } 186 | 187 | [NUnit.Framework.TestAttribute()] 188 | [NUnit.Framework.DescriptionAttribute("Not matching when 2 header differ")] 189 | public virtual void NotMatchingWhen2HeaderDiffer() 190 | { 191 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when 2 header differ", null, ((string[])(null))); 192 | #line 39 193 | this.ScenarioInitialize(scenarioInfo); 194 | this.ScenarioStart(); 195 | #line hidden 196 | TechTalk.SpecFlow.Table table19 = new TechTalk.SpecFlow.Table(new string[] { 197 | "Name", 198 | "Age"}); 199 | table19.AddRow(new string[] { 200 | "Marcus", 201 | "39"}); 202 | table19.AddRow(new string[] { 203 | "Albert", 204 | "3"}); 205 | table19.AddRow(new string[] { 206 | "Gustav", 207 | "1"}); 208 | table19.AddRow(new string[] { 209 | "Arvid", 210 | "1"}); 211 | #line 40 212 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table19, "Given "); 213 | #line hidden 214 | TechTalk.SpecFlow.Table table20 = new TechTalk.SpecFlow.Table(new string[] { 215 | "Namn", 216 | "Ålder"}); 217 | table20.AddRow(new string[] { 218 | "Marcus", 219 | "39"}); 220 | table20.AddRow(new string[] { 221 | "Albert", 222 | "3"}); 223 | table20.AddRow(new string[] { 224 | "Gustav", 225 | "1"}); 226 | table20.AddRow(new string[] { 227 | "Arvid", 228 | "1"}); 229 | #line 46 230 | testRunner.When("I compare the set to this table", ((string)(null)), table20, "When "); 231 | #line 52 232 | testRunner.Then("an set comparision exception should be thrown with 4 differences", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 233 | #line 53 234 | testRunner.And("one set difference should be on the \'Name\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 235 | #line 54 236 | testRunner.And("one set difference should be on the \'Age\' field of the instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 237 | #line 55 238 | testRunner.And("one set difference should be on the \'Namn\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 239 | #line 56 240 | testRunner.And("one set difference should be on the \'Ålder\' column of the table", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 241 | #line hidden 242 | this.ScenarioCleanup(); 243 | } 244 | 245 | [NUnit.Framework.TestAttribute()] 246 | [NUnit.Framework.DescriptionAttribute("Not matching when the number of rows are more in the table")] 247 | public virtual void NotMatchingWhenTheNumberOfRowsAreMoreInTheTable() 248 | { 249 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Not matching when the number of rows are more in the table", null, ((string[])(null))); 250 | #line 58 251 | this.ScenarioInitialize(scenarioInfo); 252 | this.ScenarioStart(); 253 | #line hidden 254 | TechTalk.SpecFlow.Table table21 = new TechTalk.SpecFlow.Table(new string[] { 255 | "Name", 256 | "Age"}); 257 | table21.AddRow(new string[] { 258 | "Marcus", 259 | "39"}); 260 | table21.AddRow(new string[] { 261 | "Albert", 262 | "3"}); 263 | #line 59 264 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table21, "Given "); 265 | #line hidden 266 | TechTalk.SpecFlow.Table table22 = new TechTalk.SpecFlow.Table(new string[] { 267 | "Name", 268 | "Age"}); 269 | table22.AddRow(new string[] { 270 | "Marcus", 271 | "39"}); 272 | table22.AddRow(new string[] { 273 | "Albert", 274 | "3"}); 275 | table22.AddRow(new string[] { 276 | "Arvid", 277 | "1"}); 278 | #line 63 279 | testRunner.When("I compare the set to this table", ((string)(null)), table22, "When "); 280 | #line 68 281 | testRunner.Then("an set comparison exception should be thrown", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 282 | #line 69 283 | testRunner.And("the error message for different rows should expect 3 rows for table and 2 rows fo" + 284 | "r instance", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 285 | #line hidden 286 | this.ScenarioCleanup(); 287 | } 288 | 289 | [NUnit.Framework.TestAttribute()] 290 | [NUnit.Framework.DescriptionAttribute("Differences on 1 value in 1 row should throw exceptions")] 291 | public virtual void DifferencesOn1ValueIn1RowShouldThrowExceptions() 292 | { 293 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Differences on 1 value in 1 row should throw exceptions", null, ((string[])(null))); 294 | #line 71 295 | this.ScenarioInitialize(scenarioInfo); 296 | this.ScenarioStart(); 297 | #line hidden 298 | TechTalk.SpecFlow.Table table23 = new TechTalk.SpecFlow.Table(new string[] { 299 | "Name", 300 | "Age", 301 | "Birth date", 302 | "Length in meters"}); 303 | table23.AddRow(new string[] { 304 | "Marcus", 305 | "39", 306 | "1972-10-09", 307 | "1.96"}); 308 | table23.AddRow(new string[] { 309 | "Albert", 310 | "3", 311 | "2008-01-24", 312 | "1.03"}); 313 | #line 72 314 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table23, "Given "); 315 | #line hidden 316 | TechTalk.SpecFlow.Table table24 = new TechTalk.SpecFlow.Table(new string[] { 317 | "Name", 318 | "Age", 319 | "Birth date", 320 | "Length in meters"}); 321 | table24.AddRow(new string[] { 322 | "Hugo", 323 | "39", 324 | "1972-10-09", 325 | "1.96"}); 326 | table24.AddRow(new string[] { 327 | "Albert", 328 | "3", 329 | "2008-01-24", 330 | "1.03"}); 331 | #line 76 332 | testRunner.When("I compare the set to this table", ((string)(null)), table24, "When "); 333 | #line 80 334 | testRunner.Then("an set comparision exception should be thrown with 1 difference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 335 | #line 81 336 | testRunner.And("1 difference should be on row 1 on property \'Name\' for the values \'Marcus\' and \'H" + 337 | "ugo\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 338 | #line hidden 339 | this.ScenarioCleanup(); 340 | } 341 | 342 | [NUnit.Framework.TestAttribute()] 343 | [NUnit.Framework.DescriptionAttribute("Differences on 2 value in 2 different row should throw exceptions")] 344 | public virtual void DifferencesOn2ValueIn2DifferentRowShouldThrowExceptions() 345 | { 346 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Differences on 2 value in 2 different row should throw exceptions", null, ((string[])(null))); 347 | #line 83 348 | this.ScenarioInitialize(scenarioInfo); 349 | this.ScenarioStart(); 350 | #line hidden 351 | TechTalk.SpecFlow.Table table25 = new TechTalk.SpecFlow.Table(new string[] { 352 | "Name", 353 | "Age", 354 | "Birth date", 355 | "Length in meters"}); 356 | table25.AddRow(new string[] { 357 | "Marcus", 358 | "39", 359 | "1972-10-09", 360 | "1.96"}); 361 | table25.AddRow(new string[] { 362 | "Albert", 363 | "3", 364 | "2008-01-24", 365 | "0.03"}); 366 | #line 84 367 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table25, "Given "); 368 | #line hidden 369 | TechTalk.SpecFlow.Table table26 = new TechTalk.SpecFlow.Table(new string[] { 370 | "Name", 371 | "Age", 372 | "Birth date", 373 | "Length in meters"}); 374 | table26.AddRow(new string[] { 375 | "Hugo", 376 | "39", 377 | "1972-10-09", 378 | "1.96"}); 379 | table26.AddRow(new string[] { 380 | "Albert", 381 | "3", 382 | "2008-01-24", 383 | "1.03"}); 384 | #line 88 385 | testRunner.When("I compare the set to this table", ((string)(null)), table26, "When "); 386 | #line 92 387 | testRunner.Then("an set comparision exception should be thrown with 2 difference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 388 | #line 93 389 | testRunner.And("1 difference should be on row 1 on property \'Name\' for the values \'Marcus\' and \'H" + 390 | "ugo\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 391 | #line 94 392 | testRunner.And("2 difference should be on row 2 on property \'LengthInMeters\' for the values \'0.03" + 393 | "\' and \'1.03\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 394 | #line hidden 395 | this.ScenarioCleanup(); 396 | } 397 | 398 | [NUnit.Framework.TestAttribute()] 399 | [NUnit.Framework.DescriptionAttribute("Differences on 4 value on 1 row should throw exceptions")] 400 | public virtual void DifferencesOn4ValueOn1RowShouldThrowExceptions() 401 | { 402 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Differences on 4 value on 1 row should throw exceptions", null, ((string[])(null))); 403 | #line 96 404 | this.ScenarioInitialize(scenarioInfo); 405 | this.ScenarioStart(); 406 | #line hidden 407 | TechTalk.SpecFlow.Table table27 = new TechTalk.SpecFlow.Table(new string[] { 408 | "Name", 409 | "Age", 410 | "Birth date", 411 | "Length in meters"}); 412 | table27.AddRow(new string[] { 413 | "Marcus", 414 | "39", 415 | "1972-10-09", 416 | "1.96"}); 417 | table27.AddRow(new string[] { 418 | "Albert", 419 | "3", 420 | "2008-01-24", 421 | "1.03"}); 422 | #line 97 423 | testRunner.Given("I create a set of dynamic instances from this table", ((string)(null)), table27, "Given "); 424 | #line hidden 425 | TechTalk.SpecFlow.Table table28 = new TechTalk.SpecFlow.Table(new string[] { 426 | "Name", 427 | "Age", 428 | "Birth date", 429 | "Length in meters"}); 430 | table28.AddRow(new string[] { 431 | "Marcus", 432 | "39", 433 | "1972-10-09", 434 | "1.96"}); 435 | table28.AddRow(new string[] { 436 | "Hugo", 437 | "2", 438 | "2010-01-24", 439 | "0.03"}); 440 | #line 101 441 | testRunner.When("I compare the set to this table", ((string)(null)), table28, "When "); 442 | #line 105 443 | testRunner.Then("an set comparision exception should be thrown with 4 difference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 444 | #line 106 445 | testRunner.And("1 difference should be on row 2 on property \'Name\' for the values \'Marcus\' and \'H" + 446 | "ugo\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 447 | #line 107 448 | testRunner.And("2 difference should be on row 2 on property \'Age\' for the values \'3\' and \'2\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 449 | #line 108 450 | testRunner.And("3 difference should be on row 2 on property \'BirthDate\' for the values \'2008-01-2" + 451 | "4 12:00AM\' and \'2010-01-24 12:00AM\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 452 | #line 109 453 | testRunner.And("4 difference should be on row 2 on property \'LengthInMeters\' for the values \'1.03" + 454 | "\' and \'0.03\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 455 | #line hidden 456 | this.ScenarioCleanup(); 457 | } 458 | } 459 | } 460 | #pragma warning restore 461 | #endregion 462 | --------------------------------------------------------------------------------