public void StudioTestViewModel_GetView_ReturnsIView_NotNull() { //------------Setup for test-------------------------- var mockWorkSurfaceViewModel = new Mock <IWorkflowDesignerViewModel>(); var mockedConn = new Mock <IEnvironmentConnection>(); mockedConn.Setup(conn => conn.ServerEvents).Returns(new Mock <IEventPublisher>().Object); var mockEnvironmentModel = new Mock <IServer>(); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockedConn.Object); mockEnvironmentModel.Setup(e => e.Name).Returns("My Env"); var environmentModel = mockEnvironmentModel.Object; mockWorkSurfaceViewModel.Setup(model => model.Server).Returns(environmentModel); //------------Execute Test--------------------------- CustomContainer.Register(new Mock <IPopupController>().Object); var eventAggregator = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); resourceModel.Setup(model => model.IsWorkflowSaved).Returns(true); mockWorkSurfaceViewModel.Setup(model => model.ResourceModel).Returns(resourceModel.Object); var serviceTestViewModel = new Mock <IServiceTestViewModel>(); serviceTestViewModel.Setup(model => model.WorkflowDesignerViewModel).Returns(mockWorkSurfaceViewModel.Object); var vm = new StudioTestViewModel(eventAggregator.Object, serviceTestViewModel.Object, new Mock <IPopupController>().Object, new Mock <IView>().Object); Assert.IsNotNull(vm); Assert.IsNotNull(vm.DebugOutputViewModel); Assert.IsFalse(vm.HasVariables); Assert.IsTrue(vm.HasDebugOutput); Assert.IsNull(vm.DisplayName); Assert.AreEqual("ServiceTestsViewer", vm.ResourceType); Assert.IsNull(vm.HelpText); Assert.IsFalse(vm.IsDirty); var view = vm.GetView(); //------------Assert Results------------------------- Assert.IsNotNull(view); }
public void StudioTestViewModel_PropertyChanged_ViewModel_IsTrue() { //------------Setup for test-------------------------- var mockWorkSurfaceViewModel = new Mock <IWorkflowDesignerViewModel>(); var mockedConn = new Mock <IEnvironmentConnection>(); mockedConn.Setup(conn => conn.ServerEvents).Returns(new Mock <IEventPublisher>().Object); var mockEnvironmentModel = new Mock <IServer>(); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockedConn.Object); mockEnvironmentModel.Setup(e => e.Name).Returns("My Env"); var environmentModel = mockEnvironmentModel.Object; mockWorkSurfaceViewModel.Setup(model => model.Server).Returns(environmentModel); //------------Execute Test--------------------------- CustomContainer.Register(new Mock <IPopupController>().Object); var mockMainViewModel = new Mock <IShellViewModel>(); mockMainViewModel.Setup(model => model.HelpViewModel).Returns(new Mock <IHelpWindowViewModel>().Object); CustomContainer.Register(mockMainViewModel.Object); var eventAggregator = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); resourceModel.Setup(model => model.IsWorkflowSaved).Returns(true); mockWorkSurfaceViewModel.Setup(model => model.ResourceModel).Returns(resourceModel.Object); var serviceTestViewModel = new Mock <IServiceTestViewModel>(); serviceTestViewModel.Setup(model => model.WorkflowDesignerViewModel).Returns(mockWorkSurfaceViewModel.Object); var env = new Mock <IServer>(); var con = new Mock <IEnvironmentConnection>(); var debugTreeMock = new Mock <List <IDebugTreeViewItemViewModel> >(); resourceModel.Setup(model => model.Environment).Returns(env.Object); resourceModel.Setup(model => model.Environment.Connection).Returns(con.Object); resourceModel.Setup(model => model.Environment.Connection.IsConnected).Returns(true); var message = new NewTestFromDebugMessage { ResourceModel = resourceModel.Object, RootItems = debugTreeMock.Object }; var testViewModel = new ServiceTestViewModel(resourceModel.Object, new SynchronousAsyncWorker(), new Mock <IEventAggregator>().Object, new Mock <IExternalProcessExecutor>().Object, new Mock <IWorkflowDesignerViewModel>().Object, message); testViewModel.WebClient = new Mock <IWarewolfWebClient>().Object; var vm = new StudioTestViewModel(eventAggregator.Object, testViewModel, new Mock <IPopupController>().Object, new Mock <IView>().Object); Assert.IsNotNull(vm); Assert.IsNotNull(vm.DebugOutputViewModel); Assert.IsFalse(vm.HasVariables); Assert.IsTrue(vm.HasDebugOutput); Assert.AreEqual(" - Tests - *", vm.DisplayName); Assert.AreEqual("ServiceTestsViewer", vm.ResourceType); Assert.IsNull(vm.HelpText); Assert.IsTrue(vm.IsDirty); testViewModel.SelectedServiceTest.TestName = "New Test Name"; vm.ViewModel = testViewModel; var wasCalled = false; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == "DisplayName") { wasCalled = true; } }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- vm.ViewModel.RefreshCommands(); //---------------Test Result ----------------------- Assert.IsTrue(wasCalled); }
public void StudioTestViewModel_DoDeactivate_CanSave_MessageBoxNo() { //------------Setup for test-------------------------- var mockWorkSurfaceViewModel = new Mock <IWorkflowDesignerViewModel>(); var mockedConn = new Mock <IEnvironmentConnection>(); mockedConn.Setup(conn => conn.ServerEvents).Returns(new Mock <IEventPublisher>().Object); var mockEnvironmentModel = new Mock <IServer>(); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockedConn.Object); mockEnvironmentModel.Setup(e => e.Name).Returns("My Env"); var environmentModel = mockEnvironmentModel.Object; mockWorkSurfaceViewModel.Setup(model => model.Server).Returns(environmentModel); //------------Execute Test--------------------------- var popupController = new Mock <IPopupController>(); popupController.Setup(controller => controller.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButton>(), MessageBoxImage.Information, "", false, false, true, false, false, false)).Returns(MessageBoxResult.No); CustomContainer.Register(popupController.Object); var eventAggregator = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); resourceModel.Setup(model => model.IsWorkflowSaved).Returns(true); mockWorkSurfaceViewModel.Setup(model => model.ResourceModel).Returns(resourceModel.Object); var serviceTestViewModel = new Mock <IServiceTestViewModel>(); serviceTestViewModel.Setup(model => model.WorkflowDesignerViewModel).Returns(mockWorkSurfaceViewModel.Object); var vm = new StudioTestViewModel(eventAggregator.Object, serviceTestViewModel.Object, popupController.Object, new Mock <IView>().Object); Assert.IsNotNull(vm); Assert.IsNotNull(vm.DebugOutputViewModel); Assert.IsFalse(vm.HasVariables); Assert.IsTrue(vm.HasDebugOutput); Assert.IsNull(vm.DisplayName); Assert.AreEqual("ServiceTestsViewer", vm.ResourceType); Assert.IsNull(vm.HelpText); Assert.IsFalse(vm.IsDirty); var env = new Mock <IServer>(); var con = new Mock <IEnvironmentConnection>(); var debugTreeMock = new Mock <List <IDebugTreeViewItemViewModel> >(); resourceModel.Setup(model => model.Environment).Returns(env.Object); resourceModel.Setup(model => model.Environment.Connection).Returns(con.Object); resourceModel.Setup(model => model.Environment.Connection.IsConnected).Returns(true); var message = new NewTestFromDebugMessage { ResourceModel = resourceModel.Object, RootItems = debugTreeMock.Object }; var testViewModel = new ServiceTestViewModel(resourceModel.Object, new SynchronousAsyncWorker(), new Mock <IEventAggregator>().Object, new Mock <IExternalProcessExecutor>().Object, new Mock <IWorkflowDesignerViewModel>().Object, message); testViewModel.WebClient = new Mock <IWarewolfWebClient>().Object; testViewModel.SelectedServiceTest.TestName = "New Test Name"; vm.ViewModel = testViewModel; var expectedValue = vm.DoDeactivate(true); //------------Assert Results------------------------- Assert.IsTrue(vm.IsDirty); Assert.IsNull(vm.HelpText); Assert.IsTrue(expectedValue); }
public void StudioTestViewModel_DebugOutputMessage_Handle_NotNull() { //------------Setup for test-------------------------- var mockWorkSurfaceViewModel = new Mock <IWorkflowDesignerViewModel>(); var mockedConn = new Mock <IEnvironmentConnection>(); mockedConn.Setup(conn => conn.ServerEvents).Returns(new Mock <IEventPublisher>().Object); var mockEnvironmentModel = new Mock <IServer>(); mockEnvironmentModel.Setup(model => model.Connection).Returns(mockedConn.Object); mockEnvironmentModel.Setup(e => e.Name).Returns("My Env"); var environmentModel = mockEnvironmentModel.Object; mockWorkSurfaceViewModel.Setup(model => model.Server).Returns(environmentModel); //------------Execute Test--------------------------- var mvm = new Mock <IShellViewModel>(); mvm.Setup(model => model.HelpViewModel.UpdateHelpText(It.IsAny <string>())); CustomContainer.Register(mvm.Object); CustomContainer.Register(new Mock <IPopupController>().Object); var eventAggregator = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); resourceModel.Setup(model => model.IsWorkflowSaved).Returns(true); mockWorkSurfaceViewModel.Setup(model => model.ResourceModel).Returns(resourceModel.Object); var serviceTestViewModel = new Mock <IServiceTestViewModel>(); serviceTestViewModel.Setup(model => model.WorkflowDesignerViewModel).Returns(mockWorkSurfaceViewModel.Object); var vm = new StudioTestViewModel(eventAggregator.Object, serviceTestViewModel.Object, new Mock <IPopupController>().Object, new Mock <IView>().Object); Assert.IsNotNull(vm); Assert.IsNotNull(vm.DebugOutputViewModel); Assert.IsFalse(vm.HasVariables); Assert.IsTrue(vm.HasDebugOutput); Assert.IsNull(vm.DisplayName); Assert.AreEqual("ServiceTestsViewer", vm.ResourceType); Assert.IsNull(vm.HelpText); Assert.IsFalse(vm.IsDirty); vm.HelpText = string.Empty; var env = new Mock <IServer>(); var con = new Mock <IEnvironmentConnection>(); var debugTreeMock = new Mock <List <IDebugTreeViewItemViewModel> >(); resourceModel.Setup(model => model.Environment).Returns(env.Object); resourceModel.Setup(model => model.Environment.Connection).Returns(con.Object); resourceModel.Setup(model => model.Environment.Connection.IsConnected).Returns(true); var message = new NewTestFromDebugMessage { ResourceModel = resourceModel.Object, RootItems = debugTreeMock.Object }; var testViewModel = new ServiceTestViewModel(resourceModel.Object, new SynchronousAsyncWorker(), new Mock <IEventAggregator>().Object, new Mock <IExternalProcessExecutor>().Object, new Mock <IWorkflowDesignerViewModel>().Object, message); testViewModel.WebClient = new Mock <IWarewolfWebClient>().Object; var debugForTest = new List <IDebugState>(); testViewModel.SelectedServiceTest.DebugForTest = debugForTest; //------------Assert Results------------------------- vm.Handle(new DebugOutputMessage(testViewModel.SelectedServiceTest?.DebugForTest)); Assert.AreEqual(DebugStatus.Ready, vm.DebugOutputViewModel.DebugStatus); mvm.Verify(model => model.HelpViewModel.UpdateHelpText(It.IsAny <string>())); }