Beispiel #1
0
        public async Task NewConnection()
        {
            //test 1, create initial connection
            using (var database = await CreateRepositoryWithConnections())
            {
                var dbConnection = await database.DbContext.DexihConnections.SingleOrDefaultAsync(c => c.Name == "source" && c.IsValid);

                Assert.Equal("source", dbConnection.Name);
                Assert.Equal("source server", dbConnection.Server);

                //modify the connection and re-save
                dbConnection.Server = "source server 2";
                var saveConnectionResult = await database.SaveConnection(dbConnection.HubKey, dbConnection, CancellationToken.None);

                Assert.NotNull(saveConnectionResult);

                dbConnection = database.DbContext.DexihConnections.Single(c => c.Key == saveConnectionResult.Key && c.IsValid);
                Assert.Equal("source", dbConnection.Name);
                Assert.Equal("source server 2", dbConnection.Server);

                // create a new connection with same name and save it, this should fail.
                var connection = new DexihConnection()
                {
                    Name   = "source",
                    Server = "source server 3",
                    ConnectionClassName    = "class",
                    ConnectionAssemblyName = "assembly"
                };

                Assert.Throws <AggregateException>(() => database.SaveConnection(dbConnection.HubKey, connection, CancellationToken.None).Result);

                // delete the connection.
                var deleteReturn = await database.DeleteConnections(dbConnection.HubKey, new[] { dbConnection.Key }, CancellationToken.None);

                Assert.NotNull(deleteReturn);

                // check the connection is deleted
                var dbConnection2 = await database.DbContext.DexihConnections.SingleOrDefaultAsync(c => c.Key == dbConnection.Key && c.IsValid);

                Assert.Null(dbConnection2);

                // create a new connection with the same name as the deleted one.  save should succeed
                saveConnectionResult = await database.SaveConnection(dbConnection.HubKey, connection, CancellationToken.None);

                Assert.NotNull(saveConnectionResult);
            }
        }
Beispiel #2
0
        public async Task <RepositoryManager> CreateRepositoryWithConnections()
        {
            var database = await CreateRepositoryWithHub();

            var hub = await database.DbContext.DexihHubs.SingleAsync(c => c.Name == "test" && c.IsValid);

            var connection = new DexihConnection()
            {
                Name                   = "source",
                Purpose                = EConnectionPurpose.Source,
                Server                 = "source server",
                ConnectionClassName    = "test",
                ConnectionAssemblyName = "asembly",
                HubKey                 = hub.HubKey
            };

            var saveConnectionResult = await database.SaveConnection(hub.HubKey, connection, CancellationToken.None);

            connection = new DexihConnection()
            {
                Name                   = "managed",
                Purpose                = EConnectionPurpose.Managed,
                Server                 = "managed server",
                ConnectionClassName    = "test",
                ConnectionAssemblyName = "asembly",
                HubKey                 = hub.HubKey
            };

            saveConnectionResult = await database.SaveConnection(hub.HubKey, connection, CancellationToken.None);

            var dbSourceConnection = database.DbContext.DexihConnections.Single(c => c.Purpose == EConnectionPurpose.Source && c.IsValid);

            Assert.Equal("source", dbSourceConnection.Name);
            Assert.Equal("source server", dbSourceConnection.Server);

            var dbManagedConnection = database.DbContext.DexihConnections.Single(c => c.Purpose == EConnectionPurpose.Managed && c.IsValid);

            Assert.Equal("managed", dbManagedConnection.Name);
            Assert.Equal("managed server", dbManagedConnection.Server);

            return(database);
        }
Beispiel #3
0
        public async Task Save_Connection_and_Tables()
        {
            var hub = await CreateHub();

            // create initial connection
            var connection = new DexihConnection()
            {
                Name                   = "connection",
                Description            = "description",
                ConnectionAssemblyName = "assembly",
                Server                 = "server",
                Password               = "******",
            };
            await _repositoryManager.SaveConnection(hub.HubKey, connection, CancellationToken.None);

            Assert.True(connection.Key > 0);

            // add table to the connection
            var table = new DexihTable()
            {
                Name              = "table",
                Description       = "description",
                ConnectionKey     = connection.Key,
                DexihTableColumns = new List <DexihTableColumn>()
                {
                    new DexihTableColumn()
                    {
                        Name = "column1", DataType = ETypeCode.Int32, DeltaType = EDeltaType.TrackingField
                    },
                    new DexihTableColumn()
                    {
                        Name         = "column2", DataType = ETypeCode.Node, DeltaType = EDeltaType.TrackingField,
                        ChildColumns = new List <DexihTableColumn> ()
                        {
                            new DexihTableColumn()
                            {
                                Name = "childColumn1", DataType = ETypeCode.Int32, DeltaType = EDeltaType.TrackingField
                            },
                            new DexihTableColumn()
                            {
                                Name         = "childColumn2", DataType = ETypeCode.Node, DeltaType = EDeltaType.TrackingField,
                                ChildColumns = new List <DexihTableColumn> ()
                                {
                                    new DexihTableColumn()
                                    {
                                        Name = "grandChildColumn1", DataType = ETypeCode.Int32, DeltaType = EDeltaType.TrackingField
                                    },
                                    new DexihTableColumn()
                                    {
                                        Name = "grandChildColumn2", DataType = ETypeCode.Int32, DeltaType = EDeltaType.TrackingField
                                    },
                                }
                            },
                        }
                    },
                }
            };

            var savedTable = await _repositoryManager.SaveTable(hub.HubKey, table, true, false, CancellationToken.None);

            Assert.True(savedTable.Key > 0);

            // retrieve the connection and the table
            var retrievedConnection = await _repositoryManager.GetConnection(hub.HubKey, connection.Key, true, CancellationToken.None);

            Assert.Equal(connection.Key, retrievedConnection.Key);
            Assert.Equal(connection.ConnectionAssemblyName, retrievedConnection.ConnectionAssemblyName);
            Assert.Equal(connection.Server, retrievedConnection.Server);
            Assert.Equal(connection, retrievedConnection);


            var retrievedTable = await _repositoryManager.GetTable(hub.HubKey, savedTable.Key, true, CancellationToken.None);

            retrievedTable = retrievedTable.CloneProperties <DexihTable>(); //clone the table to avoid conflicts with MemoryDatabase.
            var columns = retrievedTable.DexihTableColumns.ToArray();

            Assert.Equal(table.Name, retrievedTable.Name);
            Assert.Equal(table.Description, retrievedTable.Description);
            Assert.Equal(2, table.DexihTableColumns.Count);
            Assert.Equal("column1", columns[0].Name);
            Assert.Equal("column2", columns[1].Name);

            var childColumns = columns[1].ChildColumns.ToArray();

            Assert.Equal(2, childColumns.Length);
            Assert.Equal(2, childColumns[1].ChildColumns.Count);

            // update the table name
            retrievedTable.Name = "table updated";
            // update a column
            columns[0].Name = "column1 updated";
            // delete a column
            retrievedTable.DexihTableColumns.Remove(columns[1]);
            // add a column
            retrievedTable.DexihTableColumns.Add(new DexihTableColumn()
            {
                Name = "column3", DataType = ETypeCode.Int32, DeltaType = EDeltaType.TrackingField
            });

            var savedTable2 = await _repositoryManager.SaveTable(hub.HubKey, retrievedTable, true, false, CancellationToken.None);

            var columns2        = savedTable2.DexihTableColumns.Where(c => c.IsValid).ToArray();
            var retrievedTable2 = await _repositoryManager.GetTable(hub.HubKey, savedTable2.Key, true, CancellationToken.None);

            Assert.Equal(savedTable2.Name, retrievedTable2.Name);
            Assert.Equal(2, columns2.Length);
            Assert.Equal("column1 updated", columns2[0].Name);
            Assert.Equal("column3", columns2[1].Name);

            // delete the table
            await _repositoryManager.DeleteTables(hub.HubKey, new[] { savedTable.Key }, CancellationToken.None);

            // confirm table deleted
            await Assert.ThrowsAsync <RepositoryManagerException>(async() => await _repositoryManager.GetTable(hub.HubKey, savedTable.Key, true, CancellationToken.None));

            // retrieve the connection with tables, and confirm table not retrieved.
            retrievedConnection = await _repositoryManager.GetConnection(hub.HubKey, connection.Key, true, CancellationToken.None);

            Assert.Equal(0, hub.DexihTables.Count(c => c.IsValid));
        }