Esempio n. 1
0
        public int Delete <T>(T item, string tableName)
        {
            var       inserter = new DeleteCommandBuilder <T>(_database, Connection, tableName, Transaction);
            DbCommand command  = inserter.Build(item);

            return(command.ExecuteNonQuery());
        }
Esempio n. 2
0
    public void Build_Generates_Command_With_Parameters()
    {
        // Arrange
        var input = new DeleteCommandBuilder()
                    .From("MyTable")
                    .Where("Field1 = @Field1")
                    .And("Field2 = @Field2")
                    .And("Field3 = @Field3")
                    .AppendParameters(new { Field1 = "Value1", Field2 = "Value2", Field3 = "Value3" });

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable WHERE Field1 = @Field1 AND Field2 = @Field2 AND Field3 = @Field3");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        if (parameters != null)
        {
            parameters.Should().HaveCount(3);
            parameters.Keys.Should().BeEquivalentTo(new[] { "Field1", "Field2", "Field3" });
            parameters.Values.Should().BeEquivalentTo(new[] { "Value1", "Value2", "Value3" });
        }
    }
Esempio n. 3
0
    public void Build_Generates_Command_Without_Where_Statement()
    {
        // Arrange
        var input = new DeleteCommandBuilder().From("MyTable");

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        parameters.Should().BeEmpty();
    }
Esempio n. 4
0
    public void Build_Generates_Command_With_OutputValues()
    {
        // Arrange
        var input = new DeleteCommandBuilder()
                    .From("MyTable")
                    .Where("Field1 = @Field1")
                    .And("Field2 = @Field2")
                    .And("Field3 = @Field3")
                    .AddOutputFields("Field1", "Field2");

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable OUTPUT Field1, Field2 WHERE Field1 = @Field1 AND Field2 = @Field2 AND Field3 = @Field3");
    }