public void DsfActivityFactory_UnitTest_ResourceAndEnvironmentIDAssigned_Done()
        {
            var expectedResourceID    = Guid.NewGuid();
            var expectedEnvironmentID = Guid.NewGuid();

            var activity = new DsfActivity();

            var environment = new Mock <IEnvironmentModel>();

            environment.Setup(e => e.ID).Returns(expectedEnvironmentID);

            var model = new Mock <IContextualResourceModel>();

            model.Setup(m => m.ResourceType).Returns(ResourceType.Service);
            model.Setup(m => m.ID).Returns(expectedResourceID);
            model.Setup(m => m.Environment).Returns(environment.Object);
            model.Setup(m => m.WorkflowXaml).Returns(new StringBuilder("<root/>"));
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty);

            DsfActivityFactory.CreateDsfActivity(model.Object, activity, false, environmentRepository, false);

            var actualResourceID    = Guid.Parse(activity.ResourceID.Expression.ToString());
            var actualEnvironmentID = Guid.Parse(activity.EnvironmentID.Expression.ToString());

            Assert.AreEqual(expectedResourceID, actualResourceID, "DsfActivityFactory did not assign the resource ID.");
            Assert.AreEqual(expectedEnvironmentID, actualEnvironmentID, "DsfActivityFactory did not assign the environment ID.");
        }
        public void DsfActivityFactory_CreateDsfActivity_NullWorkflowXamlServerResourceTypeDbService_TypeIsDbService()
        {
            //------------Setup for test--------------------------
            var expectedResourceID    = Guid.NewGuid();
            var expectedEnvironmentID = Guid.NewGuid();

            var activity = new DsfActivity();

            var environment = new Mock <IEnvironmentModel>();

            environment.Setup(e => e.ID).Returns(expectedEnvironmentID);

            var model = new Mock <IContextualResourceModel>();

            model.Setup(m => m.ResourceType).Returns(ResourceType.Service);
            model.Setup(m => m.ID).Returns(expectedResourceID);
            model.Setup(m => m.Environment).Returns(environment.Object);
            model.Setup(m => m.ServerResourceType).Returns("DbService");
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty);

            //------------Execute Test---------------------------
            DsfActivityFactory.CreateDsfActivity(model.Object, activity, false, environmentRepository, false);

            //------------Assert Results-------------------------
            Assert.AreEqual("DbService", ((Literal <string>)(activity.Type.Expression)).Value);
        }
        public void DsfActivityFactory_CreateDsfActivity_WhenLocalEnviromentIsActiveAndActivityFromRemoteEnvironment_ExpectRemoteEnviromentID()
        {
            //------------Setup for test--------------------------
            var expectedResourceID    = Guid.NewGuid();
            var expectedEnvironmentID = Guid.NewGuid();

            var activity = new DsfActivity();

            var environment = new Mock <IEnvironmentModel>();

            environment.Setup(e => e.ID).Returns(expectedEnvironmentID);

            var model = new Mock <IContextualResourceModel>();

            model.Setup(m => m.ResourceType).Returns(ResourceType.Service);
            model.Setup(m => m.ID).Returns(expectedResourceID);
            model.Setup(m => m.Environment).Returns(environment.Object);
            model.Setup(m => m.ServerResourceType).Returns("Workflow");
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment

            //------------Execute Test---------------------------
            DsfActivityFactory.CreateDsfActivity(model.Object, activity, false, environmentRepository, true);

            //------------Assert Results-------------------------
            StringAssert.Contains(((Literal <string>)(activity.Type.Expression)).Value, "Workflow");
            Assert.AreEqual(expectedEnvironmentID.ToString(), activity.EnvironmentID.Expression.ToString());
        }
Exemple #4
0
        public void AddItem_Given_MergeToolModel_VerifyCalls()
        {
            //------------Setup for test--------------------------
            var serverRepo = new Mock <IServerRepository>();

            CustomContainer.Register(serverRepo.Object);
            var repo = new Mock <IResourceRepository>();

            repo.Setup(repository => repository.SaveToServer(It.IsAny <IResourceModel>(), It.IsAny <string>())).Verifiable();
            var env = EnviromentRepositoryTest.CreateMockEnvironment();

            env.Setup(e => e.ResourceRepository).Returns(repo.Object);

            var crm = new Mock <IContextualResourceModel>();

            crm.Setup(r => r.Environment).Returns(env.Object);
            crm.Setup(r => r.ResourceName).Returns("Test");
            crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));

            var wh = new Mock <IWorkflowHelper>();

            var properties            = new Dictionary <string, Mock <ModelProperty> >();
            var propertyCollection    = new Mock <ModelPropertyCollection>();
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment
            var testAct = DsfActivityFactory.CreateDsfActivity(crm.Object, new DsfActivity(), true, environmentRepository, true);
            var actId   = Guid.NewGuid();

            testAct.UniqueID = actId.ToString();

            var eventAggregator = new Mock <IEventAggregator>();

            eventAggregator.Setup(aggregator => aggregator.Publish(It.IsAny <UpdateResourceMessage>())).Verifiable();
            eventAggregator.Setup(aggregator => aggregator.Publish(It.IsAny <AddWorkSurfaceMessage>())).Verifiable();
            var _moq             = new Mock <WorkflowDesigner>();
            var modelService     = new Mock <ModelService>();
            var viewStateService = new Mock <ViewStateService>();
            var chart            = new Flowchart();

            chart.Nodes.Add(testAct.GetFlowNode());
            var flowChart = ModelItemUtils.CreateModelItem(chart);

            modelService.Setup(p => p.Root).Returns(flowChart).Verifiable();
            modelService.Setup(p => p.Find(flowChart, typeof(Flowchart))).Returns(() => new List <ModelItem>()
            {
                flowChart
            }).Verifiable();
            var dHelper = new Mock <IWorkflowDesignerWrapper>();

            dHelper.Setup(p => p.GetService <ModelService>(It.IsAny <WorkflowDesigner>())).Returns(modelService.Object).Verifiable();
            dHelper.Setup(p => p.GetService <ViewStateService>(It.IsAny <WorkflowDesigner>())).Returns(viewStateService.Object);
            var wd  = new MergePreviewWorkflowDesignerViewModelMock(dHelper.Object, crm.Object, wh.Object, eventAggregator.Object, _moq.Object);
            var obj = new Mock <IToolConflictItem>();

            obj.Setup(o => o.UniqueId).Returns(actId);
            wd.AddItem(obj.Object);
            dHelper.VerifyAll();
            modelService.VerifyAll();
            viewStateService.Verify(p => p.RemoveViewState(It.IsAny <ModelItem>(), It.IsAny <string>()));
            viewStateService.Verify(p => p.StoreViewState(It.IsAny <ModelItem>(), It.IsAny <string>(), It.IsAny <Point>()));
        }
Exemple #5
0
        public bool SetModelItemForServiceTypes(IDataObject dataObject)
        {
            if (dataObject != null && (dataObject.GetDataPresent(GlobalConstants.ExplorerItemModelFormat) || dataObject.GetDataPresent(GlobalConstants.UpgradedExplorerItemModelFormat)))
            {
                var  explorerItemModel = dataObject.GetData(GlobalConstants.UpgradedExplorerItemModelFormat);
                Guid envId             = new Guid();
                Guid resourceId        = new Guid();

                if (explorerItemModel == null)
                {
                    return(false);
                }
                IExplorerItemViewModel itemModel = explorerItemModel as IExplorerItemViewModel;
                if (itemModel != null)
                {
                    if (itemModel.Server != null)
                    {
                        envId = itemModel.Server.EnvironmentID;
                    }
                    resourceId = itemModel.ResourceId;
                }

                try
                {
                    IServer server   = ServerRepository.Instance.FindSingle(c => c.EnvironmentID == envId);
                    var     resource = server?.ResourceRepository.LoadContextualResourceModel(resourceId);

                    if (resource != null)
                    {
                        DsfActivity d = DsfActivityFactory.CreateDsfActivity(resource, null, true, ServerRepository.Instance, true);
                        d.ServiceName = d.DisplayName = d.ToolboxFriendlyName = resource.Category;
                        if (Application.Current != null && Application.Current.Dispatcher.CheckAccess() && Application.Current.MainWindow != null)
                        {
                            dynamic mvm = Application.Current.MainWindow.DataContext;
                            if (mvm != null && mvm.ActiveItem != null)
                            {
                                WorkflowDesignerUtils.CheckIfRemoteWorkflowAndSetProperties(d, resource, mvm.ActiveItem.Environment);
                            }
                        }

                        ModelItem modelItem = ModelItemUtils.CreateModelItem(d);
                        if (modelItem != null)
                        {
                            dynamic             mi = ModelItem;
                            ModelItemCollection activitiesCollection = mi.Activities;
                            activitiesCollection.Insert(activitiesCollection.Count, d);
                            return(true);
                        }
                    }
                }
                catch (RuntimeBinderException e)
                {
                    Dev2Logger.Error(e);
                }
            }
            return(false);
        }
        public void DsfActivityFactory_UnitTest_ServiceActivityAndNullSourceMethod_DoesNotThrowException()
        {
            var activity = new DsfServiceActivity();
            Mock <IContextualResourceModel> mockRes = Dev2MockFactory.SetupResourceModelMock(ResourceType.Service);

            mockRes.Setup(r => r.WorkflowXaml).Returns(new StringBuilder(StringResources.xmlNullSourceMethodServiceDef));
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty);

            DsfActivityFactory.CreateDsfActivity(mockRes.Object, activity, true, environmentRepository, false);

            //If no exception - pass
            Assert.IsTrue(true);
        }
Exemple #7
0
        public bool SetModelItemForServiceTypes(IDataObject dataObject)
        {
            if (dataObject != null && dataObject.GetDataPresent(GlobalConstants.ExplorerItemModelFormat))
            {
                var explorerItemModel = dataObject.GetData(GlobalConstants.ExplorerItemModelFormat);
                try
                {
                    ExplorerItemModel itemModel = explorerItemModel as ExplorerItemModel;
                    if (itemModel != null)
                    {
                        IEnvironmentModel environmentModel = EnvironmentRepository.Instance.FindSingle(c => c.ID == itemModel.EnvironmentId);
                        if (environmentModel != null)
                        {
                            var resource = environmentModel.ResourceRepository.FindSingle(c => c.ID == itemModel.ResourceId) as IContextualResourceModel;

                            if (resource != null)
                            {
                                DsfActivity d = DsfActivityFactory.CreateDsfActivity(resource, null, true, EnvironmentRepository.Instance, true);
                                d.ServiceName = d.DisplayName = d.ToolboxFriendlyName = resource.Category;
                                d.IconPath    = resource.IconPath;
                                if (Application.Current != null && Application.Current.Dispatcher.CheckAccess() && Application.Current.MainWindow != null)
                                {
                                    dynamic mvm = Application.Current.MainWindow.DataContext;
                                    if (mvm != null && mvm.ActiveItem != null)
                                    {
                                        WorkflowDesignerUtils.CheckIfRemoteWorkflowAndSetProperties(d, resource, mvm.ActiveItem.Environment);
                                    }
                                }

                                ModelItem modelItem = ModelItemUtils.CreateModelItem(d);
                                if (modelItem != null)
                                {
                                    dynamic             mi = ModelItem;
                                    ModelItemCollection activitiesCollection = mi.Activities;
                                    activitiesCollection.Insert(activitiesCollection.Count, d);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                catch (RuntimeBinderException e)
                {
                    Dev2Logger.Log.Error(e);
                }
            }
            return(false);
        }