/Test/InterpreterTest.cs
C# | 108 lines | 96 code | 12 blank | 0 comment | 0 complexity | 8166ab2b860b6b0f5dba81e32d8c92bb MD5 | raw file
Possible License(s): BSD-3-Clause
- using System.Linq;
- using Behaviorize.CodeGenerator.CodeModel;
- using Behaviorize.CodeGenerator.TextInterpretation;
- using FluentAssertions;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- namespace Test
- {
- [TestClass]
- public class InterpreterTest
- {
- [TestMethod]
- public void TestFeatures()
- {
- const string spec =
- @"
- Feature: Pairing of operators
- As a user
- I want to be able to see paired operators
- so that I can party all night long
-
- Scenario: Two operators
- Given there are two operators
- and a single tag
- when someone walks in the door
- then one should not be two
-
- Scenario: Three operators
- Given my birthday
- When clock turns seven
- then my family sings for me";
-
- Feature feature = Interpreter.ParseSpecificationText(spec);
-
- feature.Name.Should().Be("Pairing of operators");
- feature.Description.Should().BeBlank("because no description is given");
- feature.Story.Role.Should().Be("user");
- feature.Story.Goal.Should().Be("to be able to see paired operators");
- feature.Story.Motivation.Should().Be("I can party all night long");
-
- feature.Scenarios.Should().HaveCount(2);
-
- feature.Scenarios[0].Name.Should().Be("Two operators");
- feature.Scenarios[0].Given[0].ToString().Should().Be("there are two operators");
- feature.Scenarios[0].Given[1].ToString().Should().Be("a single tag");
- feature.Scenarios[0].When.Single().ToString().Should().Be("someone walks in the door");
- feature.Scenarios[0].Then.Single().ToString().Should().Be("one should not be two");
-
- feature.Scenarios[1].Name.Should().Be("Three operators");
- feature.Scenarios[1].Given.Single().ToString().Should().Be("my birthday");
- feature.Scenarios[1].When.Single().ToString().Should().Be("clock turns seven");
- feature.Scenarios[1].Then.Single().ToString().Should().Be("my family sings for me");
- }
-
- [TestMethod]
- public void TestScenariosWithExamples()
- {
- const string spec =
- @"
- Feature: Calculation
- Description: A simple calculator with addition features
-
- Scenario: Addition of two numbers
- Given first number if <first>
- when I add <second>
- then the result should be <result>
-
- Examples:
- |first|second|result|
- |1|4|five|
- |4|2|six|
-
- Scenario: Addition of three numbers
- Given first number if <first>
- when I add <second>
- and <third>
- then the result should be <result>
-
- Examples:
- |first|second|third|result|
- |1.2|4|4|9|
- |4|2|10|hej|";
-
- Feature feature = Interpreter.ParseSpecificationText(spec);
- feature.Scenarios.Should().HaveCount(2);
-
- Scenario twoNumbersScenario = feature.Scenarios.First();
-
- twoNumbersScenario.Given.Single().GetMethodName().Should().Be("FirstNumberIf_");
-
- twoNumbersScenario.Examples.Should().HaveCount(3);
- twoNumbersScenario.Examples["first"].Should().HaveCount(2);
- twoNumbersScenario.Examples["first"].Should().HaveSameCount(twoNumbersScenario.Examples["second"]);
- twoNumbersScenario.Examples["first"].Should().HaveSameCount(twoNumbersScenario.Examples["result"]);
- Assert.AreEqual(1, twoNumbersScenario.Examples["first"][0]);
- Assert.AreEqual(4, twoNumbersScenario.Examples["first"][1]);
- Assert.AreEqual(4, twoNumbersScenario.Examples["second"][0]);
- Assert.AreEqual(2, twoNumbersScenario.Examples["second"][1]);
- Assert.AreEqual("five", twoNumbersScenario.Examples["result"][0]);
- Assert.AreEqual("six", twoNumbersScenario.Examples["result"][1]);
-
- Scenario threeNumberScenario = feature.Scenarios.Skip(1).First();
- threeNumberScenario.Examples.Should().HaveCount(4);
- Assert.AreEqual(1.2, threeNumberScenario.Examples["first"][0]);
- Assert.AreEqual("hej", threeNumberScenario.Examples["result"][1]);
- }
- }
- }