Exemplo n.º 1
0
        public void WorkflowDesignerViewModel_HandleUpdateResourceMessage_WhenMessageHasErrors_ResourceModelShouldHaveErrors()
        {
            //------------Setup for test--------------------------
            var workflow = new ActivityBuilder
            {
                Implementation = new Flowchart
                {
                    StartNode = CreateFlowNode(Guid.NewGuid(), "CanSaveTest", true, typeof(TestActivity))
                }
            };

            var resourceRep = new Mock<IResourceRepository>();
            resourceRep.Setup(r => r.All()).Returns(new List<IResourceModel>());
            resourceRep.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage());
            resourceRep.Setup(repository => repository.Save(It.IsAny<IResourceModel>())).Verifiable();
            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(m => m.Environment.ResourceRepository).Returns(resourceRep.Object);
            resourceModel.Setup(model => model.IsNewWorkflow).Returns(false);
            resourceModel.Setup(m => m.ResourceName).Returns("Some resource name 11");
            var workflowHelper = new Mock<IWorkflowHelper>();
            workflowHelper.Setup(h => h.CreateWorkflow(It.IsAny<string>())).Returns(workflow);

            var viewModel = new WorkflowDesignerViewModelMock(resourceModel.Object, workflowHelper.Object);
            viewModel.InitializeDesigner(new Dictionary<Type, Type>());
            resourceModel.SetupGet(model => model.Errors);
            resourceModel.Setup(model => model.Errors).Returns(new ObservableReadOnlyList<IErrorInfo>(new List<IErrorInfo> { new ErrorInfo() }));
            resourceModel.Setup(model => model.AddError(It.IsAny<IErrorInfo>())).Verifiable();
            var updateResourceMessage = new UpdateResourceMessage(resourceModel.Object);

            //------------Execute Test---------------------------
            viewModel.Handle(updateResourceMessage);
            //------------Assert Results-------------------------
            resourceModel.Verify(model => model.AddError(It.IsAny<IErrorInfo>()), Times.Once());
        }
Exemplo n.º 2
0
        public void WorkflowDesignerViewModel_HandleSaveUnsavedWorkflow_MessageWithArgs_Saves()
        {
            //------------Setup for test--------------------------
            #region Setup view model constructor parameters

            var repo = new Mock<IResourceRepository>();
            repo.Setup(repository => repository.SaveToServer(It.IsAny<IResourceModel>())).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>();

            #endregion

            #region setup Mock ModelItem

            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 prop = new Mock<ModelProperty>();
            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Action", prop);

            propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object);

            var source = new Mock<ModelItem>();
            source.Setup(s => s.Properties).Returns(propertyCollection.Object);
            source.Setup(s => s.ItemType).Returns(typeof(FlowSwitch<string>));

            #endregion

            #region setup mock to change properties

            //mock item adding - this is obsolote functionality but not refactored due to overhead
            var args = new Mock<ModelChangedEventArgs>();
            #pragma warning disable 618
            args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object });
            #pragma warning restore 618

            #endregion

            #region setup mock ModelChangedEventArgs

            var eventArgs = new Mock<ModelChangedEventArgs>();
            #pragma warning disable 618
            eventArgs.Setup(c => c.ItemsAdded).Returns(new List<ModelItem> { source.Object });
            #pragma warning restore 618

            #endregion

            #region setup event aggregator

            var eventAggregator = new Mock<IEventAggregator>();
            eventAggregator.Setup(aggregator => aggregator.Publish(It.IsAny<UpdateResourceMessage>())).Verifiable();
            eventAggregator.Setup(aggregator => aggregator.Publish(It.IsAny<RemoveResourceAndCloseTabMessage>())).Verifiable();
            eventAggregator.Setup(aggregator => aggregator.Publish(It.IsAny<AddWorkSurfaceMessage>())).Verifiable();

            #endregion

            var wd = new WorkflowDesignerViewModelMock(crm.Object, wh.Object, eventAggregator.Object);

            var unsavedResourceModel = new Mock<IContextualResourceModel>();
            unsavedResourceModel.Setup(model => model.ResourceName).Returns("Unsaved 1");
            unsavedResourceModel.Setup(model => model.WorkflowXaml).Returns(new StringBuilder("workflow xaml"));
            unsavedResourceModel.Setup(r => r.Environment).Returns(env.Object);
            var saveUnsavedWorkflowMessage = new SaveUnsavedWorkflowMessage(unsavedResourceModel.Object, "new name", "new category", false);
            //------------Execute Test---------------------------
            wd.Handle(saveUnsavedWorkflowMessage);
            //------------Assert Results-------------------------
            eventAggregator.Verify(aggregator => aggregator.Publish(It.IsAny<UpdateResourceMessage>()), Times.Once());
            eventAggregator.Verify(aggregator => aggregator.Publish(It.IsAny<RemoveResourceAndCloseTabMessage>()), Times.Once());
            eventAggregator.Verify(aggregator => aggregator.Publish(It.IsAny<AddWorkSurfaceMessage>()), Times.Never());
            repo.Verify(repository => repository.SaveToServer(It.IsAny<IResourceModel>()), Times.Once());
            repo.Verify(repository => repository.Save(It.IsAny<IResourceModel>()), Times.Once());
            repo.Verify(repository => repository.DeleteResource(It.IsAny<IResourceModel>()), Times.Once());
        }