InsertCommand() public method

Generate an insert command, should end with a command that returns the insert identity.
/// command /// or /// entity /// No values were added to the query for + entity
public InsertCommand ( IDbCommand command, object entity ) : void
command IDbCommand Command to add the query to
entity object Entity to store
return void
コード例 #1
0
        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>();
        }
コード例 #2
0
        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");
        }