Esempio n. 1
0
        public void ShouldGenerateInsertStatement()
        {
            TableQueryGenerator generator = new TableQueryGenerator(customerTable);
            string statement = generator.InsertStatement;

            Assert.That(statement, Is.Not.Null);
            Assert.That(statement, Is.Not.Empty);

            Assert.That(statement, Is.EqualTo("INSERT INTO dbo.Customer(" + generator.ColumnList + ")"));
        }
Esempio n. 2
0
        public void ShouldGenerateColumnListForTableForAllColumnExceptIdentityColumn()
        {
            TableQueryGenerator generator = new TableQueryGenerator(customerTable);
            string columnList             = generator.ColumnList;

            Assert.That(columnList, Is.Not.Null);
            Assert.That(columnList, Is.Not.Empty);

            Assert.That(columnList, Is.EqualTo("CustomerType, Name, IsActive"));
        }
Esempio n. 3
0
        public void ShouldGenerateValuesStatement()
        {
            TableQueryGenerator generator = new TableQueryGenerator(customerTable);
            var          valueStore       = new ValueStore();
            DataProducer producer         = new DataProducer(valueStore);
            var          dataRow          = producer.ProduceRow(customerTable, 1);

            string values = generator.GenerateValuesStatement(dataRow, valueStore);

            Assert.That(values, Is.Not.Empty);
            Assert.That(values, Is.Not.Null);

            Assert.That(values, Is.EqualTo("VALUES (1, 'Arboga', 1)"));
        }
Esempio n. 4
0
        public void ShouldKnowAboutNullValues()
        {
            var          valueStore = new ValueStore();
            DataProducer producer   = new DataProducer(valueStore);

            TableQueryGenerator generator = new TableQueryGenerator(tableWithNullFields);

            IEnumerable <DataRowEntity> rows = new List <DataRowEntity> {
                producer.ProduceRow(tableWithNullFields, 1)
            };

            string actual = generator.GenerateValuesStatement(rows.First(), valueStore);

            Assert.That(actual, Is.EqualTo("VALUES (NULL)"));
        }
Esempio n. 5
0
        public void ShouldGenerateFullInsertStatementForOneRow()
        {
            TableQueryGenerator generator = new TableQueryGenerator(customerTable);
            var          valueStore       = new ValueStore();
            DataProducer producer         = new DataProducer(valueStore);

            IEnumerable <DataRowEntity> rows = new List <DataRowEntity> {
                producer.ProduceRow(customerTable, 1)
            };

            string firstValues = generator.GenerateInsertStatement(rows.First(), valueStore);

            Assert.That(firstValues, Is.StringStarting("INSERT INTO dbo.Customer(" + generator.ColumnList + ") OUTPUT INSERTED.CustomerId")
                        .And.StringEnding(" VALUES (1, 'Arboga', 1)"));
        }
Esempio n. 6
0
        public void ShouldGenerateInsertStatementForValueProducingColumns()
        {
            var          valueStore = new ValueStore();
            DataProducer producer   = new DataProducer(valueStore);

            TableQueryGenerator generator = new TableQueryGenerator(tableWithIdentity);

            IEnumerable <DataRowEntity> rows = new List <DataRowEntity> {
                producer.ProduceRow(tableWithIdentity, 1)
            };


            Assert.That(generator.ColumnList, Is.EqualTo("OrderDate"));
            Assert.That(
                generator.GenerateInsertStatement(rows.First(), valueStore),
                Is.StringStarting("INSERT INTO dbo.Order(" + generator.ColumnList + ") OUTPUT INSERTED.OrderId"));
        }
Esempio n. 7
0
        public void ShouldGenerateFullInsertStatementForAllRows()
        {
            var          valueStore = new ValueStore();
            DataProducer producer   = new DataProducer(valueStore);

            IEnumerable <DataRowEntity> rows = new List <DataRowEntity> {
                producer.ProduceRow(customerTable, 1), producer.ProduceRow(customerTable, 2)
            };

            string firstValues = TableQueryGenerator.GenerateInsertStatements(rows, valueStore).First();

            Assert.That(firstValues, Is.StringStarting("INSERT INTO dbo.Customer(CustomerType, Name, IsActive) OUTPUT INSERTED.CustomerId AS")
                        .And.StringEnding(" VALUES (1, 'Arboga', 1)"));

            string secondValues = TableQueryGenerator.GenerateInsertStatements(rows, valueStore).Skip(1).First();

            Assert.That(secondValues, Is.StringStarting("INSERT INTO dbo.Customer(CustomerType, Name, IsActive) OUTPUT INSERTED.CustomerId AS")
                        .And.StringEnding(" VALUES (2, 'Arvika', 1)"));
        }
Esempio n. 8
0
 public void ShouldInstantiateGenerator()
 {
     TableQueryGenerator generator = new TableQueryGenerator(customerTable);
 }