Inheritance: AbstractResourceMessage
        public void EmailDesignerViewModel_Handles_UpdateResourceMessageResourceIdAreNotTheSame_EmailSourceIsNotUpdated()
        {
            //------------Setup for test--------------------------
            var emailSource = new EmailSource
            {
                ResourceID = Guid.NewGuid(),
                ResourceName = "Email1",
                UserName = "******",
                Password = "******"
            };

            var emailSources = CreateEmailSources(2);
            var modelItem = ModelItemUtils.CreateModelItem(new DsfSendEmailActivity
            {
                SelectedEmailSource = emailSource
            });

            var viewModel = CreateViewModel(new List<EmailSource> { emailSource }, modelItem);

            var updatedEmailSource = new EmailSource(emailSources[0].ToXml())
            {
                ResourceID = Guid.NewGuid(),
                UserName = "******",
                Password = "******"
            };

            //var xaml = new StringBuilder
            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.WorkflowXaml).Returns(new StringBuilder(updatedEmailSource.ToXml().ToString()));

            var message = new UpdateResourceMessage(resourceModel.Object);

            //------------Execute Test---------------------------
            viewModel.Handle(message);

            //------------Assert Results-------------------------
            var selectedSource = viewModel.SelectedEmailSourceModelItemValue;
            Assert.AreNotEqual(updatedEmailSource.UserName, selectedSource.UserName);
            Assert.AreNotEqual(updatedEmailSource.Password, selectedSource.Password);
        }
        public void UpdateResourceMessage_WhenResourceExistsChangedCategory_Expects_CategoryChanged()
        {
            var eventAggregator = new EventAggregator();

            Mock<IContextualResourceModel> mockResourceModel = Dev2MockFactory.SetupResourceModelMock();
            mockResourceModel.Setup(resModel => resModel.WorkflowXaml).Returns(WorkflowXAMLForTest());

            var workflowDesigner = CreateWorkflowDesignerViewModel(eventAggregator, mockResourceModel.Object, null, false);
            //var designerAttributes = new Dictionary<Type, Type>();
            //workflowDesigner.InitializeDesigner(designerAttributes);

            mockResourceModel.Setup(r => r.Category).Returns("Testing");
            var updatemsg = new UpdateResourceMessage(mockResourceModel.Object);
            workflowDesigner.Handle(updatemsg);

            mockResourceModel.Setup(r => r.Category).Returns("Testing2");
            updatemsg = new UpdateResourceMessage(mockResourceModel.Object);
            workflowDesigner.Handle(updatemsg);

            Assert.AreEqual("Testing2", workflowDesigner.ResourceModel.Category);
            workflowDesigner.Dispose();
        }
        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());
        }
        public void NavigationViewModel_SetNodeOverwrite_SetToFalse_FalseReturned()
        {
            Init(false, true);
            var newResource = new Mock<IContextualResourceModel>();
            newResource.Setup(r => r.ResourceType)
                .Returns(ResourceType.WorkflowService);
            newResource.Setup(r => r.Category).Returns("Testing");
            newResource.Setup(r => r.ResourceName).Returns("Cake");
            newResource.Setup(r => r.Environment)
                .Returns(_mockEnvironmentModel.Object);

            var updatemsg = new UpdateResourceMessage(newResource.Object);
            _vm.Handle(updatemsg);

            Assert.IsFalse(_vm.SetNodeOverwrite(newResource.Object, false));
        }