private int DropProcedure(string cleanProcName)
        {
            var dropProcedure = "IF ( OBJECT_ID('" + cleanProcName + "') IS NOT NULL ) DROP PROCEDURE [dbo].[" + cleanProcName + "]";
            var dropResult    = SqlHelper.RunSqlCommand(dropProcedure);

            return(dropResult);
        }
        public void Add_A_New_InputOnSqlProcedure_Expect_New_IS_InputAdded()
        {
            const string procName = "TestingAddingANewInput";

            Setup(procName);

            IDatabaseInputRegion databaseInputRegion = new DatabaseInputRegion(_modelItem, _dbActionRegion);

            Assert.AreEqual(1, databaseInputRegion.Inputs.Count);
            Assert.AreEqual("ProductId", databaseInputRegion.Inputs.Single().Name);
            Assert.AreEqual("[[ProductId]]", databaseInputRegion.Inputs.Single().Value);
            //testing here
            const string alterProcedure    = "ALTER procedure [dbo].[" + procName + "](@ProductId int,@ProductId1 int,@ProductId2 int) as Begin select * from Country select * from City end";
            var          alterTableResults = SqlHelper.RunSqlCommand(alterProcedure);

            Assert.AreEqual(-1, alterTableResults);

            _dbActionRegion.RefreshActionsCommand.Execute(null);
            Assert.IsNotNull(_dbActionRegion.Actions, "No Actions were generated for source: " + _selectedSource);

            var procActionsToInputs = _dbActionRegion.Actions.Single(p => p.Name.EndsWith(procName));

            Assert.AreEqual("ProductId", procActionsToInputs.Inputs.ToList()[0].Name);
            Assert.AreEqual("[[ProductId]]", procActionsToInputs.Inputs.ToList()[0].Value);

            Assert.AreEqual("ProductId1", procActionsToInputs.Inputs.ToList()[1].Name);
            Assert.AreEqual("[[ProductId1]]", procActionsToInputs.Inputs.ToList()[1].Value);

            Assert.AreEqual("ProductId2", procActionsToInputs.Inputs.ToList()[2].Name);
            Assert.AreEqual("[[ProductId2]]", procActionsToInputs.Inputs.ToList()[2].Value);
        }
        public void Change_sql_source_verify_Empty_Inputs()
        {
            var newName       = Guid.NewGuid().ToString();
            var cleanProcName = newName.Replace("-", "").Replace(" ", "");

            try
            {
                var createProcedure = "CREATE procedure [dbo].[" + cleanProcName + "](@ProductId int) as Begin select * from Country select * from City end";
                var result          = SqlHelper.RunSqlCommand(createProcedure);
                Assert.AreEqual(-1, result);

                Setup(cleanProcName);

                var mockSource = new Mock <IDbSource>();

                IDatabaseInputRegion databaseInputRegion = new DatabaseInputRegion(_modelItem, _dbActionRegion);
                Assert.AreEqual(1, databaseInputRegion.Inputs.Count);
                Assert.AreEqual("ProductId", databaseInputRegion.Inputs.Single().Name);
                Assert.AreEqual("[[ProductId]]", databaseInputRegion.Inputs.Single().Value);
                //add testing here

                _source.SelectedSource = mockSource.Object;
                Assert.AreEqual(0, databaseInputRegion.Inputs.Count);
            }
            finally
            {
                var dropResult = DropProcedure(cleanProcName);
                Assert.AreEqual(-1, dropResult);
            }
        }
        int DropProcedure(string cleanProcName)
        {
            var dropProcedure = "IF ( OBJECT_ID('" + cleanProcName + "') IS NOT NULL ) DROP PROCEDURE [dbo].[" + cleanProcName + "]";
            var dropResult    = SqlHelper.RunSqlCommand(_containerOps.Container.IP,
                                                        _containerOps.Container.Port, dropProcedure);

            return(dropResult);
        }
예제 #5
0
        int DropProcedure(string cleanProcName)
        {
            var dropProcedure = "IF ( OBJECT_ID('" + cleanProcName + "') IS NOT NULL ) DROP PROCEDURE [dbo].[" + cleanProcName + "]";
            var dropResult    = SqlHelper.RunSqlCommand(Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP,
                                                        Depends.EnableDocker?_containerOps.Container.Port:"1433", dropProcedure);

            return(dropResult);
        }
        public void change_sql_source_verify_Empty_Inputs()
        {
            var newName         = Guid.NewGuid().ToString();
            var cleanProcName   = newName.Replace("-", "").Replace(" ", "");
            var createProcedure = "CREATE procedure [dbo].[" + cleanProcName + "](@ProductId int) as Begin select * from Country select * from City end";
            var result          = SqlHelper.RunSqlCommand(createProcedure);

            Assert.AreEqual(-1, result);
            var inputs = new List <IServiceInput>()
            {
                new ServiceInput("ProductId", "[[ProductId]]")
                {
                    ActionName = "dbo." + cleanProcName
                }
            };
            var sqlActivity = new DsfSqlServerDatabaseActivity()
            {
                Inputs        = inputs,
                ActionName    = "dbo." + cleanProcName,
                ProcedureName = "dbo." + cleanProcName,
                SourceId      = new Guid("b9184f70-64ea-4dc5-b23b-02fcd5f91082")
            };
            var modelItem        = ModelItemUtils.CreateModelItem(sqlActivity);
            var environmentModel = ServerRepository.Instance.Source;

            environmentModel.Connect();
            var environmentConnection = environmentModel.Connection;
            var controllerFactory     = new CommunicationControllerFactory();
            var _proxyLayer           = new StudioServerProxy(controllerFactory, environmentConnection);
            var mock           = new Mock <IShellViewModel>();
            var dbServiceModel = new ManageDbServiceModel(new StudioResourceUpdateManager(controllerFactory, environmentConnection)
                                                          , _proxyLayer.QueryManagerProxy
                                                          , mock.Object
                                                          , environmentModel);
            var source         = new DatabaseSourceRegion(dbServiceModel, modelItem, Common.Interfaces.Core.DynamicServices.enSourceType.SqlDatabase);
            var selectedSource = source.Sources.Single(a => a.Id == sqlActivity.SourceId);

            source.SelectedSource = selectedSource;
            var actionRegion = new DbActionRegion(dbServiceModel, modelItem, source, new SynchronousAsyncWorker());

            var mockSource = new Mock <IDbSource>();

            IDatabaseInputRegion databaseInputRegion = new DatabaseInputRegion(modelItem, actionRegion);

            Assert.AreEqual(1, databaseInputRegion.Inputs.Count);
            Assert.AreEqual("ProductId", databaseInputRegion.Inputs.Single().Name);
            Assert.AreEqual("[[ProductId]]", databaseInputRegion.Inputs.Single().Value);
            //add testing here

            source.SelectedSource = mockSource.Object;
            Assert.AreEqual(0, databaseInputRegion.Inputs.Count);
        }
        public void Add_A_New_InputOnSqlProcedure_Expect_New_IS_InputAdded()
        {
            var newName         = Guid.NewGuid().ToString();
            var cleanProcName   = newName.Replace("-", "").Replace(" ", "");
            var dropProcedure   = "USE [Dev2TestingDB]  DROP PROCEDURE [dbo].[" + cleanProcName + "]";
            var createProcedure = "CREATE procedure [dbo].[" + cleanProcName + "](@ProductId int) as Begin select * from Country select * from City end";
            var result          = SqlHelper.RunSqlCommand(createProcedure);

            Assert.AreEqual(-1, result);
            var inputs = new List <IServiceInput>()
            {
                new ServiceInput("ProductId", "[[ProductId]]")
                {
                    ActionName = "dbo." + cleanProcName
                }
            };
            var sqlActivity = new DsfSqlServerDatabaseActivity()
            {
                Inputs        = inputs,
                ActionName    = "dbo." + cleanProcName,
                ProcedureName = "dbo." + cleanProcName,
                SourceId      = new Guid("b9184f70-64ea-4dc5-b23b-02fcd5f91082")
            };
            var modelItem        = ModelItemUtils.CreateModelItem(sqlActivity);
            var environmentModel = ServerRepository.Instance.Source;

            environmentModel.Connect();
            var environmentConnection = environmentModel.Connection;
            var controllerFactory     = new CommunicationControllerFactory();
            var _proxyLayer           = new StudioServerProxy(controllerFactory, environmentConnection);
            var mock           = new Mock <IShellViewModel>();
            var dbServiceModel = new ManageDbServiceModel(new StudioResourceUpdateManager(controllerFactory, environmentConnection)
                                                          , _proxyLayer.QueryManagerProxy
                                                          , mock.Object
                                                          , environmentModel);
            var source         = new DatabaseSourceRegion(dbServiceModel, modelItem, Common.Interfaces.Core.DynamicServices.enSourceType.SqlDatabase);
            var selectedSource = source.Sources.Single(a => a.Id == sqlActivity.SourceId);

            source.SelectedSource = selectedSource;
            var actionRegion = new DbActionRegion(dbServiceModel, modelItem, source, new SynchronousAsyncWorker());


            var diffAction = actionRegion.Actions.First(p => p.Name != sqlActivity.ProcedureName);
            IDatabaseInputRegion databaseInputRegion = new DatabaseInputRegion(modelItem, actionRegion);

            Assert.AreEqual(1, databaseInputRegion.Inputs.Count);
            Assert.AreEqual("ProductId", databaseInputRegion.Inputs.Single().Name);
            Assert.AreEqual("[[ProductId]]", databaseInputRegion.Inputs.Single().Value);
            //add testing here
            var alterProcedure = "ALTER procedure [dbo].[" + cleanProcName + "](@ProductId int,@ProductId1 int,@ProductId2 int) as Begin select * from Country select * from City end";
            //actionRegion.SelectedAction = diffAction;//trigger action changes
            var alterTableResults = SqlHelper.RunSqlCommand(alterProcedure);

            actionRegion.RefreshActionsCommand.Execute(null);
            var underTest = actionRegion.Actions.Single(p => p.Name.EndsWith(cleanProcName));

            Assert.AreEqual(3, databaseInputRegion.Inputs.Count);
            Assert.AreEqual("ProductId", underTest.Inputs.ToList()[0].Name);
            Assert.AreEqual("ProductId1", underTest.Inputs.ToList()[1].Name);
            Assert.AreEqual("ProductId2", underTest.Inputs.ToList()[2].Name);

            Assert.AreEqual("ProductId", databaseInputRegion.Inputs.ToList()[0].Name);
            Assert.AreEqual("[[ProductId]]", databaseInputRegion.Inputs.ToList()[0].Value);

            Assert.AreEqual("ProductId1", databaseInputRegion.Inputs.ToList()[1].Name);
            Assert.AreEqual("[[ProductId1]]", databaseInputRegion.Inputs.ToList()[1].Value);

            Assert.AreEqual("ProductId2", databaseInputRegion.Inputs.ToList()[2].Name);
            Assert.AreEqual("[[ProductId2]]", databaseInputRegion.Inputs.ToList()[2].Value);
            Assert.AreEqual(-1, alterTableResults);
            var resultForDrop = SqlHelper.RunSqlCommand(dropProcedure);

            Assert.AreEqual(-1, resultForDrop);
        }