Esempio n. 1
0
        public void When_Nothing_Is_Changed_ChangedProperties_Should_BeEmpty()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEmpty();
        }
Esempio n. 2
0
        public void When_Nothing_Is_Changed_Should_Be_Unchanged()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.CastToIChangeTrackable().IsChanged.Should().BeFalse();
            trackable.CastToIChangeTrackable().ChangeTrackingStatus.Should().Be(ChangeStatus.Unchanged);
        }
Esempio n. 3
0
        public void When_Changed_ChangedProperties_Should_ReturnChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.CustomerNumber = "Change";

            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEquivalentTo(nameof(Order.CustomerNumber));
        }
        public void When_Changed_CollectionProperty_ChangedProperties_Should_ReturnChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.OrderDetails.RemoveAt(0);

            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEquivalentTo(nameof(Order.OrderDetails));
        }
        public void When_Changed_ComplexProperty_ChangedProperties_Should_ReturnChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.Address.City = "Hanoi";

            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEquivalentTo(nameof(Order.Address));
        }
Esempio n. 6
0
        public void AsTrackable_Should_Take_MakeComplexPropertiesTrackable_From_Default()
        {
            ChangeTrackingFactory.Default.MakeComplexPropertiesTrackable = false;
            Order order = Helper.GetOrder();

            Order trackable = order.AsTrackable();

            trackable.Should().BeAssignableTo <IChangeTrackable <Order> >();
            trackable.Address.Should().NotBeAssignableTo <IChangeTrackable <Address> >();
            ChangeTrackingFactory.Default.MakeComplexPropertiesTrackable = true;
        }
Esempio n. 7
0
        public void AsTrackable_Should_Take_MakeCollectionPropertiesTrackable_From_Default()
        {
            ChangeTrackingFactory.Default.MakeCollectionPropertiesTrackable = false;
            Order order = Helper.GetOrder();

            Order trackable = order.AsTrackable();

            trackable.Should().BeAssignableTo <IChangeTrackable <Order> >();
            trackable.OrderDetails.Should().NotBeAssignableTo <IChangeTrackableCollection <OrderDetail> >();
            ChangeTrackingFactory.Default.MakeCollectionPropertiesTrackable = true;
        }
        public void When_Changed_ComplexProperty_PropertyChanged_Should_Raise_For_ChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            IMonitor <System.ComponentModel.INotifyPropertyChanged> monitor = ((System.ComponentModel.INotifyPropertyChanged)trackable).Monitor();

            trackable.Address.City = "Karachi";

            monitor.Should().RaisePropertyChangeFor(o => ((IChangeTrackable)o).ChangedProperties);
            monitor.OccurredEvents.Count(i => i.Parameters.OfType <System.ComponentModel.PropertyChangedEventArgs>().SingleOrDefault()?.PropertyName == nameof(IChangeTrackable.ChangedProperties)).Should().Be(1);
        }
Esempio n. 9
0
        public void When_Changed_Back_Should_Be_Unchanged()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            trackable.Id++;
            trackable.Id--;
            trackable.LinkedOrder.Id++;
            trackable.LinkedOrder.Id--;

            trackable.CastToIChangeTrackable().IsChanged.Should().BeFalse();
            trackable.CastToIChangeTrackable().ChangeTrackingStatus.Should().Be(ChangeStatus.Unchanged);
        }
        public void When_Changed_ComplexProperty_PropertyChanged_Should_Raise_Twice_If_Reverting_Back_To_Original_For_ChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            IMonitor <System.ComponentModel.INotifyPropertyChanged> monitor = ((System.ComponentModel.INotifyPropertyChanged)trackable).Monitor();

            trackable.Address.City = "Hiroshima";
            trackable.Address.CastToIChangeTrackable().RejectChanges();

            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEmpty();
            monitor.Should().RaisePropertyChangeFor(o => ((IChangeTrackable)o).ChangedProperties);
            monitor.OccurredEvents.Count(i => i.Parameters.OfType <System.ComponentModel.PropertyChangedEventArgs>().SingleOrDefault()?.PropertyName == nameof(IChangeTrackable.ChangedProperties)).Should().Be(2);
        }
        public void When_Changed_CollectionProperty_PropertyChanged_Should_Raise_Twice_If_AcceptChanges_For_ChangedProperties()
        {
            Order order     = Helper.GetOrder();
            var   trackable = order.AsTrackable();

            IMonitor <System.ComponentModel.INotifyPropertyChanged> monitor = ((System.ComponentModel.INotifyPropertyChanged)trackable).Monitor();

            trackable.OrderDetails.Clear();

            trackable.CastToIChangeTrackable().ChangedProperties.Count().Should().Be(1);
            trackable.CastToIChangeTrackable().AcceptChanges();
            trackable.CastToIChangeTrackable().ChangedProperties.Should().BeEmpty();
            monitor.Should().RaisePropertyChangeFor(o => ((IChangeTrackable)o).ChangedProperties);
            monitor.OccurredEvents.Count(i => i.Parameters.OfType <System.ComponentModel.PropertyChangedEventArgs>().SingleOrDefault()?.PropertyName == nameof(IChangeTrackable.ChangedProperties)).Should().Be(2);
        }
Esempio n. 12
0
        public async Task Concurrent_Access_To_CollectionProperty_Should_Not_Throw()
        {
            Order order     = Helper.GetOrder();
            Order trackable = order.AsTrackable();

            int count = 2;

            IList <OrderDetail>[] orderDetails = new IList <OrderDetail> [count];
            Task[] tasks = new Task[count];

            for (int i = 0; i < count; i++)
            {
                int index = i;
                tasks[index] = Task.Run(() =>
                {
                    orderDetails[index] = trackable.OrderDetails;
                });
            }
            await Task.WhenAll(tasks);

            IList <OrderDetail> firstOrderDetails = orderDetails[0];

            orderDetails.All(od => od != null && ReferenceEquals(firstOrderDetails, od)).Should().BeTrue();
        }
Esempio n. 13
0
        public async Task Concurrent_Access_To_ComplexProperty_Should_Not_Throw()
        {
            Order order     = Helper.GetOrder();
            Order trackable = order.AsTrackable();

            int count = 2;

            Address[] addresses = new Address[count];
            Task[]    tasks     = new Task[count];

            for (int i = 0; i < count; i++)
            {
                int index = i;
                tasks[index] = Task.Run(() =>
                {
                    addresses[index] = trackable.Address;
                });
            }
            await Task.WhenAll(tasks);

            Address firstAddress = addresses[0];

            addresses.All(a => a != null && ReferenceEquals(firstAddress, a)).Should().BeTrue();
        }