예제 #1
0
        public void GetDatabaseTables_UnitTest_ExecuteWithNullValues_ExpectedInvalidDataContractException()
        {
            var esb    = new GetDatabaseTables();
            var actual = esb.Execute(null, null);

            Assert.AreEqual(string.Empty, actual);
        }
예제 #2
0
        public void GetDatabaseTables_Execute_InValidDatabaseName()
        {
            var parser = new Mock <IActivityParser>();

            parser.Setup(a => a.Parse(It.IsAny <DynamicActivity>())).Returns(new Mock <IDev2Activity>().Object);
            CustomContainer.Register(parser.Object);
            //------------Setup for test--------------------------
            var dbSource = CreateDev2TestingDbSource(true);

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource, "");
            var someJsonData  = JsonConvert.SerializeObject(dbSource);
            var esb           = new GetDatabaseTables();
            var mockWorkspace = new Mock <IWorkspace>();

            mockWorkspace.Setup(workspace => workspace.ID).Returns(Guid.Empty);
            //------------Execute Test---------------------------
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder(someJsonData) }
            }, mockWorkspace.Object);
            //------------Assert Results-------------------------
            var value = actual.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(value));
            var result = JsonConvert.DeserializeObject <DbTableList>(value);

            Assert.IsTrue(result.HasErrors);
            Assert.IsTrue(value.Contains("Invalid database sent"));
        }
        public void GetDatabaseTables_Execute_ValidDatabaseSource()
        {
            //------------Setup for test--------------------------
            var dbSource = CreateDev2TestingDbSource();

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource);
            string someJsonData  = JsonConvert.SerializeObject(dbSource);
            var    esb           = new GetDatabaseTables();
            var    mockWorkspace = new Mock <IWorkspace>();

            mockWorkspace.Setup(workspace => workspace.ID).Returns(Guid.Empty);
            //------------Execute Test---------------------------
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder(someJsonData) }
            }, mockWorkspace.Object);
            //------------Assert Results-------------------------
            var value = actual.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(value));
            var result = JsonConvert.DeserializeObject <DbTableList>(value);

            Assert.IsTrue(result.Items.Count > 2);
            var duplicateTables = result.Items.FindAll(table => table.TableName.Contains("[City]"));

            Assert.AreEqual(2, duplicateTables.Count);
            var dboCityTable      = duplicateTables.Find(table => table.Schema == "dbo");
            var warewolfCityTable = duplicateTables.Find(table => table.Schema == "Warewolf");

            Assert.IsNotNull(dboCityTable);
            Assert.AreEqual("dbo", dboCityTable.Schema);
            Assert.IsNotNull(warewolfCityTable);
            Assert.AreEqual("Warewolf", warewolfCityTable.Schema);
        }
예제 #4
0
        public void GetDatabaseTables_UnitTest_ExecuteWithBlankDatabase_ExpectHasErrors()
        {
            var esb    = new GetDatabaseTables();
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder() }
            }, null);

            Assert.IsNotNull(actual);
            var result = JsonConvert.DeserializeObject <DbTableList>(actual.ToString());

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("No database set.", result.Errors);
        }
예제 #5
0
        public void GetDatabaseTables_UnitTest_ExecuteWithDatabaseNotValidJson_ExpectedHasErrors()
        {
            var esb    = new GetDatabaseTables();
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder("Test") }
            }, null);

            Assert.IsNotNull(actual);
            var result = JsonConvert.DeserializeObject <DbTableList>(actual.ToString());

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Invalid JSON data for Database parameter. Exception: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.", result.Errors);
        }
예제 #6
0
        public void GetDatabaseTables_UnitTest_ExecuteWithNotDbSourceJson_ExpectedHasErrors()
        {
            const string someJsonData = "{Val:1}";
            var          esb          = new GetDatabaseTables();
            var          actual       = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder(someJsonData) }
            }, null);

            Assert.IsNotNull(actual);
            var result = JsonConvert.DeserializeObject <DbTableList>(actual.ToString());

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Invalid Database source", result.Errors);
        }
예제 #7
0
        public void GetDatabaseTables_Execute_ValidDatabaseSource()
        {
            var parser = new Mock <IActivityParser>();

            parser.Setup(a => a.Parse(It.IsAny <DynamicActivity>())).Returns(new Mock <IDev2Activity>().Object);
            CustomContainer.Register(parser.Object);
            //------------Setup for test--------------------------
            GetDatabaseColumnsForTableTests._containerOps = new Depends(Depends.ContainerType.MSSQL);
            var dbSource = CreateDev2TestingDbSource();

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource, "");
            var someJsonData  = JsonConvert.SerializeObject(dbSource);
            var esb           = new GetDatabaseTables();
            var mockWorkspace = new Mock <IWorkspace>();

            mockWorkspace.Setup(workspace => workspace.ID).Returns(Guid.Empty);
            //------------Execute Test---------------------------
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", new StringBuilder(someJsonData) }
            }, mockWorkspace.Object);
            //------------Assert Results-------------------------
            var value = actual.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(value));
            var result = JsonConvert.DeserializeObject <DbTableList>(value);

            Assert.IsTrue(result.Items.Count > 2, "Wrong tables in database: \"" + value + "\" expecting only 2 tables in the database.");
            var duplicateTables = result.Items.FindAll(table => table.TableName.Contains("[City]"));

            Assert.AreEqual(2, duplicateTables.Count);
            var dboCityTable      = duplicateTables.Find(table => table.Schema == "dbo");
            var warewolfCityTable = duplicateTables.Find(table => table.Schema == "Warewolf");

            Assert.IsNotNull(dboCityTable);
            Assert.AreEqual("dbo", dboCityTable.Schema);
            Assert.IsNotNull(warewolfCityTable);
            Assert.AreEqual("Warewolf", warewolfCityTable.Schema);
        }