public void Prevent_ExecutePublish_IfAny() { var vm = new ProcessEditViewModel(); var cs = new Lazy<ICommunicationService>(); var val = new CommunicationService(); Mock.Arrange(() => cs.Value).Returns(val); Mock.Arrange(() => vm.CommunicationService).Returns(cs); Mock.Arrange(() => vm.CommunicationService.Value.IsPublishingInProgress).Returns(false); var popupFactory = new PopupFactory(); var popupBuilder = new PopupBuilder(); Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => { }); Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder); vm.ThePopupFactory = new Lazy<PopupFactory>(() => popupFactory); var pvm = new Lazy<PublishViewModel>(); Mock.Arrange(() => vm.PublishVM).Returns(pvm); var prevented = false; Mock.Arrange(() => popupBuilder.Message(LanguageService.Translate("Label_PublishingIsInProgress"))).DoInstead(() => prevented = true).Returns(popupBuilder); var model = Mock.Create<ProcessEdit>(); Mock.Arrange(() => vm.Model).Returns(model); Mock.Arrange(() => vm.Model.IsValid).Returns(true); Mock.Arrange(() => vm.Model.IsDirty).Returns(false); Mock.Arrange(() => vm.Model.IsInactive).Returns(false); Mock.Arrange(() => Utils.CurrentUserIsReadOnly).Returns(false); vm.PublishCommand.Execute(null); Assert.IsFalse(prevented); Mock.Arrange(() => vm.CommunicationService.Value.IsPublishingInProgress).Returns(true); vm.PublishCommand.Execute(null); Assert.IsTrue(prevented); }
public void SelecLayoutEvenIfNameIsEmpty() { // arraange var vm = new ProcessLayoutsViewModel(); Mock.NonPublic.Arrange<bool>(vm, "CanSortOrGroupLayout", new object[] { ArgExpr.IsNull<object>() }).Returns(true); vm.EditLayoutVM = new Lazy<EditLayoutViewModel>(); var model = Mock.Create<ProcessEdit>(); model.LayoutList = new ProcessLayoutList(); Mock.Arrange(() => vm.Model).Returns(model); var popupBuilder = new PopupBuilder(); var popupFactory = new PopupFactory { PopupFactoryFactory = new ExportFactory<PopupBuilder>(() => new Tuple<PopupBuilder, Action>(popupBuilder, () => { })) }; Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => ok()); Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder); vm.ThePopupFactory = popupFactory; var newLayoutViewModelFactory = Mock.Create<INewLayoutViewModelFactory>(); Mock.Arrange(() => newLayoutViewModelFactory.CreateLayoutVM(Arg.IsAny<ProcessLayoutEdit>())).Returns<ProcessLayoutEdit>((l) => new NewLayoutViewModel(l) { Name = l.Name, Id = l.Id, LayoutString = l.LayoutInfo }); vm.TheLayoutFactory = newLayoutViewModelFactory; vm.LayoutAddCommand.Execute(null); vm.LayoutAddCommand.Execute(null); vm.SelectedLayout = vm.LayoutList[0]; vm.SelectedLayout.Name = string.Empty; vm.SelectedLayout = vm.LayoutList[1]; // act vm.SelectedLayout = vm.LayoutList[0]; // assert Assert.IsTrue(vm.SelectedLayout.GetHashCode() == vm.LayoutList[0].GetHashCode()); }