public void Subscriptions_to_INotifyPropertyChanging_and_INotifyPropertyChanged_ignore_unmapped_properties()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity));
            entityType.AddProperty("Name", typeof(string));

            var entity = new FullNotificationEntity();

            var entryMock = new Mock<StateEntry>();
            entryMock.Setup(m => m.EntityType).Returns(entityType);
            entryMock.Setup(m => m.Entity).Returns(entity);

            var detectorMock = new Mock<ChangeDetector>();
            new StateEntrySubscriber(detectorMock.Object).SnapshotAndSubscribe(entryMock.Object);

            entity.NotMapped = "Formby";

            detectorMock.Verify(m => m.PropertyChanging(It.IsAny<StateEntry>(), It.IsAny<IProperty>()), Times.Never);
            detectorMock.Verify(m => m.PropertyChanged(It.IsAny<StateEntry>(), It.IsAny<IProperty>()), Times.Never);
        }
        public void Entry_subscribes_to_INotifyPropertyChanging_and_INotifyPropertyChanged()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity));
            var property = entityType.AddProperty("Name", typeof(string));

            var entity = new FullNotificationEntity();

            var entryMock = new Mock<StateEntry>();
            entryMock.Setup(m => m.EntityType).Returns(entityType);
            entryMock.Setup(m => m.Entity).Returns(entity);

            var detectorMock = new Mock<ChangeDetector>();
            new StateEntrySubscriber(detectorMock.Object).SnapshotAndSubscribe(entryMock.Object);

            entity.Name = "George";

            detectorMock.Verify(m => m.PropertyChanging(entryMock.Object, property));
            detectorMock.Verify(m => m.PropertyChanged(entryMock.Object, property));
        }
예제 #3
0
    public void Entry_subscribes_to_INotifyPropertyChanging_and_INotifyPropertyChanged_for_properties()
    {
        var contextServices = InMemoryTestHelpers.Instance.CreateContextServices(
            new ServiceCollection().AddScoped <IChangeDetector, TestPropertyListener>(),
            BuildModel());

        var testListener = contextServices.GetRequiredService <IEnumerable <IChangeDetector> >().OfType <TestPropertyListener>().Single();

        var entity = new FullNotificationEntity();
        var entry  = contextServices.GetRequiredService <IStateManager>().GetOrCreateEntry(entity);

        entry.SetEntityState(EntityState.Unchanged);

        Assert.Empty(testListener.Changing);
        Assert.Empty(testListener.Changed);

        entity.Name = "Palmer";

        var property = entry.EntityType.FindProperty("Name");

        Assert.Same(property, testListener.Changing.Single().Item2);
        Assert.Same(property, testListener.Changed.Single().Item2);
    }
예제 #4
0
        public void Entry_subscribes_to_INotifyPropertyChanging_and_INotifyPropertyChanged_for_navigations()
        {
            var contextServices = TestHelpers.Instance.CreateContextServices(
                new ServiceCollection().AddScoped <IPropertyListener, TestPropertyListener>(),
                BuildModel());

            var testListener = contextServices.GetRequiredService <IEnumerable <IPropertyListener> >().OfType <TestPropertyListener>().Single();

            var entity = new FullNotificationEntity();
            var entry  = contextServices.GetRequiredService <IStateManager>().GetOrCreateEntry(entity);

            entry.SetEntityState(EntityState.Unchanged);

            Assert.Null(testListener.Changing);
            Assert.Null(testListener.Changed);

            entity.RelatedCollection = new List <ChangedOnlyNotificationEntity>();

            var property = entry.EntityType.FindNavigation("RelatedCollection");

            Assert.Same(property, testListener.Changing);
            Assert.Same(property, testListener.Changed);
        }