Esempio n. 1
0
        public DataProducerTest()
            : base()
        {
            customerTable = new TableEntity("dbo", "Customer");
            var customerId = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null);

            customerTable.AddColumn(customerId);
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", true), false, 3, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", true), false, 4, false, null, null));

            var fk = new ForeignKeyEntity();

            fk.ReferencingColumn = "CustomerId";
            fk.ReferencingTable  = customerTable;

            orderTable = new TableEntity("dbo", "Order");
            var customerIdColumn = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), false, 2, true, null, fk);

            customerIdColumn.Generator = new SQLDataProducer.Entities.Generators.IntGenerators.ValueFromOtherColumnIntGenerator(customerIdColumn.ColumnDataType);
            customerIdColumn.Generator.GeneratorParameters["Value From Column"].Value = customerId;

            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));
            orderTable.AddColumn(customerIdColumn);
            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Amount", new ColumnDataTypeDefinition("decimal(19, 6)", false), false, 3, false, null, null));
            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("SessionId", new ColumnDataTypeDefinition("uniqueidentifier", false), false, 4, false, null, null));
        }
        public void ShouldAddRangeOfColumns()
        {
            TableEntity table    = new TableEntity("dbo", "Customer");
            var         idColumn = DatabaseEntityFactory.CreateColumnEntity(
                "CustomerId",
                new ColumnDataTypeDefinition("int", true),
                true,
                1,
                false,
                string.Empty,
                null);

            var nameColumn = DatabaseEntityFactory.CreateColumnEntity(
                "CustomerName",
                new ColumnDataTypeDefinition("varchar(500)", true),
                false,
                2,
                false,
                string.Empty,
                null);

            IEnumerable <ColumnEntity> columnsToAdd = new List <ColumnEntity> {
                idColumn, nameColumn
            };

            table.AddColumns(columnsToAdd);

            Assert.That(table.Columns.Contains(idColumn));
            Assert.That(table.Columns.Contains(nameColumn));
            Assert.That(table.HasIdentityColumn);
        }
Esempio n. 3
0
        public InsertConsumerTest()
        {
            customerTable = new TableEntity("dbo", "Customer");
            var customerId = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null);

            customerTable.AddColumn(customerId);
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", false), false, 3, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", false), false, 4, false, null, null));

            orderTable = new TableEntity("dbo", "Orders");
            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));

            var fk = new ForeignKeyEntity();

            fk.ReferencingColumn = "CustomerId";
            fk.ReferencingTable  = customerTable;

            var customerIdColumn = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), false, 2, true, null, fk);

            customerIdColumn.Generator = new SQLDataProducer.Entities.Generators.IntGenerators.ValueFromOtherColumnIntGenerator(customerIdColumn.ColumnDataType);
            customerIdColumn.Generator.GeneratorParameters.ValueFromOtherColumn.Value = customerId;

            orderTable.AddColumn(customerIdColumn);
            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("ArticleId", new ColumnDataTypeDefinition("int", false), false, 3, false, null, null));
            orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("TotalAmount", new ColumnDataTypeDefinition("decimal(19, 6)", false), false, 4, false, null, null));


            var builder = new System.Data.SqlClient.SqlConnectionStringBuilder();

            builder.DataSource         = "localhost";
            builder.InitialCatalog     = "AdventureWorks";
            builder.IntegratedSecurity = true;
            connectionString           = builder.ToString();
        }
Esempio n. 4
0
        public void shouldUseSameGeneratedValueWhenGettingValueFromSameTable()
        {
            TableEntity table     = new TableEntity("dbo", "Calendar");
            var         startDate = DatabaseEntityFactory.CreateColumnEntity("StartDate", new ColumnDataTypeDefinition("datetime", false), false, 1, false, null, null);
            var         endDate   = DatabaseEntityFactory.CreateColumnEntity("EndDate", new ColumnDataTypeDefinition("datetime", false), false, 2, false, null, null);

            endDate.Generator = new ValueFromOtherColumnDateTimeGenerator(endDate.ColumnDataType);
            endDate.Generator.GeneratorParameters["Value From Column"].Value = startDate;

            table.AddColumn(startDate);
            table.AddColumn(endDate);

            var tables = new List <ExecutionTable>();

            tables.Add(new ExecutionTable(table, 1));

            List <DataRowEntity> rows = new List <DataRowEntity>(new DataProducer(new ValueStore()).ProduceRows(tables));

            Assert.That(rows.Count, Is.EqualTo(1));

            var row = rows[0];

            // Check key is the same as it is for the CustomerId column in CustomerRow
            Assert.That(row.Fields[1].KeyValue, Is.EqualTo(row.Fields[0].KeyValue));
        }
Esempio n. 5
0
        public CommonDataConsumerTest(Dictionary <string, string> options, Func <IDataConsumer> getNewInstanceOfConsumer)
        {
            this.GetImplementedType = getNewInstanceOfConsumer;
            this.options            = options;

            customerTable = new TableEntity("dbo", "Customer").AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));

            orderTable = new TableEntity("dbo", "Order").AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));


            singleRowDataSet = new List <DataRowEntity>();
            singleRowDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));

            tenRowsDataSet = new List <DataRowEntity>();
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            tenRowsDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));

            mixedDataSet = new List <DataRowEntity>();
            mixedDataSet.Add(new DataRowEntity(customerTable).AddField("CustomerId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
            mixedDataSet.Add(new DataRowEntity(orderTable).AddField("OrderId", Guid.NewGuid(), new ColumnDataTypeDefinition("int", false), false));
        }
Esempio n. 6
0
        public void ShouldAddColumnToCollection()
        {
            var columns = new ColumnEntityCollection();

            columns.Add(DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));

            Assert.That(columns.Count(), Is.EqualTo(1));
        }
Esempio n. 7
0
        public void ShouldGetColumnFromCollection()
        {
            var columns = new ColumnEntityCollection();
            var column  = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null);

            columns.Add(column);

            Assert.That(columns[0], Is.EqualTo(column));
            Assert.That(columns.Get("CustomerId"), Is.EqualTo(column));
        }
        private static TableEntity CreateCustomerTable()
        {
            var customerTable = new TableEntity("dbo", "Customer");
            var customerId    = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null);

            customerTable.AddColumn(customerId);
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", false), false, 3, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", false), false, 4, false, null, null));
            return(customerTable);
        }
        private static TableEntity CreateOrderTable()
        {
            var ordertable = new TableEntity("dbo", "Orders");

            ordertable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));
            ordertable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderDate", new ColumnDataTypeDefinition("datetime", false), false, 2, false, null, null));
            ordertable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Quantity", new ColumnDataTypeDefinition("int", false), false, 3, false, null, null));
            ordertable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("TotalCost", new ColumnDataTypeDefinition("decimal(19,6)", false), false, 4, false, null, null));
            ordertable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), false, 5, true, null, new ForeignKeyEntity()));

            return(ordertable);
        }
Esempio n. 10
0
        static ProjectModelDummy()
        {
            model = new ProjectModel();
            var customerTable = new TableEntity("dbo", "Customer");
            var customerId    = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null);

            customerTable.AddColumn(customerId);
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", false), false, 3, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", false), false, 4, false, null, null));

            model.Tables.Add(customerTable);
        }
        public void ShouldAddColumnToTable()
        {
            TableEntity table  = new TableEntity("dbo", "Customer");
            var         column = DatabaseEntityFactory.CreateColumnEntity(
                "CustomerName",
                new ColumnDataTypeDefinition("varchar(500)", true),
                false,
                2,
                false,
                string.Empty,
                null);

            table.AddColumn(column);

            Assert.That(table.Columns.Contains(column));
        }
Esempio n. 12
0
        public TableQueryGeneratorTest()
        {
            customerTable = new TableEntity("dbo", "Customer");
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", false), false, 3, false, null, null));
            customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", false), false, 4, false, null, null));

            tableWithIdentity = new TableEntity("dbo", "Order");
            tableWithIdentity.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));
            tableWithIdentity.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderDate", new ColumnDataTypeDefinition("datetime", false), false, 2, false, null, null));

            tableWithNullFields = new TableEntity("dbo", "OrderDetails");
            tableWithNullFields.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderDetailId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null));
            tableWithNullFields.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Details", new ColumnDataTypeDefinition("varchar(max)", true), false, 2, false, null, null));
        }
        public void ShouldAddIdentityColumnAndBeMarkedWithIdentityTable()
        {
            TableEntity table  = new TableEntity("dbo", "Customer");
            var         column = DatabaseEntityFactory.CreateColumnEntity(
                "CustomerId",
                new ColumnDataTypeDefinition("int", true),
                true,
                1,
                false,
                string.Empty,
                null);

            table.AddColumn(column);

            Assert.That(table.Columns.Contains(column));
            Assert.That(table.HasIdentityColumn);
        }
        public void GivenSomeTableConfigurationItShouldGenerateValuesForAllColumns()
        {
            TableEntity table = new TableEntity("dbo", "Customer");

            table.AddColumn(DatabaseEntityFactory.CreateColumnEntity(
                                "CustomerName",
                                new ColumnDataTypeDefinition("varchar(500)", true),
                                false,
                                2,
                                false,
                                string.Empty,
                                null));

            ColumnEntity firstCol = table.Columns.First();

            Assert.IsTrue(firstCol.ColumnName == "CustomerName");
            Assert.IsTrue(firstCol.IsForeignKey == false);
            Assert.IsTrue(firstCol.IsIdentity == false);
            Assert.IsTrue(firstCol.OrdinalPosition == 2);
            Assert.IsTrue(firstCol.Generator != null);
            Assert.IsTrue(firstCol.PossibleGenerators.Count > 0);
            Assert.IsTrue(firstCol.HasWarning == false);

            table.AddColumn(DatabaseEntityFactory.CreateColumnEntity(
                                "CustomerID",
                                new ColumnDataTypeDefinition("int", false),
                                true,
                                1,
                                false,
                                string.Empty,
                                null));

            ColumnEntity secondCol = table.Columns.Skip(1).First();

            Assert.IsTrue(secondCol.ColumnName == "CustomerID");
            Assert.IsTrue(secondCol.IsForeignKey == false);
            Assert.IsTrue(secondCol.IsIdentity == true);
            Assert.IsTrue(secondCol.OrdinalPosition == 1);
            Assert.IsTrue(secondCol.Generator != null);
            Assert.IsTrue(secondCol.PossibleGenerators.Count > 0);
            Assert.IsTrue(secondCol.HasWarning == false);
        }