public TestCommandBatchPreparer( ModificationCommandBatchFactory modificationCommandBatchFactory, ParameterNameGeneratorFactory parameterNameGeneratorFactory, ModificationCommandComparer modificationCommandComparer) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, modificationCommandComparer) { }
public SqlServerCommandBatchPreparer( [NotNull] SqlServerModificationCommandBatchFactory modificationCommandBatchFactory, [NotNull] ParameterNameGeneratorFactory parameterNameGeneratorFactory, [NotNull] ModificationCommandComparer modificationCommandComparer) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, modificationCommandComparer) { }
public SQLiteCommandBatchPreparer( [NotNull] SQLiteModificationCommandBatchFactory modificationCommandBatchFactory, [NotNull] ParameterNameGeneratorFactory parameterNameGeneratorFactory, [NotNull] GraphFactory graphFactory, [NotNull] ModificationCommandComparer modificationCommandComparer) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, graphFactory, modificationCommandComparer) { }
public TestCommandBatchPreparer( ModificationCommandBatchFactory modificationCommandBatchFactory, ParameterNameGeneratorFactory parameterNameGeneratorFactory, ModificationCommandComparer modificationCommandComparer, IBoxedValueReaderSource boxedValueReaderSource) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, modificationCommandComparer, boxedValueReaderSource) { }
public SqlServerCommandBatchPreparer( [NotNull] SqlServerModificationCommandBatchFactory modificationCommandBatchFactory, [NotNull] ParameterNameGeneratorFactory parameterNameGeneratorFactory, [NotNull] ModificationCommandComparer modificationCommandComparer, [NotNull] IBoxedValueReaderSource boxedValueReaderSource) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, modificationCommandComparer, boxedValueReaderSource) { }
private void Compare_returns_0_only_for_entries_that_have_same_key_values_generic <T>(T value1, T value2) { var modelBuilder = RelationalTestHelpers.Instance.CreateConventionBuilder(); var model = modelBuilder.Model; var entityType = model.AddEntityType(typeof(object)); var keyProperty = entityType.AddProperty("Id", typeof(T)); keyProperty.IsNullable = false; entityType.SetPrimaryKey(keyProperty); var optionsBuilder = new DbContextOptionsBuilder() .UseInternalServiceProvider(InMemoryFixture.DefaultServiceProvider) .UseModel(modelBuilder.FinalizeModel()) .UseInMemoryDatabase(Guid.NewGuid().ToString()); var stateManager = new DbContext(optionsBuilder.Options).GetService <IStateManager>(); var modificationCommandSource = CreateModificationCommandSource(); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[(IProperty)keyProperty] = value1; entry1.SetEntityState(EntityState.Modified); var modificationCommand1 = modificationCommandSource.CreateModificationCommand( new ModificationCommandParameters("A", null, false, null, new ParameterNameGenerator().GenerateNext)); modificationCommand1.AddEntry(entry1, true); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[(IProperty)keyProperty] = value2; entry2.SetEntityState(EntityState.Modified); var modificationCommand2 = modificationCommandSource.CreateModificationCommand( new ModificationCommandParameters("A", null, false, null, new ParameterNameGenerator().GenerateNext)); modificationCommand2.AddEntry(entry2, true); var modificationCommand3 = modificationCommandSource.CreateModificationCommand( new ModificationCommandParameters("A", null, false, null, new ParameterNameGenerator().GenerateNext)); modificationCommand3.AddEntry(entry1, true); var mCC = new ModificationCommandComparer(); Assert.True(0 > mCC.Compare(modificationCommand1, modificationCommand2)); Assert.True(0 < mCC.Compare(modificationCommand2, modificationCommand1)); Assert.True(0 == mCC.Compare(modificationCommand1, modificationCommand3)); }
private void Compare_returns_0_only_for_entries_that_have_same_key_values_generic <T>(T value1, T value2) { var model = new Model(); var entityType = model.AddEntityType(typeof(object)); var optionsBuilder = new DbContextOptionsBuilder().UseModel(model).UseInMemoryDatabase(); var contextServices = new DbContext(optionsBuilder.Options).GetInfrastructure(); var stateManager = contextServices.GetRequiredService <IStateManager>(); var keyProperty = entityType.AddProperty("Id", typeof(T)); keyProperty.IsNullable = false; entityType.GetOrSetPrimaryKey(keyProperty); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[keyProperty] = value1; entry1.SetEntityState(EntityState.Modified); var modificationCommand1 = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommand1.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[keyProperty] = value2; entry2.SetEntityState(EntityState.Modified); var modificationCommand2 = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommand2.AddEntry(entry2); var modificationCommand3 = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommand3.AddEntry(entry1); var mCC = new ModificationCommandComparer(); Assert.True(0 > mCC.Compare(modificationCommand1, modificationCommand2)); Assert.True(0 < mCC.Compare(modificationCommand2, modificationCommand1)); Assert.True(0 == mCC.Compare(modificationCommand1, modificationCommand3)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { IMutableModel model = new Model(TestRelationalConventionSetBuilder.Build()); var entityType = model.AddEntityType(typeof(object)); var key = entityType.AddProperty("Id", typeof(int)); entityType.SetPrimaryKey(key); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model.FinalizeModel()) .UseInMemoryDatabase(Guid.NewGuid().ToString()) .UseInternalServiceProvider(InMemoryFixture.DefaultServiceProvider); var stateManager = new DbContext(optionsBuilder.Options).GetService <IStateManager>(); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[key] = 1; entry1.SetEntityState(EntityState.Added); var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null); modificationCommandAdded.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[key] = 2; entry2.SetEntityState(EntityState.Modified); var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null); modificationCommandModified.AddEntry(entry2); var entry3 = stateManager.GetOrCreateEntry(new object()); entry3[key] = 3; entry3.SetEntityState(EntityState.Deleted); var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null); modificationCommandDeleted.AddEntry(entry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True( 0 == mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null), null)); Assert.True( 0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null))); Assert.True( 0 < mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.True( 0 > mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, false, null))); Assert.True( 0 < mCC.Compare( new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, false, null))); Assert.True( 0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.True( 0 < mCC.Compare( new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, false, null), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var model = new Entity.Metadata.Model(); var entityType = model.AddEntityType(typeof(object)); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model); optionsBuilder.UseInMemoryStore(persist: false); var contextServices = ((IAccessor<IServiceProvider>)new DbContext(optionsBuilder.Options)).Service; var stateManager = contextServices.GetRequiredService<IStateManager>(); var key = entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType.GetOrSetPrimaryKey(key); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[key] = 1; entry1.SetEntityState(EntityState.Added); var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()); modificationCommandAdded.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[key] = 2; entry2.SetEntityState(EntityState.Modified); var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()); modificationCommandModified.AddEntry(entry2); var entry3 = stateManager.GetOrCreateEntry(new object()); entry3[key] = 3; entry3.SetEntityState(EntityState.Deleted); var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()); modificationCommandDeleted.AddEntry(entry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", "foo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "foo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("B", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 < mCC.Compare( new ModificationCommand("B", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()), new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new BoxedValueReaderSource()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var model = new Entity.Metadata.Model(); var entityType = model.AddEntityType(typeof(object)); var optionsBuilder = new EntityOptionsBuilder() .UseModel(model); optionsBuilder.UseInMemoryStore(persist: false); var contextServices = ((IAccessor <IServiceProvider>) new DbContext(optionsBuilder.Options)).Service; var stateManager = contextServices.GetRequiredService <IStateManager>(); var key = entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType.GetOrSetPrimaryKey(key); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[key] = 1; entry1.SetEntityState(EntityState.Added); var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()); modificationCommandAdded.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[key] = 2; entry2.SetEntityState(EntityState.Modified); var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()); modificationCommandModified.AddEntry(entry2); var entry3 = stateManager.GetOrCreateEntry(new object()); entry3[key] = 3; entry3.SetEntityState(EntityState.Deleted); var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()); modificationCommandDeleted.AddEntry(entry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", "foo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "foo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", "dbo", new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("B", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 < mCC.Compare( new ModificationCommand("B", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()), new ModificationCommand("A", null, new ParameterNameGenerator(), p => p.Relational(), new UntypedValueBufferFactoryFactory()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var mCC = new ModificationCommandComparer(); var configuration = new DbContext(new DbContextOptions().UseInMemoryStore(persist: false)).Configuration; var entityType1 = new EntityType(typeof(object)); var key1 = entityType1.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType1.GetOrSetPrimaryKey(key1); var stateEntry1 = new MixedStateEntry(configuration, entityType1, new object()); stateEntry1[key1] = 0; stateEntry1.EntityState = EntityState.Added; var modificationCommandAdded = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()); modificationCommandAdded.AddStateEntry(stateEntry1); var entityType2 = new EntityType(typeof(object)); var key2 = entityType2.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType2.GetOrSetPrimaryKey(key2); var stateEntry2 = new MixedStateEntry(configuration, entityType2, new object()); stateEntry2[key2] = 0; stateEntry2.EntityState = EntityState.Modified; var modificationCommandModified = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()); modificationCommandModified.AddStateEntry(stateEntry2); var entityType3 = new EntityType(typeof(object)); var key3 = entityType3.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType3.GetOrSetPrimaryKey(key3); var stateEntry3 = new MixedStateEntry(configuration, entityType3, new object()); stateEntry3[key3] = 0; stateEntry3.EntityState = EntityState.Deleted; var modificationCommandDeleted = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()); modificationCommandDeleted.AddStateEntry(stateEntry3); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A", "foo"), new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "foo"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("B"), new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("B"), new ParameterNameGenerator()), new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var model = new Model(); var entityType = model.AddEntityType(typeof(object)); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model); optionsBuilder.UseInMemoryDatabase(); var contextServices = new DbContext(optionsBuilder.Options).GetInfrastructure(); var stateManager = contextServices.GetRequiredService <IStateManager>(); var key = entityType.AddProperty("Id", typeof(int)); entityType.GetOrSetPrimaryKey(key); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[key] = 1; entry1.SetEntityState(EntityState.Added); var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandAdded.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[key] = 2; entry2.SetEntityState(EntityState.Modified); var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandModified.AddEntry(entry2); var entry3 = stateManager.GetOrCreateEntry(new object()); entry3[key] = 3; entry3.SetEntityState(EntityState.Deleted); var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandDeleted.AddEntry(entry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public TestCommandBatchPreparer( ModificationCommandBatchFactory modificationCommandBatchFactory, ParameterNameGeneratorFactory parameterNameGeneratorFactory, ModificationCommandComparer modificationCommandComparer, IBoxedValueReaderSource boxedValueReaderSource) : base(modificationCommandBatchFactory, parameterNameGeneratorFactory, modificationCommandComparer, boxedValueReaderSource) { }
public void Compare_returns_0_only_for_commands_that_are_equal() { var model = new Entity.Metadata.Model(); var entityType = model.AddEntityType(typeof(object)); var contextServices = ((IDbContextServices) new DbContext( new DbContextOptions() .UseModel(model) .UseInMemoryStore(persist: false))).ScopedServiceProvider; var stateManager = contextServices.GetRequiredService <StateManager>(); var key = entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true); entityType.GetOrSetPrimaryKey(key); var stateEntry1 = stateManager.GetOrCreateEntry(new object()); stateEntry1[key] = 0; stateEntry1.EntityState = EntityState.Added; var modificationCommandAdded = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()); modificationCommandAdded.AddStateEntry(stateEntry1); var stateEntry2 = stateManager.GetOrCreateEntry(new object()); stateEntry2[key] = 1; stateEntry2.EntityState = EntityState.Modified; var modificationCommandModified = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()); modificationCommandModified.AddStateEntry(stateEntry2); var stateEntry3 = stateManager.GetOrCreateEntry(new object()); stateEntry3[key] = 2; stateEntry3.EntityState = EntityState.Deleted; var modificationCommandDeleted = new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()); modificationCommandDeleted.AddStateEntry(stateEntry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 < mCC.Compare(new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A", "foo"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A", "foo"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A", "dbo"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 > mCC.Compare( new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("B"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 < mCC.Compare( new ModificationCommand(new SchemaQualifiedName("B"), new ParameterNameGenerator(), p => p.Relational()), new ModificationCommand(new SchemaQualifiedName("A"), new ParameterNameGenerator(), p => p.Relational()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var model = new Model(); var entityType = model.AddEntityType(typeof(object)); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model); optionsBuilder.UseInMemoryDatabase(); var contextServices = new DbContext(optionsBuilder.Options).GetInfrastructure(); var stateManager = contextServices.GetRequiredService<IStateManager>(); var key = entityType.AddProperty("Id", typeof(int)); entityType.GetOrSetPrimaryKey(key); var entry1 = stateManager.GetOrCreateEntry(new object()); entry1[key] = 1; entry1.SetEntityState(EntityState.Added); var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandAdded.AddEntry(entry1); var entry2 = stateManager.GetOrCreateEntry(new object()); entry2[key] = 2; entry2.SetEntityState(EntityState.Modified); var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandModified.AddEntry(entry2); var entry3 = stateManager.GetOrCreateEntry(new object()); entry3[key] = 3; entry3.SetEntityState(EntityState.Deleted); var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()); modificationCommandDeleted.AddEntry(entry3); var mCC = new ModificationCommandComparer(); Assert.True(0 == mCC.Compare(modificationCommandAdded, modificationCommandAdded)); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 == mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), null)); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("A", "foo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", "dbo", new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare( new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 < mCC.Compare( new ModificationCommand("B", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()), new ModificationCommand("A", null, new ParameterNameGenerator().GenerateNext, p => p.TestProvider()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }
public void Compare_returns_0_only_for_commands_that_are_equal() { var mCC = new ModificationCommandComparer(); var configuration = new DbContext(new DbContextOptions().UseInMemoryStore(persist: false)).Configuration; var entityType1 = new EntityType(typeof(object)); var key1 = entityType1.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false); entityType1.SetKey(key1); var stateEntry1 = new MixedStateEntry(configuration, entityType1, new object()); stateEntry1[key1] = 0; stateEntry1.EntityState = EntityState.Added; var modificationCommandAdded = new ModificationCommand("A", null, new ParameterNameGenerator()); modificationCommandAdded.AddStateEntry(stateEntry1); var entityType2 = new EntityType(typeof(object)); var key2 = entityType2.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false); entityType2.SetKey(key2); var stateEntry2 = new MixedStateEntry(configuration, entityType2, new object()); stateEntry2[key2] = 0; stateEntry2.EntityState = EntityState.Modified; var modificationCommandModified = new ModificationCommand("A", null, new ParameterNameGenerator()); modificationCommandModified.AddStateEntry(stateEntry2); var entityType3 = new EntityType(typeof(object)); var key3 = entityType3.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false); entityType3.SetKey(key3); var stateEntry3 = new MixedStateEntry(configuration, entityType3, new object()); stateEntry3[key3] = 0; stateEntry3.EntityState = EntityState.Deleted; var modificationCommandDeleted = new ModificationCommand("A", null, new ParameterNameGenerator()); modificationCommandDeleted.AddStateEntry(stateEntry3); Assert.True(0 == mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator()), new ModificationCommand("A", null, new ParameterNameGenerator()))); Assert.True(0 == mCC.Compare(new ModificationCommand("A", "dbo", new ParameterNameGenerator()), new ModificationCommand("A", "dbo", new ParameterNameGenerator()))); Assert.True(0 == mCC.Compare(null, null)); Assert.True(0 > mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator()), new ModificationCommand("A", "dbo", new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", "foo", new ParameterNameGenerator()), new ModificationCommand("A", "dbo", new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(null, new ModificationCommand("A", null, new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator()), null)); Assert.True(0 > mCC.Compare(new ModificationCommand("A", null, new ParameterNameGenerator()), new ModificationCommand("B", null, new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand("B", null, new ParameterNameGenerator()), new ModificationCommand("A", null, new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(new ModificationCommand("A", "dbo", new ParameterNameGenerator()), new ModificationCommand("B", "dbo", new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand("B", "dbo", new ParameterNameGenerator()), new ModificationCommand("A", "dbo", new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(new ModificationCommand("A", "dbo", new ParameterNameGenerator()), new ModificationCommand("B", null, new ParameterNameGenerator()))); Assert.True(0 < mCC.Compare(new ModificationCommand("B", "dbo", new ParameterNameGenerator()), new ModificationCommand("A", "foo", new ParameterNameGenerator()))); Assert.True(0 > mCC.Compare(modificationCommandModified, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandModified)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandAdded)); Assert.True(0 < mCC.Compare(modificationCommandAdded, modificationCommandDeleted)); Assert.True(0 > mCC.Compare(modificationCommandDeleted, modificationCommandModified)); Assert.True(0 < mCC.Compare(modificationCommandModified, modificationCommandDeleted)); }