DeleteCommand() public method

Modifies the command to execute a DELETE statement
/// command /// or /// entity ///
public DeleteCommand ( IDbCommand command, object entity ) : void
command IDbCommand Command that will be executed after this method call
entity object Only primary key properties are used in the WHERE clause
return void
        public void do_not_allow_DbNull_in_the_delete_query()
        {
            var mapper = Substitute.For<ICrudEntityMapper>();
            mapper.TableName.Returns("Users");
            mapper.Properties.Returns(new Dictionary<string, IPropertyMapping>
            {
                {"Name", new FakePropertyMapping("Name", "real_name")},
                {"Id", new FakePropertyMapping("Id", "id"){Value = DBNull.Value, IsPrimaryKey = true}}
            });
            var command = new AdoNetFakes.FakeCommand();
            var entity = new { Id = "Hello" };


            var sut = new CommandBuilder(mapper);
            Action actual = () => sut.DeleteCommand(command, entity);

            actual.ShouldThrow<DataException>();
        }
        public void key_should_be_the_only_field_in_a_delete_query()
        {
            var mapper = Substitute.For<ICrudEntityMapper>();
            mapper.TableName.Returns("Users");
            mapper.Properties.Returns(new Dictionary<string, IPropertyMapping>
            {
                {"Name", new FakePropertyMapping("Name", "real_name"){Value = "Arne"}},
                {"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.DeleteCommand(command, entity);

            command.Parameters.Count.Should().Be(1);
        }
        public void key_is_assigned_correctly_in_a_delete_query()
        {
            var mapper = Substitute.For<ICrudEntityMapper>();
            mapper.TableName.Returns("Users");
            mapper.Properties.Returns(new Dictionary<string, IPropertyMapping>
            {
                {"Name", new FakePropertyMapping("Name", "real_name"){Value = "Arne"}},
                {"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.DeleteCommand(command, entity);

            command.CommandText.Should().Be("DELETE FROM Users WHERE id=@Id");
            command.Parameters[0].ParameterName.Should().Be("Id");
            command.Parameters[0].Value.Should().Be("Hello");
        }
        public void keys_must_be_specified_in_a_delete_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.DeleteCommand(command, entity);

            actual.ShouldThrow<DataException>();
        }