public void Test_Full_Match_Complex_Object() => CheckMatches <Complex_Class>( ResponseSpecification .Field("X") .Field("Y", _ => _.Field("A")) .Field("Z", _ => _.Field("B")) );
public void Test_Format_Array() { var array = new[] { new { A = "a", B = "b" }, new { A = "aa", B = "bb" } }; var actual = formatter.Format(array, ResponseSpecification.Field("A")); var expected = new[] { new { A = "a" }, new { A = "aa" } }; AssertExpectedContract(actual, expected); }
public void Test_Duplicate_Field_Names_When_Explicit_Specification_Building() { Assert.Throws <InvalidOperationException>( () => ResponseSpecification .Field("A") .Field("A") .Create() ); }
public void Test_Not_Matches_Complex_Object() => CheckNotMatches <Complex_Class>( ResponseSpecification .Field("A") .Field("Y", _ => _.Field("C").Field("B")) .Field("Z", _ => _.Field("A").Field("D")), "root.A", "root.Y.[dictionary].C", "root.Z.[list].D" );
public void Test_Format_Nested() { var array = new { A = "a", B = "b", C = new { D = "d", E = "e" } }; var actual = formatter.Format(array, ResponseSpecification .Field("A") .Field("C", _ => _.Field("E")) ); var expected = new { A = "a", C = new { E = "e" } }; AssertExpectedContract(actual, expected); }
public void Test_Contract_With_Custom_Names() { var actual = ResponseSpecification.Create <CustomNamesType>(); var expected = ResponseSpecification .Field("A") .Field("B") .Field("C") .Field("custom1") .Field("E") .Field("F") .Field("custom2") .Field("custom3") .Field("custom4") .Create(); actual.ShouldBeEquivalentTo(expected); }
public void Test_Create_For_Complex_Type() { var actual = ResponseSpecification.Create <ComplexType>(); var expected = ResponseSpecification .Field("A") .Field("B") .Field("C", _ => _.Field("X")) .Field("D", _ => _.Field("X")) .Field("E", _ => _.Field("X")) .Field("F") .Field("G") .Field("H") .Field("I") .Field("J") .Field("K", _ => _ .Field("W") .Field("Z", __ => __.Field("X")) ) .Create(); actual.ShouldBeEquivalentTo(expected); }
public void Test_Format_Dictionary() { var dictionary = new Dictionary <string, ABClass> { { "item1", new ABClass { A = "a", B = "b" } }, { "item2", new ABClass { A = "aa", B = "bb" } } }; var actual = formatter.Format(dictionary, ResponseSpecification.Field("A")); var expected = new Dictionary <string, AClass> { { "item1", new AClass { A = "a" } }, { "item2", new AClass { A = "aa" } } }; AssertExpectedContract(actual, expected); }
public void Test_Single_Field_And_Array() => CheckNotMatches <int[]>(ResponseSpecification.Field("A"), "root.[list].A");
public void Test_Single_Field_Not_Matches_Complex_Object() => CheckNotMatches <Complex_Class>(ResponseSpecification.Field("A"), "root.A");
public void Test_Array_Of_Array_Of_Nested_Types() { var actual = ResponseSpecification.Create <NestedType[][]>(); actual.ShouldBeEquivalentTo(ResponseSpecification.Field("X").Create()); }
public void Test_Single_Field_Matches_Array_Of_Object() => CheckMatches <Simple_Class[]>(ResponseSpecification.Field("A"));
public void Test_Single_Field_Matches_Dictionary_Of_Object() => CheckMatches <Dictionary <string, Simple_Class> >(ResponseSpecification.Field("A"));
public void Test_Single_Field_And_Not_Matched_Object() => CheckNotMatches <Simple_Class>(ResponseSpecification.Field("C"), "root.C");
public void Test_Dictionary_Of_Dictionary_Of_Nested_Types() { var actual = ResponseSpecification.Create <Dictionary <Guid, Dictionary <string, NestedType> > >(); actual.ShouldBeEquivalentTo(ResponseSpecification.Field("X").Create()); }
public void Test_Create_For_Simple_Type() { var actual = ResponseSpecification.Create <SimpleType>(); actual.ShouldBeEquivalentTo(ResponseSpecification.Field("A").Create()); }
public void Test_Contract_With_Ignored_Properties() { var actual = ResponseSpecification.Create <IgnoredPropertiesClass>(); actual.ShouldBeEquivalentTo(ResponseSpecification.Field("A").Create()); }
public void Test_Single_Field_And_Int() => CheckNotMatches <int>(ResponseSpecification.Field("A"), "root.A");
public void Test_Format_Complex_Object() { var nested1 = new NestedTestContract { X = "xxx", Y = 666, Z = new DateTime(2099, 01, 01) }; var nested2 = new NestedTestContract { X = "yyy", Y = 777, Z = new DateTime(9999, 01, 01) }; var testContract = new TestContract { A = "aaa", B = 42, C = new DateTime(2016, 02, 10), D = 36.6m, Nested = nested1, Array = new[] { nested1, nested2 }, List = new List <NestedTestContract> { nested1, nested2 }, Dictionary = new Dictionary <string, NestedTestContract> { { "item1", nested1 }, { "item2", nested2 } } }; var nestedFields = ResponseSpecification.Field("X").Field("Z"); var responseSpecification = ResponseSpecification .Field("A") .Field("D") .Field("C") .Field("Array", _ => _ .Field("X") .Field("Z") ) .Field("List", _ => _ .Field("X") .Field("Z") ) .Field("Nested", _ => nestedFields) .Field("Dictionary", _ => nestedFields); var actual = formatter.Format(testContract, responseSpecification); var nestedExpected1 = new { X = "xxx", Z = new DateTime(2099, 01, 01) }; var nestedExpected2 = new { X = "yyy", Z = new DateTime(9999, 01, 01) }; var expected = new { A = "aaa", D = 36.6, C = new DateTime(2016, 02, 10), Array = new[] { nestedExpected1, nestedExpected2, }, List = new[] { nestedExpected1, nestedExpected2, }, Nested = nestedExpected1, Dictionary = new { item1 = nestedExpected1, item2 = nestedExpected2 } }; AssertExpectedContract(actual, expected); }
public void Test_Single_Field_And_Dictionary() => CheckNotMatches <Dictionary <int, int> >(ResponseSpecification.Field("A"), "root.[dictionary].A");
public void Test_Single_Field_Matches() => CheckMatches <Simple_Class>(ResponseSpecification.Field("A"));
private static IEnumerable <TestCaseData> GenerateTestData() { yield return(new TestCaseData( ResponseSpecification.Empty, string.Empty ).SetName("Empty")); yield return(new TestCaseData( ResponseSpecification.Field("name").Create(), "name" ).SetName("Single field")); yield return(new TestCaseData( ResponseSpecification .Field("name1") .Field("name2") .Create(), "name1;name2" ).SetName("Two fields")); yield return(new TestCaseData( ResponseSpecification .Field("name1", _ => _.Field("a").Field("b")) .Field("name2", _ => _.Field("d").Field("a")) .Create(), "name1:(a;b);name2:(d;a)" ).SetName("Two fields with nested fields")); yield return(new TestCaseData( ResponseSpecification .Field( "root", root => root .Field( "l", l => l .Field( "ll", ll => ll .Field("lll") .Field("llr") ) .Field( "lr", lr => lr .Field("lrl") .Field("lrr") ) ) .Field( "r", r => r .Field( "rl", ll => ll .Field("rll") .Field("rlr") ) .Field( "rr", lr => lr .Field("rrl") .Field("rrr") ) ) ).Create(), "root:(l:(ll:(lll;llr);lr:(lrl;lrr));r:(rl:(rll;rlr);rr:(rrl;rrr)))" ).SetName("Binary tree")); }