public void ToStringEmptyObjectExpected()
 {
     var testDbSource = new DbSource();
     string actualSerializedDbSource = testDbSource.ToString();
     string expected = JsonConvert.SerializeObject(testDbSource);
     Assert.AreEqual(expected, actualSerializedDbSource);
 }
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCached_CachedResults()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            TestDatabaseBroker broker = new TestDatabaseBroker();

            DbSource source = new DbSource();

            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
// ReSharper disable UseObjectOrCollectionInitializer
            var methodList = new ServiceMethodList();
// ReSharper restore UseObjectOrCollectionInitializer
            methodList.Add(new ServiceMethod("bob", "bob src", null, null, null,""));

            TestDatabaseBroker.TheCache.TryAdd(source.ConnectionString, methodList);
            //------------Execute Test---------------------------

            var result = broker.GetServiceMethods(source);

            // set back to empty ;)
            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
            //------------Assert Results-------------------------

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("bob", result[0].Name);
        }
 public void DbSource_ConnectionString_NotNamedInstance_ShouldUsePortNumber()
 {
     //------------Setup for test--------------------------
     var dbSource = new DbSource
     {
         Server = "myserver", 
         ServerType = enSourceType.SqlDatabase, 
         AuthenticationType = AuthenticationType.Windows, 
         DatabaseName = "testdb",
         Port=1433
     };
     //------------Execute Test---------------------------
     var connectionString = dbSource.ConnectionString;
     //------------Assert Results-------------------------
     StringAssert.Contains(connectionString,",1433");
 }
        // ReSharper disable InconsistentNaming

        public static DbSource CreateDev2TestingDbSource(AuthenticationType authenticationType = AuthenticationType.User)
        {
            var dbSource = new DbSource
            {
                ResourceID = Guid.NewGuid(),
                ResourceName = "Dev2TestingDB",
                ResourcePath = "Test",
                DatabaseName = "Dev2TestingDB",
                Server = "RSAKLFSVRGENDEV",
                AuthenticationType = authenticationType,
                ServerType = enSourceType.SqlDatabase,
                ReloadActions = true,
                UserID = authenticationType == AuthenticationType.User ? "testUser" : null,
                Password = authenticationType == AuthenticationType.User ? "test123" : null
            };
            return dbSource;
        }
 public void DbSource_ConnectionString_NamedInstanceDefaultPort_ShouldNotUsePort()
 {
     //------------Setup for test--------------------------
     var dbSource = new DbSource
     {
         Server = "myserver\\instance", 
         ServerType = enSourceType.SqlDatabase, 
         AuthenticationType = AuthenticationType.Windows, 
         DatabaseName = "testdb",
         Port=1433
     };
     //------------Execute Test---------------------------
     var connectionString = dbSource.ConnectionString;
     //------------Assert Results-------------------------
     var contains = connectionString.Contains(",1433");
     Assert.IsFalse(contains);
 }
Пример #6
0
 // POST: Service/dbSources/Get
 public DbSource Get(string resourceId, Guid workspaceId, Guid dataListId)
 {
     var result = new DbSource { ResourceID = Guid.Empty, ResourceType = ResourceType.DbSource, AuthenticationType = AuthenticationType.Windows };
     try
     {
         var xmlStr = ResourceCatalog.Instance.GetResourceContents(workspaceId, Guid.Parse(resourceId)).ToString();
         if(!string.IsNullOrEmpty(xmlStr))
         {
             var xml = XElement.Parse(xmlStr);
             result = new DbSource(xml);
         }
     }
     catch(Exception ex)
     {
         RaiseError(ex);
     }
     return result;
 }
 static DbSource CreateDbSource()
 {
     var resourceID = Guid.NewGuid();
     var dbSource = new DbSource { ResourcePath = "SQL Tests\\" + resourceID, ResourceName = resourceID.ToString(), ResourceID = resourceID };
     ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource);
     return dbSource;
 }
        private void SetupArguments(string currentDL, string testData, ISqlBulkInserter sqlBulkInserter, IList<DataColumnMapping> inputMappings, string resultString, DbSource dbSource = null, string destinationTableName = null, PopulateOptions populateOptions = PopulateOptions.IgnoreBlankRows, bool keepIdentity = false)
        {
            var ignoreBlankRows = populateOptions == PopulateOptions.IgnoreBlankRows;
            if(dbSource == null)
            {
                dbSource = CreateDbSource();
            }
            if(destinationTableName == null)
            {
                destinationTableName = "SomeTestTable";
            }
            TestStartNode = new FlowStep
            {
                Action = new DsfSqlBulkInsertActivity
                {
                    Database = dbSource,
                    TableName = destinationTableName,
                    InputMappings = inputMappings,
                    SqlBulkInserter = sqlBulkInserter,
                    Result = resultString,
                    IgnoreBlankRows = ignoreBlankRows,
                    KeepIdentity = keepIdentity
                }
            };

            CurrentDl = testData;
            TestData = currentDL;
        }
Пример #9
0
 public DbService()
 {
     ResourceType = "DbService";
     Source       = new DbSource();
     Recordset    = new Recordset();
 }
Пример #10
0
 public DbService()
 {
     ResourceType = ResourceType.DbService;
     Source = new DbSource();
     Recordset = new Recordset();
 }
 DbSource CreateDev2TestingDbSource(bool emptyDBName=false)
 {
     var dbSource = new DbSource
     {
         ResourceID = Guid.NewGuid(),
         ResourceName = "Dev2TestingDB",
         ResourcePath = "Test",
         DatabaseName = emptyDBName?"": "Dev2TestingDB",
         Server = "RSAKLFSVRGENDEV",
         AuthenticationType = AuthenticationType.User,
         ServerType = enSourceType.SqlDatabase,
         ReloadActions = true,
         UserID = "testUser",
         Password = "******"
     };
     return dbSource;
 }
Пример #12
0
        private DbSource SetupDefaultDbSource()
        {
            var testDbSource = new DbSource
            {
                Server = "someServerIMadeUpToTest",
                Port = 420,
                AuthenticationType = AuthenticationType.Windows,
                UserID = @"Domain\User",
                Password = "******",
                DatabaseName = "someDatabaseNameIMadeUpToTest",
                ResourceID = Guid.NewGuid(),
                ResourceName = "TestResourceIMadeUp",
                ResourcePath = @"host\Server",
                ResourceType = ResourceType.DbSource
            };

            return testDbSource;
        }
Пример #13
0
        public void ToXmlEmptyObjectExpectedXElementContainingNoInformationRegardingSource()
        {
            var testDbSource = new DbSource();
            XElement expectedXml = testDbSource.ToXml();

            IEnumerable<XAttribute> attrib = expectedXml.Attributes();
            IEnumerator<XAttribute> attribEnum = attrib.GetEnumerator();
            while(attribEnum.MoveNext())
            {
                if(attribEnum.Current.Name == "Name")
                {
                    Assert.AreEqual(string.Empty, attribEnum.Current.Value);
                    break;
                }
            }
        }
Пример #14
0
 public DbService()
 {
     ResourceType = Common.Interfaces.Data.ResourceType.DbService;
     Source       = new DbSource();
     Recordset    = new Recordset();
 }
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCachedNoRefreshRequested_FreshResults()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            TestDatabaseBroker broker = new TestDatabaseBroker();

            DbSource source = new DbSource { ReloadActions = true };

            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
            var methodList = new ServiceMethodList { new ServiceMethod("bob", "bob src", null, null, null, null) };

            TestDatabaseBroker.TheCache.TryAdd(source.ConnectionString, methodList);
            //------------Execute Test---------------------------

            var result = broker.GetServiceMethods(source);

            // set back to empty ;)
            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
            //------------Assert Results-------------------------

            Assert.AreEqual(0, result.Count);
        }
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetDatabases_InvokesDbServerFetchDatabases_Done()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var dbSource = new DbSource();

            var dbServer = new Mock<TestDbServer>();
            dbServer.Setup(s => s.Connect(It.IsAny<string>())).Verifiable();
            dbServer.Setup(s => s.FetchDatabases()).Verifiable();

            var broker = new TestDatabaseBroker(dbServer.Object);

            //------------Execute Test---------------------------
            broker.GetDatabases(dbSource);

            //------------Assert Results-------------------------
            dbServer.Verify(s => s.Connect(It.IsAny<string>()));
            dbServer.Verify(s => s.FetchDatabases());
        }
Пример #17
0
     public virtual ServiceMethodList FetchMethods(DbSource dbSource)
     {
         switch(dbSource.ServerType)
         {
                 case enSourceType.MySqlDatabase:
             {
                 var broker = new  MySqlDatabaseBroker();
                 return broker.GetServiceMethods(dbSource);
             }
             default:
             {
                         var broker = CreateDatabaseBroker();
                     return broker.GetServiceMethods(dbSource);
             }
         }
 
     }
Пример #18
0
        protected virtual DatabaseValidationResult DoDatabaseValidation(DbSource dbSourceDetails)
        {
            var result = new DatabaseValidationResult();

            switch (dbSourceDetails.ServerType)
            {
                case enSourceType.SqlDatabase:
                    var broker = CreateDatabaseBroker(dbSourceDetails.ServerType);
                    result.DatabaseList = broker.GetDatabases(dbSourceDetails);
                    break;
                case enSourceType.MySqlDatabase:
                    var mybroker = CreateMySqlDatabaseBroker(dbSourceDetails.ServerType);
                    result.DatabaseList = mybroker.GetDatabases(dbSourceDetails);
                    break;
                default:
                    result.IsValid = false;
                    break;
            }
            return result;
        }
Пример #19
0
        // ReSharper disable InconsistentNaming
        public void DbService_ToXml_WhenRecordSetHasBlankFields_ExpectNotPartOfOutputDescription()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var dbService = new DbService();
            var dbSource = new DbSource { ResourceName = "Source" };
            var resourceId = Guid.NewGuid();
            dbSource.ResourceID = resourceId;
            dbService.Source = dbSource;
            var serviceMethod = new ServiceMethod { Name = "Method" };
            dbService.Method = serviceMethod;
            var recordset = new Recordset { Name = "SomeRecSet" };
            var recordsetField = new RecordsetField { Alias = "SomeAlias", Name = "" };
            recordset.Fields.Add(recordsetField);
            dbService.Recordset = recordset;

            // ReSharper disable InconsistentNaming
            const string expected = @"<Service ID=""00000000-0000-0000-0000-000000000000"" Name="""" ResourceType=""DbService"" IsValid=""false"">
  <Actions>
    <Action Name=""SomeRecSet"" Type=""InvokeStoredProc"" SourceID=""{0}"" SourceName=""Source"" ExecuteAction="""" SourceMethod=""Method"">
      <Inputs />
      <Outputs />
      <OutputDescription><![CDATA[<z:anyType xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:d1p1=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph.Ouput"" i:type=""d1p1:OutputDescription"" xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""><d1p1:DataSourceShapes xmlns:d2p1=""http://schemas.microsoft.com/2003/10/Serialization/Arrays""><d2p1:anyType i:type=""d1p1:DataSourceShape""><d1p1:_x003C_Paths_x003E_k__BackingField /></d2p1:anyType></d1p1:DataSourceShapes><d1p1:Format>ShapedXML</d1p1:Format></z:anyType>]]></OutputDescription>
    </Action>
  </Actions>
  <AuthorRoles />
  <Comment />
  <Tags />
  <HelpLink />
  <UnitTestTargetWorkflowService />
  <BizRule />
  <WorkflowActivityDef />
  <XamlDefinition />
  <DataList />
  <TypeOf>InvokeStoredProc</TypeOf>
  <DisplayName></DisplayName>
  <Category></Category>
  <AuthorRoles></AuthorRoles>
  <ErrorMessages />
</Service>";
            // ReSharper restore InconsistentNaming

            //------------Execute Test---------------------------
            var xElement = dbService.ToXml();
            //------------Assert Results-------------------------
            Assert.AreEqual(string.Format(expected, resourceId), xElement.ToString());
        }
Пример #20
0
 protected override DatabaseValidationResult DoDatabaseValidation(DbSource dbSourceDetails)
 {
     //PBI 8720
     DatabaseValidationHitCount++;
     return new DatabaseValidationResult { IsValid = true };
 }
Пример #21
0
 public DbService()
 {
     ResourceType = Common.Interfaces.Data.ResourceType.DbService;
     Source = new DbSource();
     Recordset = new Recordset();
 }