示例#1
0
        public void IgnoresIndexer()
        {
            var type            = typeof(SettingsTypes.WithIndexerType);
            var nameProperty    = type.GetProperty(nameof(SettingsTypes.WithIndexerType.Name));
            var indexerProperty = type.GetProperties().Single(x => x.GetIndexParameters().Length > 0);
            var settings        = PropertiesSettings.Build()
                                  .IgnoreIndexersFor <SettingsTypes.WithIndexerType>()
                                  .CreateSettings();

            Assert.AreEqual(false, settings.IsIgnoringProperty(nameProperty));
            Assert.AreEqual(true, settings.IsIgnoringProperty(indexerProperty));
        }
示例#2
0
        public void IgnoresPropertyBuilder()
        {
            var type          = typeof(SettingsTypes.ComplexType);
            var nameProperty  = type.GetProperty(nameof(SettingsTypes.ComplexType.Name));
            var valueProperty = type.GetProperty(nameof(SettingsTypes.ComplexType.Value));
            var settings      = PropertiesSettings.Build()
                                .IgnoreProperty(nameProperty)
                                .CreateSettings();

            Assert.AreEqual(true, settings.IsIgnoringProperty(nameProperty));
            Assert.AreEqual(false, settings.IsIgnoringProperty(valueProperty));
        }
示例#3
0
        public void IgnoresBaseTypeBuilder()
        {
            var settings = PropertiesSettings.Build()
                           .IgnoreType <SettingsTypes.ComplexType>()
                           .CreateSettings();

            Assert.AreEqual(true, settings.IsIgnoringProperty(typeof(SettingsTypes.ComplexType).GetProperty(nameof(SettingsTypes.ComplexType.Name))));
            Assert.AreEqual(true, settings.IsIgnoringProperty(typeof(SettingsTypes.ComplexType).GetProperty(nameof(SettingsTypes.ComplexType.Value))));
            Assert.AreEqual(true, settings.IsIgnoringProperty(typeof(SettingsTypes.Derived).GetProperty(nameof(SettingsTypes.Derived.Name))));
            Assert.AreEqual(true, settings.IsIgnoringProperty(typeof(SettingsTypes.Derived).GetProperty(nameof(SettingsTypes.Derived.Value))));
            Assert.AreEqual(false, settings.IsIgnoringProperty(typeof(SettingsTypes.Derived).GetProperty(nameof(SettingsTypes.Derived.DoubleValue))));
        }
示例#4
0
        public override void CopyMethod <T>(T source, T target, ReferenceHandling referenceHandling = ReferenceHandling.Structural, string excluded = null)
        {
            var builder = PropertiesSettings.Build();

            if (excluded != null)
            {
                builder.IgnoreProperty <T>(excluded);
            }

            var settings = builder.CreateSettings(referenceHandling);

            Copy.PropertyValues(source, target, settings);
        }
示例#5
0
        public void IgnoresBaseClassPropertyLambda()
        {
            var settings = PropertiesSettings.Build()
                           .IgnoreProperty <SettingsTypes.ComplexType>(x => x.Name)
                           .CreateSettings();
            var nameProperty = typeof(SettingsTypes.ComplexType).GetProperty(nameof(SettingsTypes.ComplexType.Name));

            Assert.AreEqual(true, settings.IsIgnoringProperty(nameProperty));

            nameProperty = typeof(SettingsTypes.Derived).GetProperty(nameof(SettingsTypes.Derived.Name));
            Assert.AreEqual(true, settings.IsIgnoringProperty(nameProperty));
            Assert.AreEqual(false, settings.IsIgnoringProperty(typeof(SettingsTypes.Derived).GetProperty(nameof(SettingsTypes.Derived.Value))));
        }
示例#6
0
        public override Diff DiffMethod <T>(T x, T y, ReferenceHandling referenceHandling = ReferenceHandling.Structural, string excludedMembers = null, Type excludedType = null)
        {
            var builder = PropertiesSettings.Build();

            if (excludedMembers != null)
            {
                builder.IgnoreProperty <T>(excludedMembers);
            }

            if (excludedType != null)
            {
                builder.IgnoreType(excludedType);
            }

            var settings = builder.CreateSettings(referenceHandling);

            return(DiffBy.PropertyValues(x, y, settings));
        }
示例#7
0
        public override void VerifyMethod <T>(ReferenceHandling referenceHandling = ReferenceHandling.Structural, string excludedMembers = null, Type excludedType = null)
        {
            var builder = PropertiesSettings.Build();

            if (excludedMembers != null)
            {
                builder.IgnoreProperty <T>(excludedMembers);
            }

            if (excludedType != null)
            {
                builder.IgnoreType(excludedType);
            }

            var settings = builder.CreateSettings(referenceHandling);

            DiffBy.VerifyCanDiffByPropertyValues <T>(settings);
        }
            public void WithExplicitImmutableAndComparer()
            {
                var x = new With <IntCollection> {
                    Value = new IntCollection(1)
                };
                var y = new With <IntCollection> {
                    Value = new IntCollection(1)
                };
                var propertyChanges = new List <string>();
                var expectedChanges = new List <string>();
                var settings        = PropertiesSettings.Build()
                                      .AddImmutableType <IntCollection>()
                                      .AddComparer(IntCollection.Comparer)
                                      .CreateSettings();

                using (var tracker = Track.IsDirty(x, y, settings))
                {
                    tracker.PropertyChanged += (_, e) => propertyChanges.Add(e.PropertyName);
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff);
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.Value = new IntCollection(2);
                    Assert.AreEqual(true, tracker.IsDirty);
                    var expected = "With<IntCollection> Value x: Gu.State.Tests.DirtyTrackerTypes+IntCollection y: Gu.State.Tests.DirtyTrackerTypes+IntCollection";
                    var actual   = tracker.Diff.ToString("", " ");
                    Assert.AreEqual(expected, actual);
                    expectedChanges.AddRange(new[] { "Diff", "IsDirty" });
                    CollectionAssert.AreEqual(expectedChanges, propertyChanges);

                    y.Value = new IntCollection(2);
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff?.ToString("", " "));
                    expectedChanges.AddRange(new[] { "Diff", "IsDirty" });
                    CollectionAssert.AreEqual(expectedChanges, propertyChanges);
                }
            }
示例#9
0
            public void Excludes()
            {
                var source = new WithComplexProperty("a", 1)
                {
                    ComplexType = new ComplexType("b", 2)
                };
                var target = new WithComplexProperty("c", 3)
                {
                    ComplexType = new ComplexType("d", 4)
                };
                var settings = PropertiesSettings.Build()
                               .IgnoreProperty <WithComplexProperty>(nameof(WithComplexProperty.Name))
                               .CreateSettings(ReferenceHandling.Structural);

                using (Synchronize.PropertyValues(source, target, settings))
                {
                    Assert.AreEqual("a", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(1, source.Value);
                    Assert.AreEqual(1, target.Value);

                    Assert.AreNotSame(source.ComplexType, target.ComplexType);
                    Assert.AreEqual("b", source.ComplexType.Name);
                    Assert.AreEqual("b", target.ComplexType.Name);
                    Assert.AreEqual(2, source.ComplexType.Value);
                    Assert.AreEqual(2, target.ComplexType.Value);

                    source.Value = 5;
                    Assert.AreEqual("a", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreEqual("b", source.ComplexType.Name);
                    Assert.AreEqual("b", target.ComplexType.Name);
                    Assert.AreEqual(2, source.ComplexType.Value);
                    Assert.AreEqual(2, target.ComplexType.Value);

                    source.Name = "ignored";
                    Assert.AreEqual("ignored", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreEqual("b", source.ComplexType.Name);
                    Assert.AreEqual("b", target.ComplexType.Name);
                    Assert.AreEqual(2, source.ComplexType.Value);
                    Assert.AreEqual(2, target.ComplexType.Value);

                    source.ComplexType.Value = 6;
                    Assert.AreEqual("ignored", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreNotSame(source.ComplexType, target.ComplexType);
                    Assert.AreEqual("b", source.ComplexType.Name);
                    Assert.AreEqual("b", target.ComplexType.Name);
                    Assert.AreEqual(6, source.ComplexType.Value);
                    Assert.AreEqual(6, target.ComplexType.Value);

                    source.ComplexType = null;
                    Assert.AreEqual("ignored", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreEqual(null, source.ComplexType);
                    Assert.AreEqual(null, target.ComplexType);

                    source.ComplexType = new ComplexType("f", 7);
                    Assert.AreEqual("ignored", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreEqual("f", source.ComplexType.Name);
                    Assert.AreEqual("f", target.ComplexType.Name);
                    Assert.AreEqual(7, source.ComplexType.Value);
                    Assert.AreEqual(7, target.ComplexType.Value);

                    source.ComplexType.Value = 8;
                    Assert.AreEqual("ignored", source.Name);
                    Assert.AreEqual("c", target.Name);
                    Assert.AreEqual(5, source.Value);
                    Assert.AreEqual(5, target.Value);

                    Assert.AreNotSame(source.ComplexType, target.ComplexType);
                    Assert.AreEqual("f", source.ComplexType.Name);
                    Assert.AreEqual("f", target.ComplexType.Name);
                    Assert.AreEqual(8, source.ComplexType.Value);
                    Assert.AreEqual(8, target.ComplexType.Value);
                }

                source.Value = 6;
                Assert.AreEqual("ignored", source.Name);
                Assert.AreEqual("c", target.Name);
                Assert.AreEqual(6, source.Value);
                Assert.AreEqual(5, target.Value);

                Assert.AreEqual("f", source.ComplexType.Name);
                Assert.AreEqual("f", target.ComplexType.Name);
                Assert.AreEqual(8, source.ComplexType.Value);
                Assert.AreEqual(8, target.ComplexType.Value);
            }