Beispiel #1
0
        public async Task TestReceiveTablesAndColumns()
        {
            #region arrange
            var connectionString = GetSqlServerConnectionString();
            var rr = new ReceiverRelationalSqlServer();
            rr.ConnectionString = connectionString;
            using (var conn = new SqlConnection(connectionString))
            {
                await conn.OpenAsync();

                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = @"
IF OBJECT_ID('dbo.TestAndrei', 'U') IS NOT NULL
 DROP TABLE dbo.TestAndrei;";
                    await cmd.ExecuteNonQueryAsync();

                    cmd.CommandText = @"create table TestAndrei(
        ID int,
        FirstName varchar(64) not null
             )";
                    await cmd.ExecuteNonQueryAsync();
                }
            }
            #endregion
            #region act
            await rr.LoadData();

            #endregion
            #region assert
            Assert.AreEqual(1, rr.valuesRead?.Length);
            var server = rr.valuesRead[0] as IRowReceiveRelation;
            Assert.IsNotNull(server);
            Assert.IsTrue(server.Relations.ContainsKey("databases"));
            var dbs = server.Relations["databases"];
            Assert.IsTrue(dbs.Count > 0, "must contain at least 1 databases");
            int nrTables  = 0;
            int nrColumns = 0;
            foreach (var item in dbs)
            {
                var dbsTables = item.Relations["tables"];
                nrTables += dbsTables.Count;
                foreach (var table in dbsTables)
                {
                    var cols = table.Relations["columns"];
                    nrColumns += cols.Count;
                }
            }
            Assert.IsTrue(nrTables > 0, "must contain some tables");
            Assert.IsTrue(nrColumns > 0, "must contain some columns");
            #endregion
        }
        public async Task TestExportRelationalHTMLSqlServer()
        {
            #region arrange
            string folderName = AppContext.BaseDirectory;
            //CreateExportFilesSqlServer(Path.Combine(folderName,"Views"));
            var connectionString = GetSqlServerConnectionString();

            using (var conn = new SqlConnection(connectionString))
            {
                await conn.OpenAsync();

                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = @"
IF OBJECT_ID('dbo.TestAndrei', 'U') IS NOT NULL
 DROP TABLE dbo.TestAndrei;";
                    await cmd.ExecuteNonQueryAsync();

                    cmd.CommandText = @"create table TestAndrei(
        ID int,
        FirstName varchar(64) not null
             )";
                    await cmd.ExecuteNonQueryAsync();
                }
            }

            var rr = new ReceiverRelationalSqlServer();
            rr.ConnectionString = connectionString;
            string OutputFileName = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderName, "relationalSqlServer.html"));
            var    sender         = new Sender_HTMLRazor("Views/sqlserver.cshtml", OutputFileName);

            var senderViz = new Sender_HTMLRelationViz("Name", OutputFileName);
            var filter    = new FilterExcludeRelation("columns", "tables");
            var job       = new SimpleJobConditionalTransformers();
            job.Receivers.Add(0, rr);
            job.AddSender(sender);
            job.Add(filter);
            job.Add(filter, senderViz);
            #endregion
            #region act
            await job.Execute();

            #endregion
            #region assert
            Assert.IsTrue(File.Exists(OutputFileName), $"{OutputFileName} must exists");
            //Process.Start("explorer.exe", OutputFileName);
            var text = File.ReadAllText(OutputFileName);
            Assert.IsTrue(text.Contains("TestAndrei"), "must contain table testandrei");
            Assert.IsTrue(text.Contains("FirstName"), "must contain column FirstName ");

            #endregion
        }
Beispiel #3
0
        static string DocumentSqlServer()
        {
            var rr = new ReceiverRelationalSqlServer();

            rr.ConnectionString = "#file:SqlServerConnectionString#";
            string OutputFileName = "relationalSqlServer.html";
            var    sender         = new Sender_HTMLRazor("Views/sqlserver.cshtml", OutputFileName);

            sender.FileMode = FileMode.Create;
            var filter    = new FilterExcludeRelation(new string[] { "columns", "tables", "views" });
            var senderViz = new Sender_HTMLRelationViz("Name", OutputFileName);


            var si = new SimpleJobConditionalTransformers();

            si.Receivers.Add(0, rr);
            si.AddSender(sender);
            si.Add(filter);
            si.Add(filter, senderViz);
            return(si.SerializeMe());
        }