public void DoesNotNotifyWhenMissingProperty()
            {
                var x = new WithSimpleProperties {
                    Value = 1, Time = DateTime.MinValue
                };
                var y = new WithSimpleProperties {
                    Value = 1, Time = DateTime.MinValue
                };
                var propertyChanges = new List <string>();

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

                    x.OnPropertyChanged("Missing");
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff?.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged("Missing");
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff?.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);
                }
            }
            public void HandlesPropertyChangedEmptyAndNull(string prop)
            {
                var source = new WithSimpleProperties {
                    IntValue = 1, StringValue = "2"
                };
                var target = new WithSimpleProperties {
                    IntValue = 3, StringValue = "4"
                };

                foreach (var referenceHandling in Enum.GetValues(typeof(ReferenceHandling)).Cast <ReferenceHandling>())
                {
                    source.IntValue    = 1;
                    source.StringValue = "2";
                    target.IntValue    = 3;
                    target.StringValue = "4";
                    using (Synchronize.PropertyValues(source, target, referenceHandling))
                    {
                        Assert.AreEqual(1, source.IntValue);
                        Assert.AreEqual(1, target.IntValue);
                        Assert.AreEqual("2", source.StringValue);
                        Assert.AreEqual("2", target.StringValue);

                        source.SetFields(5, "6");
                        source.OnPropertyChanged(prop);
                        Assert.AreEqual(5, source.IntValue);
                        Assert.AreEqual(5, target.IntValue);
                        Assert.AreEqual("6", source.StringValue);
                        Assert.AreEqual("6", target.StringValue);
                    }
                }
            }
            public void HandlesMissingProperty(ReferenceHandling referenceHandling)
            {
                var source = new WithSimpleProperties {
                    IntValue = 1, StringValue = "2"
                };
                var target = new WithSimpleProperties {
                    IntValue = 3, StringValue = "4"
                };

                using (Synchronize.PropertyValues(source, target, referenceHandling))
                {
                    Assert.AreEqual(1, source.IntValue);
                    Assert.AreEqual(1, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
                    source.OnPropertyChanged("Missing");
                    source.IntValue = 5;
                    Assert.AreEqual(5, source.IntValue);
                    Assert.AreEqual(5, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
                }

                source.IntValue = 6;
                Assert.AreEqual(6, source.IntValue);
                Assert.AreEqual(5, target.IntValue);
                Assert.AreEqual("2", source.StringValue);
                Assert.AreEqual("2", target.StringValue);
            }
Пример #4
0
            public void HandlesMissingProperty(ReferenceHandling referenceHandling)
            {
                var source = new WithSimpleProperties {
                    IntValue = 1, StringValue = "2"
                };
                var target = new WithSimpleProperties {
                    IntValue = 3, StringValue = "4"
                };

                using (Synchronize.PropertyValues(source, target, referenceHandling))
                {
                    Assert.AreEqual(1, source.IntValue);
                    Assert.AreEqual(1, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
#pragma warning disable INPC009 // Don't raise PropertyChanged for missing property.
                    source.OnPropertyChanged("Missing");
#pragma warning restore INPC009 // Don't raise PropertyChanged for missing property.
                    source.IntValue = 5;
                    Assert.AreEqual(5, source.IntValue);
                    Assert.AreEqual(5, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
                }

                source.IntValue = 6;
                Assert.AreEqual(6, source.IntValue);
                Assert.AreEqual(5, target.IntValue);
                Assert.AreEqual("2", source.StringValue);
                Assert.AreEqual("2", target.StringValue);
            }
            public void DoesNotNotifyWhenNoChangeWhenDirty()
            {
                var x = new WithSimpleProperties {
                    Value = 1, Time = DateTime.MinValue
                };
                var y = new WithSimpleProperties {
                    Value = 1, Time = DateTime.MinValue.AddSeconds(1)
                };
                var propertyChanges = new List <string>();

                using (var tracker = Track.IsDirty(x, y))
                {
                    tracker.PropertyChanged += (_, e) => propertyChanges.Add(e.PropertyName);
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.OnPropertyChanged(nameof(WithSimpleProperties.Value));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.OnPropertyChanged(nameof(WithSimpleProperties.Time));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged(nameof(WithSimpleProperties.Value));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged(nameof(WithSimpleProperties.Time));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);
                }
            }
            public void HandlesPropertyChangedEmptyAndNull(string prop)
            {
                var x = new WithSimpleProperties(1, DateTime.MinValue);
                var y = new WithSimpleProperties(1, DateTime.MinValue);
                var propertyChanges = new List <string>();
                var expectedChanges = new List <string>();

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

                    x.SetFields(1, DateTime.MinValue.AddSeconds(1));
                    x.OnPropertyChanged(prop);
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:01.0000000 y: 0001-01-01T00:00:00.0000000", tracker.Diff.ToString("", " "));
                    expectedChanges.AddRange(new[] { "Diff", "IsDirty" });
                    CollectionAssert.AreEqual(expectedChanges, propertyChanges);
                }
            }
            public void DoesNotNotifyWhenMissingProperty()
            {
                var x = new WithSimpleProperties { Value = 1, Time = DateTime.MinValue };
                var y = new WithSimpleProperties { Value = 1, Time = DateTime.MinValue };
                var propertyChanges = new List<string>();

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

                    x.OnPropertyChanged("Missing");
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff?.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged("Missing");
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff?.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);
                }
            }
            public void HandlesPropertyChangedEmptyAndNull(string prop)
            {
                var x = new WithSimpleProperties(1, DateTime.MinValue);
                var y = new WithSimpleProperties(1, DateTime.MinValue);
                var propertyChanges = new List<string>();
                var expectedChanges = new List<string>();
                using (var tracker = Track.IsDirty(x, y))
                {
                    tracker.PropertyChanged += (_, e) => propertyChanges.Add(e.PropertyName);
                    Assert.AreEqual(false, tracker.IsDirty);
                    Assert.AreEqual(null, tracker.Diff);
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.SetFields(1, DateTime.MinValue.AddSeconds(1));
                    x.OnPropertyChanged(prop);
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:01.0000000 y: 0001-01-01T00:00:00.0000000", tracker.Diff.ToString("", " "));
                    expectedChanges.AddRange(new[] { "Diff", "IsDirty" });
                    CollectionAssert.AreEqual(expectedChanges, propertyChanges);
                }
            }
            public void DoesNotNotifyWhenNoChangeWhenDirty()
            {
                var x = new WithSimpleProperties { Value = 1, Time = DateTime.MinValue };
                var y = new WithSimpleProperties { Value = 1, Time = DateTime.MinValue.AddSeconds(1) };
                var propertyChanges = new List<string>();
                using (var tracker = Track.IsDirty(x, y))
                {
                    tracker.PropertyChanged += (_, e) => propertyChanges.Add(e.PropertyName);
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.OnPropertyChanged(nameof(WithSimpleProperties.Value));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    x.OnPropertyChanged(nameof(WithSimpleProperties.Time));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged(nameof(WithSimpleProperties.Value));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);

                    y.OnPropertyChanged(nameof(WithSimpleProperties.Time));
                    Assert.AreEqual(true, tracker.IsDirty);
                    Assert.AreEqual("WithSimpleProperties Time x: 0001-01-01T00:00:00.0000000 y: 0001-01-01T00:00:01.0000000", tracker.Diff.ToString("", " "));
                    CollectionAssert.IsEmpty(propertyChanges);
                }
            }
            public void HandlesPropertyChangedEmptyAndNull(string prop)
            {
                var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" };
                var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" };
                foreach (var referenceHandling in Enum.GetValues(typeof(ReferenceHandling)).Cast<ReferenceHandling>())
                {
                    source.IntValue = 1;
                    source.StringValue = "2";
                    target.IntValue = 3;
                    target.StringValue = "4";
                    using (Synchronize.PropertyValues(source, target, referenceHandling))
                    {
                        Assert.AreEqual(1, source.IntValue);
                        Assert.AreEqual(1, target.IntValue);
                        Assert.AreEqual("2", source.StringValue);
                        Assert.AreEqual("2", target.StringValue);

                        source.SetFields(5, "6");
                        source.OnPropertyChanged(prop);
                        Assert.AreEqual(5, source.IntValue);
                        Assert.AreEqual(5, target.IntValue);
                        Assert.AreEqual("6", source.StringValue);
                        Assert.AreEqual("6", target.StringValue);
                    }
                }
            }
            public void HandlesMissingProperty(ReferenceHandling referenceHandling)
            {
                var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" };
                var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" };
                using (Synchronize.PropertyValues(source, target, referenceHandling))
                {
                    Assert.AreEqual(1, source.IntValue);
                    Assert.AreEqual(1, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
                    source.OnPropertyChanged("Missing");
                    source.IntValue = 5;
                    Assert.AreEqual(5, source.IntValue);
                    Assert.AreEqual(5, target.IntValue);
                    Assert.AreEqual("2", source.StringValue);
                    Assert.AreEqual("2", target.StringValue);
                }

                source.IntValue = 6;
                Assert.AreEqual(6, source.IntValue);
                Assert.AreEqual(5, target.IntValue);
                Assert.AreEqual("2", source.StringValue);
                Assert.AreEqual("2", target.StringValue);
            }