PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Examples/Example.WithBehavior/DateTimeParsingSpec.cs

https://github.com/machine/machine.specifications
C# | 46 lines | 31 code | 12 blank | 3 comment | 0 complexity | bcc775dbcbfe278f443ea0794a195601 MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0
  1. using System;
  2. using FluentAssertions;
  3. using Machine.Specifications;
  4. // This is a rather contrived example, but I hope it shows what you can do with it.
  5. // I like the concept of MbUnit's RowTest and TypeFixture very much, especially when it comes to
  6. // testing the same logic with different input patterns/files, etc.
  7. namespace Example.WithBehavior
  8. {
  9. [Subject("Date time parsing")]
  10. public class when_a_date_is_parsed_with_the_regular_expression_parser : DateTimeParsingSpecs
  11. {
  12. Establish context = () => { Parser = new RegexParser(); };
  13. Because of = () => { ParsedDate = Parser.Parse("2009/01/21"); };
  14. Behaves_like<DateTimeParsingBehavior> a_date_time_parser;
  15. }
  16. [Subject("Date time parsing")]
  17. public class when_a_date_is_parsed_by_the_infrastructure : DateTimeParsingSpecs
  18. {
  19. Establish context = () => { Parser = new InfrastructureParser(); };
  20. Because of = () => { ParsedDate = Parser.Parse("2009/01/21"); };
  21. Behaves_like<DateTimeParsingBehavior> a_date_time_parser;
  22. }
  23. public abstract class DateTimeParsingSpecs
  24. {
  25. protected static DateTime ParsedDate;
  26. protected static IParser Parser;
  27. }
  28. [Behaviors]
  29. public class DateTimeParsingBehavior
  30. {
  31. protected static DateTime ParsedDate;
  32. It should_parse_the_expected_date = () => ParsedDate.Should().Be(new DateTime(2009, 1, 21));
  33. }
  34. }