public InsertCommand ( IDbCommand command, object entity ) : void | ||
command | IDbCommand | Command to add the query to |
entity | object | Entity to store |
Результат | void |
public void key_without_value_is_ignored_in_the_insert_query() { var mapper = Substitute.For<ICrudEntityMapper>(); mapper.TableName.Returns("Users"); mapper.Properties.Returns(new Dictionary<string, IPropertyMapping> { {"Id", new FakePropertyMapping("Id", "id"){IsPrimaryKey = true}} }); var command = new AdoNetFakes.FakeCommand(); var entity = new { Id = "Hello" }; var sut = new CommandBuilder(mapper); Action actual = () => sut.InsertCommand(command, entity); actual.ShouldThrow<DataException>(); }
public void key_is_added_in_the_insert_query() { var mapper = Substitute.For<ICrudEntityMapper>(); mapper.TableName.Returns("Users"); mapper.Properties.Returns(new Dictionary<string, IPropertyMapping> { {"Id", new FakePropertyMapping("Id", "id"){Value = "Hello",IsPrimaryKey = true}} }); var command = new AdoNetFakes.FakeCommand(); var entity = new {Id = "Hello"}; var sut = new CommandBuilder(mapper); sut.InsertCommand(command, entity); command.CommandText.Should().Be("INSERT INTO Users (id) VALUES(@Id)"); command.Parameters[0].ParameterName.Should().Be("Id"); command.Parameters[0].Value.Should().Be("Hello"); }