public void PopulateParameters_does_not_create_parameter_for_read_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.SetTemporaryValue(property, -1); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( new FakeModificationCommand( "T", "S", parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), parameterNameGenerator.GenerateNext, true, false, false, false, false) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(0, storeCommand.RelationalCommand.Parameters.Count); }
public void PopulateParameters_creates_parameter_for_condition_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); batch.AddCommand( new FakeModificationCommand( "T", "S", new ParameterNameGenerator(), p => p.TestProvider(), new List <ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), false, false, false, true) })); var command = batch.CreateStoreCommandBase(); Assert.Equal(1, command.Parameters.Count); }
public void PopulateParameters_does_not_create_parameter_for_read_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.SetTemporaryValue(property, -1); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( new FakeModificationCommand( "T1", null, parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, property.GetTableColumnMappings().Single().Column, parameterNameGenerator.GenerateNext, property.GetTableColumnMappings().Single().TypeMapping, isRead: true, isWrite: false, isKey: false, isCondition: false, sensitiveLoggingEnabled: true) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(0, storeCommand.RelationalCommand.Parameters.Count); }
public void PopulateParameters_creates_parameter_for_write_and_condition_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( new FakeModificationCommand( "T", "S", parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), parameterNameGenerator.GenerateNext, false, true, false, true, false) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(1, storeCommand.RelationalCommand.Parameters.Count); Assert.Equal("p0", storeCommand.RelationalCommand.Parameters[0].InvariantName); Assert.Equal(1, storeCommand.ParameterValues.Count); Assert.Equal(1, storeCommand.ParameterValues["p0"]); }
public void PopulateParameters_creates_parameter_for_condition_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.SetTemporaryValue(property, 1); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( CreateModificationCommand( "T1", null, true, new[] { new ColumnModificationParameters( entry, property, property.GetTableColumnMappings().Single().Column, parameterNameGenerator.GenerateNext, property.GetTableColumnMappings().Single().TypeMapping, valueIsRead: false, valueIsWrite: false, columnIsKey: false, columnIsCondition: true, sensitiveLoggingEnabled: true) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(1, storeCommand.RelationalCommand.Parameters.Count); Assert.Equal("p0", storeCommand.RelationalCommand.Parameters[0].InvariantName); Assert.Equal(1, storeCommand.ParameterValues.Count); Assert.Equal(1, storeCommand.ParameterValues["p0"]); }
public void PopulateParameters_creates_parameter_for_condition_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.SetTemporaryValue(property, 1); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( new FakeModificationCommand( "T", "S", parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, parameterNameGenerator.GenerateNext, isRead: false, isWrite: false, isKey: false, isCondition: true, isConcurrencyToken: false, sensitiveLoggingEnabled: true) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(1, storeCommand.RelationalCommand.Parameters.Count); Assert.Equal("p0", storeCommand.RelationalCommand.Parameters[0].InvariantName); Assert.Equal(1, storeCommand.ParameterValues.Count); Assert.Equal(1, storeCommand.ParameterValues["p0"]); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.GetProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); var commandMock1 = new Mock <ModificationCommand>( "T", "S", new ParameterNameGenerator(), (Func <IProperty, IRelationalPropertyAnnotations>)(p => p.TestProvider())); commandMock1.Setup(m => m.ColumnModifications).Returns( new List <ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), false, true, false, false) }); batch.AddCommand(commandMock1.Object); var commandMock2 = new Mock <ModificationCommand>( "T", "S", new ParameterNameGenerator(), (Func <IProperty, IRelationalPropertyAnnotations>)(p => p.TestProvider())); commandMock2.Setup(m => m.ColumnModifications).Returns( new List <ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), false, true, false, false) }); batch.AddCommand(commandMock2.Object); var transaction = CreateMockDbTransaction(); var transactionMock = new Mock <IRelationalTransaction>(); var connectionMock = new Mock <IRelationalConnection>(); connectionMock.Setup(m => m.Transaction).Returns(transactionMock.Object); connectionMock.Setup(m => m.DbConnection).Returns(transaction.Connection); var command = batch.CreateStoreCommandBase("foo", connectionMock.Object); Assert.Equal("foo", command.CommandText); Assert.Equal(2, batch.PopulateParameterCalls); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.SetTemporaryValue(property, 1); var batch = new ModificationCommandBatchFake(); var parameterNameGenerator = new ParameterNameGenerator(); batch.AddCommand( new FakeModificationCommand( "T1", null, parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, property.GetTableColumnMappings().Single().Column, parameterNameGenerator.GenerateNext, property.GetTableColumnMappings().Single().TypeMapping, false, true, false, false, true) })); batch.AddCommand( new FakeModificationCommand( "T1", null, parameterNameGenerator.GenerateNext, true, new List <ColumnModification> { new ColumnModification( entry, property, property.GetTableColumnMappings().Single().Column, parameterNameGenerator.GenerateNext, property.GetTableColumnMappings().Single().TypeMapping, false, true, false, false, true) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(2, storeCommand.RelationalCommand.Parameters.Count); Assert.Equal("p0", storeCommand.RelationalCommand.Parameters[0].InvariantName); Assert.Equal("p1", storeCommand.RelationalCommand.Parameters[1].InvariantName); Assert.Equal(2, storeCommand.ParameterValues.Count); Assert.Equal(1, storeCommand.ParameterValues["p0"]); Assert.Equal(1, storeCommand.ParameterValues["p1"]); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.GetProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); var commandMock1 = new Mock <ModificationCommand>(); commandMock1.Setup(m => m.ColumnModifications).Returns( new List <ColumnModification> { new ColumnModification( entry, property, property.Relational(), new ParameterNameGenerator(), null, false, true, false, false) }); batch.AddCommand(commandMock1.Object); var commandMock2 = new Mock <ModificationCommand>(); commandMock2.Setup(m => m.ColumnModifications).Returns( new List <ColumnModification> { new ColumnModification( entry, property, property.Relational(), new ParameterNameGenerator(), null, false, true, false, false) }); batch.AddCommand(commandMock2.Object); var transaction = CreateMockDbTransaction(); var command = batch.CreateStoreCommandBase("foo", transaction, new RelationalTypeMapper(), null); Assert.Equal(CommandType.Text, command.CommandType); Assert.Equal("foo", command.CommandText); Assert.Same(transaction, command.Transaction); Assert.Equal(2, batch.PopulateParameterCalls); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand_with_non_null_parameter_name() { var stateEntry = CreateStateEntry(EntityState.Added, ValueGenerationOnSave.WhenInserting); var property = stateEntry.EntityType.GetProperty("Id"); var batch = new ModificationCommandBatchFake(); var commandMock = new Mock <ModificationCommand>(); commandMock.Setup(m => m.ColumnModifications).Returns( new List <ColumnModification> { new ColumnModification( stateEntry, property, parameterName: "p", originalParameterName: null, isRead: false, isWrite: false, isKey: false, isCondition: false), new ColumnModification( stateEntry, property, parameterName: null, originalParameterName: "op", isRead: false, isWrite: false, isKey: false, isCondition: false), }); batch.AddCommand(commandMock.Object, new Mock <SqlGenerator> { CallBase = true }.Object); var command = batch.CreateStoreCommandBase(CreateMockDbTransaction(), new RelationalTypeMapper()); Assert.Equal("p", command.Parameters[0].ParameterName); Assert.Equal("op", command.Parameters[1].ParameterName); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.GetProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); var commandMock1 = new Mock<ModificationCommand>( "T", "S", new ParameterNameGenerator(), (Func<IProperty, IRelationalPropertyAnnotations>)(p => p.TestProvider()), Mock.Of<IRelationalValueBufferFactoryFactory>()); commandMock1.Setup(m => m.ColumnModifications).Returns( new List<ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), false, true, false, false) }); batch.AddCommand(commandMock1.Object); var commandMock2 = new Mock<ModificationCommand>( "T", "S", new ParameterNameGenerator(), (Func<IProperty, IRelationalPropertyAnnotations>)(p => p.TestProvider()), Mock.Of<IRelationalValueBufferFactoryFactory>()); commandMock2.Setup(m => m.ColumnModifications).Returns( new List<ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), false, true, false, false) }); batch.AddCommand(commandMock2.Object); var transaction = CreateMockDbTransaction(); var command = batch.CreateStoreCommandBase("foo", transaction, new ConcreteTypeMapper(), null); Assert.Equal(CommandType.Text, command.CommandType); Assert.Equal("foo", command.CommandText); Assert.Same(transaction, command.Transaction); Assert.Equal(2, batch.PopulateParameterCalls); }
public void PopulateParameters_does_not_create_parameter_for_read_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); batch.AddCommand( new FakeModificationCommand( "T", "S", new ParameterNameGenerator(), p => p.TestProvider(), new List<ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator(), true, false, false, false) })); var command = batch.CreateStoreCommandBase(); Assert.Equal(0, command.Parameters.Count); }
public void PopulateParameters_creates_parameter_for_write_and_condition_ModificationCommand() { var entry = CreateEntry(EntityState.Added, generateKeyValues: true); var property = entry.EntityType.FindProperty("Id"); entry.MarkAsTemporary(property); var batch = new ModificationCommandBatchFake(); batch.AddCommand( new FakeModificationCommand( "T", "S", new ParameterNameGenerator(), p => p.TestProvider(), new List<ColumnModification> { new ColumnModification( entry, property, property.TestProvider(), new ParameterNameGenerator().GenerateNext, false, true, false, true) })); var storeCommand = batch.CreateStoreCommandBase(); Assert.Equal(2, storeCommand.RelationalCommand.Parameters.Count); Assert.Equal("p0", storeCommand.RelationalCommand.Parameters[0].InvariantName); Assert.Equal("p1", storeCommand.RelationalCommand.Parameters[1].InvariantName); Assert.Equal(2, storeCommand.ParameterValues.Count); Assert.Equal(1, storeCommand.ParameterValues["p0"]); Assert.Equal(1, storeCommand.ParameterValues["p1"]); }
public void CreateStoreCommand_creates_parameters_for_each_ModificationCommand_with_non_null_parameter_name() { var stateEntry = CreateStateEntry(EntityState.Added, ValueGenerationOnSave.WhenInserting); var property = stateEntry.EntityType.GetProperty("Id"); var batch = new ModificationCommandBatchFake(); var commandMock = new Mock<ModificationCommand>(); commandMock.Setup(m => m.ColumnModifications).Returns( new List<ColumnModification> { new ColumnModification( stateEntry, property, parameterName: "p", originalParameterName: null, isRead: false, isWrite: false, isKey: false, isCondition: false), new ColumnModification( stateEntry, property, parameterName: null, originalParameterName: "op", isRead: false, isWrite: false, isKey: false, isCondition: false), }); batch.AddCommand(commandMock.Object, new Mock<SqlGenerator> { CallBase = true }.Object); var command = batch.CreateStoreCommandBase(CreateMockDbTransaction(), new RelationalTypeMapper()); Assert.Equal("p", command.Parameters[0].ParameterName); Assert.Equal("op", command.Parameters[1].ParameterName); }