public void GetDatabaseColumnsForTable_UnitTest_ExecuteWithNullValues_ExpectedInvalidDataContractException()
        {
            var esb    = new GetDatabaseColumnsForTable();
            var actual = esb.Execute(null, null);

            Assert.AreEqual(string.Empty, actual);
        }
Beispiel #2
0
        public void GetDatabaseColumnsForTable_Execute_ValidDatabaseSource_WithSchema_OnlyReturnsForThatSchema()
        {
            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();

            ResourceCatalog.Instance.ResourceSaved = resource => { };
            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource, "");
            var someJsonData = JsonConvert.SerializeObject(dbSource, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
            });
            var esb           = new GetDatabaseColumnsForTable();
            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) }, { "TableName", new StringBuilder("City") }, { "Schema", new StringBuilder("Warewolf") }
            }, mockWorkspace.Object);
            //------------Assert Results-------------------------
            var value = actual.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(value));
            var result = JsonConvert.DeserializeObject <DbColumnList>(actual.ToString(), new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
            });

            Assert.IsFalse(result.HasErrors, $"error executing sql query: {result.Errors}");

            Assert.AreEqual(4, result.Items.Count);

            // Check Columns Returned ;)
            Assert.IsFalse(result.Items[0].IsNullable);
            Assert.IsTrue(result.Items[0].IsAutoIncrement);
            StringAssert.Contains(result.Items[0].ColumnName, "CityID");
            StringAssert.Contains(result.Items[0].SqlDataType.ToString(), "Int");

            Assert.IsFalse(result.Items[1].IsNullable);
            Assert.IsFalse(result.Items[1].IsAutoIncrement);
            StringAssert.Contains(result.Items[1].ColumnName, "Description");
            StringAssert.Contains(result.Items[1].SqlDataType.ToString(), "VarChar");

            Assert.IsFalse(result.Items[2].IsNullable);
            Assert.IsFalse(result.Items[2].IsAutoIncrement);
            StringAssert.Contains(result.Items[2].ColumnName, "CountryID");
            StringAssert.Contains(result.Items[2].SqlDataType.ToString(), "Int");

            Assert.IsTrue(result.Items[3].IsNullable);
            Assert.IsFalse(result.Items[3].IsAutoIncrement);
            StringAssert.Contains(result.Items[3].ColumnName, "TestCol");
            StringAssert.Contains(result.Items[3].SqlDataType.ToString(), "NChar");
        }
Beispiel #3
0
        public void GetDatabaseColumnsForTable_Execute_ValidDatabaseSource_WithSchema_OnlyReturnsForThatSchema()
        {
            //------------Setup for test--------------------------
            var dbSource = CreateDev2TestingDbSource();

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource);
            string someJsonData = JsonConvert.SerializeObject(dbSource, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            var esb           = new GetDatabaseColumnsForTable();
            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) }, { "TableName", new StringBuilder("City") }, { "Schema", new StringBuilder("Warewolf") }
            }, mockWorkspace.Object);
            //------------Assert Results-------------------------
            var value = actual.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(value));
            var result = JsonConvert.DeserializeObject <DbColumnList>(actual.ToString(), new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });

            Assert.AreEqual(4, result.Items.Count);

            // Check Columns Returned ;)
            Assert.IsFalse(result.Items[0].IsNullable);
            Assert.IsTrue(result.Items[0].IsAutoIncrement);
            StringAssert.Contains(result.Items[0].ColumnName, "CityID");
            StringAssert.Contains(result.Items[0].SqlDataType.ToString(), "Int");

            Assert.IsFalse(result.Items[1].IsNullable);
            Assert.IsFalse(result.Items[1].IsAutoIncrement);
            StringAssert.Contains(result.Items[1].ColumnName, "Description");
            StringAssert.Contains(result.Items[1].SqlDataType.ToString(), "VarChar");

            Assert.IsFalse(result.Items[2].IsNullable);
            Assert.IsFalse(result.Items[2].IsAutoIncrement);
            StringAssert.Contains(result.Items[2].ColumnName, "CountryID");
            StringAssert.Contains(result.Items[2].SqlDataType.ToString(), "Int");

            Assert.IsTrue(result.Items[3].IsNullable);
            Assert.IsFalse(result.Items[3].IsAutoIncrement);
            StringAssert.Contains(result.Items[3].ColumnName, "TestCol");
            StringAssert.Contains(result.Items[3].SqlDataType.ToString(), "NChar");
        }
        public void GetDatabaseColumnsForTable_UnitTest_ExecuteWithNoDatabaseInValues_ExpectedHasErrors()
        {
            var esb    = new GetDatabaseColumnsForTable();
            var actual = esb.Execute(new Dictionary <string, StringBuilder> {
                { "Database", null }
            }, null);

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

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("No database set.", result.Errors);
        }