Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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_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'");
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 8
0
        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*");
        }