Exemplo n.º 1
0
        public void Find_missing_destination_property()
        {
            // ARRANGE

            var properties = new SelectValueTypeAndStringPropertiesOfIdenticalName().SelectProperties <Source, Destination>();

            // ACT

            var result = new RejectIncompleteDestination().Validate <Source, Destination>(properties).ToArray();

            // ASSERT

            Assert.Single(result);
            Assert.Equal($"{ typeof(Destination).Name} is missing property { nameof(Source.Property)}", result.Single().Reason);
        }
Exemplo n.º 2
0
        public void Find_different_property_types()
        {
            // ARRANGE

            var properties = new SelectValueTypeAndStringPropertiesOfIdenticalName().SelectProperties <Source, Destination>();

            // ACT

            var result = new RejectDifferentPropertyTypes().Validate <Source, Destination>(properties).ToArray();

            // ASSERT
            // collect vilolations and ignore missing destinations

            Assert.Equal(2, result.Count());
            Assert.Equal($"{typeof(Source).Name}.{nameof(Source.Different)} type (System.Int32) is different from {typeof(Destination).Name}.{nameof(Destination.Different)}: System.String", result.First().Reason);
            Assert.Equal($"{typeof(Source).Name}.{nameof(Source.Assignable)} type (System.Int32) is different from {typeof(Destination).Name}.{nameof(Destination.Assignable)}: System.Int64", result.Last().Reason);
        }
        public void Select_ValueType_and_String_properties_of_identical_name_and_type_only()
        {
            // ARRANGE

            var selector = new SelectValueTypeAndStringPropertiesOfIdenticalName();

            // ACT

            var result = selector.SelectProperties <Source, Destination>().ToArray();

            // ASSERT
            // all properties wrere found except reference type. WronName has no destination

            Assert.Equal(4, result.Count());
            Assert.Equal(nameof(Source.Integer), result.ElementAt(0).src.Name);
            Assert.Equal(nameof(Source.Integer), result.ElementAt(0).dst.Name);
            Assert.Equal(nameof(Source.String), result.ElementAt(1).src.Name);
            Assert.Equal(nameof(Source.String), result.ElementAt(1).dst.Name);
            Assert.Equal(nameof(Source.WrongType), result.ElementAt(2).src.Name);
            Assert.Equal(nameof(Source.WrongType), result.ElementAt(2).dst.Name);
            Assert.Equal(nameof(Source.WrongName), result.ElementAt(3).src.Name);
            Assert.Null(result.ElementAt(3).dst);
        }