PageRenderTime 20ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Test/InterpreterTest.cs

http://behaviorize.codeplex.com
C# | 108 lines | 96 code | 12 blank | 0 comment | 0 complexity | 8166ab2b860b6b0f5dba81e32d8c92bb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System.Linq;
  2. using Behaviorize.CodeGenerator.CodeModel;
  3. using Behaviorize.CodeGenerator.TextInterpretation;
  4. using FluentAssertions;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace Test
  7. {
  8. [TestClass]
  9. public class InterpreterTest
  10. {
  11. [TestMethod]
  12. public void TestFeatures()
  13. {
  14. const string spec =
  15. @"
  16. Feature: Pairing of operators
  17. As a user
  18. I want to be able to see paired operators
  19. so that I can party all night long
  20. Scenario: Two operators
  21. Given there are two operators
  22. and a single tag
  23. when someone walks in the door
  24. then one should not be two
  25. Scenario: Three operators
  26. Given my birthday
  27. When clock turns seven
  28. then my family sings for me";
  29. Feature feature = Interpreter.ParseSpecificationText(spec);
  30. feature.Name.Should().Be("Pairing of operators");
  31. feature.Description.Should().BeBlank("because no description is given");
  32. feature.Story.Role.Should().Be("user");
  33. feature.Story.Goal.Should().Be("to be able to see paired operators");
  34. feature.Story.Motivation.Should().Be("I can party all night long");
  35. feature.Scenarios.Should().HaveCount(2);
  36. feature.Scenarios[0].Name.Should().Be("Two operators");
  37. feature.Scenarios[0].Given[0].ToString().Should().Be("there are two operators");
  38. feature.Scenarios[0].Given[1].ToString().Should().Be("a single tag");
  39. feature.Scenarios[0].When.Single().ToString().Should().Be("someone walks in the door");
  40. feature.Scenarios[0].Then.Single().ToString().Should().Be("one should not be two");
  41. feature.Scenarios[1].Name.Should().Be("Three operators");
  42. feature.Scenarios[1].Given.Single().ToString().Should().Be("my birthday");
  43. feature.Scenarios[1].When.Single().ToString().Should().Be("clock turns seven");
  44. feature.Scenarios[1].Then.Single().ToString().Should().Be("my family sings for me");
  45. }
  46. [TestMethod]
  47. public void TestScenariosWithExamples()
  48. {
  49. const string spec =
  50. @"
  51. Feature: Calculation
  52. Description: A simple calculator with addition features
  53. Scenario: Addition of two numbers
  54. Given first number if <first>
  55. when I add <second>
  56. then the result should be <result>
  57. Examples:
  58. |first|second|result|
  59. |1|4|five|
  60. |4|2|six|
  61. Scenario: Addition of three numbers
  62. Given first number if <first>
  63. when I add <second>
  64. and <third>
  65. then the result should be <result>
  66. Examples:
  67. |first|second|third|result|
  68. |1.2|4|4|9|
  69. |4|2|10|hej|";
  70. Feature feature = Interpreter.ParseSpecificationText(spec);
  71. feature.Scenarios.Should().HaveCount(2);
  72. Scenario twoNumbersScenario = feature.Scenarios.First();
  73. twoNumbersScenario.Given.Single().GetMethodName().Should().Be("FirstNumberIf_");
  74. twoNumbersScenario.Examples.Should().HaveCount(3);
  75. twoNumbersScenario.Examples["first"].Should().HaveCount(2);
  76. twoNumbersScenario.Examples["first"].Should().HaveSameCount(twoNumbersScenario.Examples["second"]);
  77. twoNumbersScenario.Examples["first"].Should().HaveSameCount(twoNumbersScenario.Examples["result"]);
  78. Assert.AreEqual(1, twoNumbersScenario.Examples["first"][0]);
  79. Assert.AreEqual(4, twoNumbersScenario.Examples["first"][1]);
  80. Assert.AreEqual(4, twoNumbersScenario.Examples["second"][0]);
  81. Assert.AreEqual(2, twoNumbersScenario.Examples["second"][1]);
  82. Assert.AreEqual("five", twoNumbersScenario.Examples["result"][0]);
  83. Assert.AreEqual("six", twoNumbersScenario.Examples["result"][1]);
  84. Scenario threeNumberScenario = feature.Scenarios.Skip(1).First();
  85. threeNumberScenario.Examples.Should().HaveCount(4);
  86. Assert.AreEqual(1.2, threeNumberScenario.Examples["first"][0]);
  87. Assert.AreEqual("hej", threeNumberScenario.Examples["result"][1]);
  88. }
  89. }
  90. }