public void When_asserting_equivalence_of_non_generic_dictionaries_the_lack_of_type_information_should_be_preserved_for_other_equivalency_steps() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Guid userId = Guid.NewGuid(); var dictionary1 = new NonGenericDictionary { { userId, new List <string> { "Admin", "Special" } } }; var dictionary2 = new NonGenericDictionary { { userId, new List <string> { "Admin", "Other" } } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dictionary1.ShouldBeEquivalentTo(dictionary2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow <AssertFailedException>() .WithMessage("*Other*Special*"); }
public void When_asserting_equivalence_of_dictionaries_and_configured_to_respect_runtime_type_it_should_respect_the_runtime_type() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- IDictionary dictionary1 = new NonGenericDictionary { { 2001, new Car() } }; IDictionary dictionary2 = new NonGenericDictionary { { 2001, new Customer() } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dictionary1.ShouldBeEquivalentTo(dictionary2, opts => opts.RespectingRuntimeTypes()); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow <AssertFailedException>("the types have different properties"); }
public void When_asserting_equivalence_of_non_generic_dictionaries_the_lack_of_type_information_should_be_preserved_for_other_equivalency_steps() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Guid userId = Guid.NewGuid(); var dictionary1 = new NonGenericDictionary { { userId, new List <string> { "Admin", "Special" } } }; var dictionary2 = new NonGenericDictionary { { userId, new List <string> { "Admin", "Other" } } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dictionary1.ShouldBeEquivalentTo(dictionary2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow("the declared type of the values is 'object'"); }
public void It_formats_non_generic_dictionaries_that_arent_generic_as_tables_with_the_key_on_the_y_axis() { var writer = new StringWriter(); IDictionary instance = new NonGenericDictionary { { "first", new EntityId("entity one", "123") }, { "second", new EntityId("entity two", "456") } }; var formatter = HtmlFormatter.GetPreferredFormatterFor(instance.GetType()); formatter.Format(instance, writer); writer.ToString() .Should() .BeEquivalentHtmlTo( $@"<table> <thead> <tr><th><i>key</i></th><th>TypeName</th><th>Id</th></tr> </thead> <tbody> <tr><td>first</td><td>entity one</td><td>123</td></tr> <tr><td>second</td><td>entity two</td><td>456</td></tr> </tbody> </table>"); }
public void ShouldDeserialize_Empty_NonGenericDictionary() { var test = new NonGenericDictionary(); var provider = new SerializerProvider(); var bytes = provider.Serialize(test); var deserializedTest = provider.Deserialize <NonGenericDictionary>(bytes); CollectionAssert.AreEqual(test, deserializedTest); }
public void ShouldDeserialize_NonGenericDictionary() { var test = new NonGenericDictionary { { 1, 100 }, { 2, 200 }, { 3, 300 }, { 4, 400 }, }; var provider = new SerializerProvider(); var bytes = provider.Serialize(test); var deserializedTest = provider.Deserialize <NonGenericDictionary>(bytes); CollectionAssert.AreEqual(test, deserializedTest); }
public void When_a_non_generic_dictionary_is_typed_as_object_it_should_respect_the_runtime_type() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- object object1 = new NonGenericDictionary(); object object2 = new NonGenericDictionary(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => object1.ShouldBeEquivalentTo(object2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_a_non_generic_dictionary_is_typed_as_object_and_runtime_typing_has_not_been_specified_the_declared_type_should_be_respected() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- object object1 = new NonGenericDictionary(); object object2 = new NonGenericDictionary(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => object1.ShouldBeEquivalentTo(object2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow <InvalidOperationException>("the type of the subject is object"); }
public void When_a_non_generic_dictionary_is_typed_as_object_and_runtime_typing_is_specified_the_runtime_type_should_be_respected() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- object object1 = new NonGenericDictionary { { "greeting", "hello" } }; object object2 = new NonGenericDictionary { { "greeting", "hello" } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => object1.ShouldBeEquivalentTo(object2, opts => opts.RespectingRuntimeTypes()); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow("the runtime type is a dictionary and the dictionaries are equivalent"); }
public void When_asserting_equivalence_of_dictionaries_it_should_respect_the_declared_type() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- IDictionary dictionary1 = new NonGenericDictionary { { 2001, new Car() } }; IDictionary dictionary2 = new NonGenericDictionary { { 2001, new Customer() } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dictionary1.ShouldBeEquivalentTo(dictionary2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow("the declared type of the items is object"); }
public void When_asserting_equivalence_of_dictionaries_it_should_respect_the_declared_type() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- IDictionary dictionary1 = new NonGenericDictionary { { 2001, new Car() } }; IDictionary dictionary2 = new NonGenericDictionary { { 2001, new Customer() } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dictionary1.ShouldBeEquivalentTo(dictionary2); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow <AssertFailedException>() .WithMessage("*Wheels*not have*VehicleId*not have*"); }