public void Reacts_to_principal_key_change_in_sidecar()
        {
            var model = BuildModel();
            var configuration = TestHelpers.CreateContextConfiguration(model);
            var stateManager = configuration.Services.StateManager;

            var entityType = model.GetEntityType(typeof(Category));
            var keyProperty = entityType.GetProperty("PrincipalId");

            var category = new Category { Id = -1, PrincipalId = 77 };
            var principalEntry = stateManager.StartTracking(stateManager.GetOrCreateEntry(category));
            principalEntry.RelationshipsSnapshot[keyProperty] = 77;
            principalEntry.EntityState = EntityState.Added;

            var notifierMock = new Mock<StateEntryNotifier>();
            var changeDetector = new ChangeDetector(configuration, notifierMock.Object);

            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey<int>(entityType, -1)));

            principalEntry.AddSidecar(new StoreGeneratedValuesFactory().Create(principalEntry))[keyProperty] = 78;
            changeDetector.SidecarPropertyChanged(principalEntry, keyProperty);

            notifierMock.Verify(m => m.PrincipalKeyPropertyChanged(principalEntry, keyProperty, 77, 78));

            Assert.Equal(78, principalEntry.RelationshipsSnapshot[keyProperty]);
            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey<int>(entityType, -1)));
        }
Beispiel #2
0
        public void Reacts_to_principal_key_change_in_sidecar()
        {
            var model         = BuildModel();
            var configuration = TestHelpers.CreateContextConfiguration(model);
            var stateManager  = configuration.Services.StateManager;

            var entityType  = model.GetEntityType(typeof(Category));
            var keyProperty = entityType.GetProperty("PrincipalId");

            var category = new Category {
                Id = -1, PrincipalId = 77
            };
            var principalEntry = stateManager.StartTracking(stateManager.GetOrCreateEntry(category));

            principalEntry.RelationshipsSnapshot[keyProperty] = 77;
            principalEntry.EntityState = EntityState.Added;

            var notifierMock   = new Mock <StateEntryNotifier>();
            var changeDetector = new ChangeDetector(configuration, notifierMock.Object);

            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey <int>(entityType, -1)));

            principalEntry.AddSidecar(new StoreGeneratedValuesFactory().Create(principalEntry))[keyProperty] = 78;
            changeDetector.SidecarPropertyChanged(principalEntry, keyProperty);

            notifierMock.Verify(m => m.PrincipalKeyPropertyChanged(principalEntry, keyProperty, 77, 78));

            Assert.Equal(78, principalEntry.RelationshipsSnapshot[keyProperty]);
            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey <int>(entityType, -1)));
        }
Beispiel #3
0
        public void Ignores_non_principal_key_change_in_sidecar()
        {
            var model         = BuildModel();
            var configuration = TestHelpers.CreateContextConfiguration(model);
            var stateManager  = configuration.Services.StateManager;

            var entityType = model.GetEntityType(typeof(Category));
            var property   = entityType.GetProperty("Name");

            var category = new Category {
                Id = -1, Name = "Blue"
            };
            var principalEntry = stateManager.StartTracking(stateManager.GetOrCreateEntry(category));

            principalEntry.RelationshipsSnapshot[property] = "Blue";
            principalEntry.EntityState = EntityState.Added;

            var notifierMock   = new Mock <StateEntryNotifier>();
            var changeDetector = new ChangeDetector(configuration, notifierMock.Object);

            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey <int>(entityType, -1)));

            principalEntry.AddSidecar(new StoreGeneratedValuesFactory().Create(principalEntry))[property] = "Red";
            changeDetector.SidecarPropertyChanged(principalEntry, property);

            notifierMock.Verify(m => m.PrincipalKeyPropertyChanged(
                                    It.IsAny <StateEntry>(), It.IsAny <IProperty>(), It.IsAny <object>(), It.IsAny <object>()), Times.Never);

            Assert.Equal("Blue", principalEntry.RelationshipsSnapshot[property]);
            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey <int>(entityType, -1)));
        }
        public void Ignores_non_principal_key_change_in_sidecar()
        {
            var model = BuildModel();
            var configuration = TestHelpers.CreateContextConfiguration(model);
            var stateManager = configuration.Services.StateManager;

            var entityType = model.GetEntityType(typeof(Category));
            var property = entityType.GetProperty("Name");

            var category = new Category { Id = -1, Name = "Blue" };
            var principalEntry = stateManager.StartTracking(stateManager.GetOrCreateEntry(category));
            principalEntry.RelationshipsSnapshot[property] = "Blue";
            principalEntry.EntityState = EntityState.Added;

            var notifierMock = new Mock<StateEntryNotifier>();
            var changeDetector = new ChangeDetector(configuration, notifierMock.Object);

            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey<int>(entityType, -1)));

            principalEntry.AddSidecar(new StoreGeneratedValuesFactory().Create(principalEntry))[property] = "Red";
            changeDetector.SidecarPropertyChanged(principalEntry, property);

            notifierMock.Verify(m => m.PrincipalKeyPropertyChanged(
                It.IsAny<StateEntry>(), It.IsAny<IProperty>(), It.IsAny<object>(), It.IsAny<object>()), Times.Never);

            Assert.Equal("Blue", principalEntry.RelationshipsSnapshot[property]);
            Assert.Same(principalEntry, stateManager.TryGetEntry(new SimpleEntityKey<int>(entityType, -1)));
        }