public MillPipeNewEditViewModel(IMillRepository repoMill, Guid id, IUserNotify notify, ISecurityContext ctx) { this.repoMill = repoMill; this.notify = notify; this.PipeId = id; this.ctx = ctx; #region Commands creation pipeDeactivationCommand = ViewModelSource.Create(() => new PipeDeactivationCommand(this, repoMill, notify, ctx)); newSavePipeCommand = ViewModelSource.Create(() => new NewSavePipeCommand(this, repoMill, notify, ctx)); savePipeCommand = ViewModelSource.Create(() => new SavePipeCommand(this, repoMill, notify, ctx)); extractHeatsCommand = ViewModelSource.Create(() => new ExtractHeatsCommand(this, repoMill.RepoHeat, notify)); extractPurchaseOrderCommand = ViewModelSource.Create(() => new ExtractPurchaseOrderCommand(this, repoMill.RepoPurchaseOrder)); extractPipeTypeCommand = ViewModelSource.Create(() => new ExtractPipeTypeCommand(this, repoMill.RepoPipeType)); getPipeCommand = ViewModelSource.Create(() => new GetPipeCommand(this, repoMill)); getProjectCommand = ViewModelSource.Create(() => new GetProjectCommand(this, repoMill.RepoProject)); #endregion this.GetProjectCommand.Execute(); this.mill = Project.MillName; if(id == Guid.Empty) { NewPipe(); } else { extractPurchaseOrderCommand.Execute(); extractHeatsCommand.Execute(); extractPipeTypeCommand.Execute(); getPipeCommand.Execute(); GetAllPipeTestResults(); PipeNotifier = NotificationService.Instance.NotRequiredOperationManager.CreateNotifier(Pipe); SelectiveOperationPipeNotifier = NotificationService.Instance.SelectiveOperationManager.CreateNotifier(Pipe); } Welders = repoMill.WelderRepo.GetAll(); if(this.Welders == null || this.Welders.Count <= 0) log.Warn(string.Format("Pipe (id:{0}) creation: List of Welders is NULL or empty", id)); Inspectors = repoMill.RepoInspector.GetAll(); if(this.Inspectors == null || this.Inspectors.Count <= 0) log.Warn(string.Format("Pipe (id:{0}) creation: List of Inspectors is NULL or empty", id)); GetAvailableTests(); foreach(string controlTypeName in Enum.GetNames(typeof(PipeTestResultStatus))) { if(controlTypeName != Enum.GetName(typeof(PipeTestResultStatus), PipeTestResultStatus.Undefined)) TestResultStatuses.Add(new EnumWrapper<PipeTestResultStatus>() { Value = (PipeTestResultStatus)Enum.Parse(typeof(PipeTestResultStatus), controlTypeName) } ); } LoadPipeMillStatuses(); }
public MillPipeNewEditViewModel(IMillRepository repoMill, Guid id, IUserNotify notify, ISecurityContext ctx) { this.repoMill = repoMill; this.notify = notify; this.PipeId = id; this.ctx = ctx; #region Commands creation pipeDeactivationCommand = ViewModelSource.Create(() => new PipeDeactivationCommand(this, repoMill, notify, ctx)); newSavePipeCommand = ViewModelSource.Create(() => new NewSavePipeCommand(this, repoMill, notify, ctx)); savePipeCommand = ViewModelSource.Create(() => new SavePipeCommand(this, repoMill, notify, ctx)); extractHeatsCommand = ViewModelSource.Create(() => new ExtractHeatsCommand(this, repoMill.RepoHeat, notify)); extractPurchaseOrderCommand = ViewModelSource.Create(() => new ExtractPurchaseOrderCommand(this, repoMill.RepoPurchaseOrder)); extractPipeTypeCommand = ViewModelSource.Create(() => new ExtractPipeTypeCommand(this, repoMill.RepoPipeType)); getPipeCommand = ViewModelSource.Create(() => new GetPipeCommand(this, repoMill)); getProjectCommand = ViewModelSource.Create(() => new GetProjectCommand(this, repoMill.RepoProject)); #endregion this.GetProjectCommand.Execute(); this.mill = Project.MillName; if (id == Guid.Empty) { NewPipe(); } else { extractPurchaseOrderCommand.Execute(); extractHeatsCommand.Execute(); extractPipeTypeCommand.Execute(); getPipeCommand.Execute(); GetAllPipeTestResults(); PipeNotifier = NotificationService.Instance.NotRequiredOperationManager.CreateNotifier(Pipe); SelectiveOperationPipeNotifier = NotificationService.Instance.SelectiveOperationManager.CreateNotifier(Pipe); } Welders = repoMill.WelderRepo.GetAll(); if (this.Welders == null || this.Welders.Count <= 0) { log.Warn(string.Format("Pipe (id:{0}) creation: List of Welders is NULL or empty", id)); } Inspectors = repoMill.RepoInspector.GetAll(); if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn(string.Format("Pipe (id:{0}) creation: List of Inspectors is NULL or empty", id)); } GetAvailableTests(); foreach (string controlTypeName in Enum.GetNames(typeof(PipeTestResultStatus))) { if (controlTypeName != Enum.GetName(typeof(PipeTestResultStatus), PipeTestResultStatus.Undefined)) { TestResultStatuses.Add(new EnumWrapper <PipeTestResultStatus>() { Value = (PipeTestResultStatus)Enum.Parse(typeof(PipeTestResultStatus), controlTypeName) } ); } } LoadPipeMillStatuses(); }
public void TestMillPipeNewEdit() { var modifiableView = new Mock<IModifiable>(); var repoPipe = new Mock<IPipeRepository>(); var notify = new Mock<IUserNotify>(); var repoPlate = new Mock<IPlateRepository>(); var repoHeat = new Mock<IHeatRepository>(); var repoWeld = new Mock<IWeldRepository>(); var repoPipeType = new Mock<IMillPipeSizeTypeRepository>(); var repoPurchaseOrder = new Mock<IPurchaseOrderRepository>(); var repoWelder = new Mock<IWelderRepository>(); var repoPipeTestResult = new Mock<IPipeTestResultRepository>(); var repoPipeTest = new Mock<IPipeTestRepository>(); var repoInspector = new Mock<IInspectorRepository>(); var repoProject = new Mock<IProjectRepository>(); var ctx = new Mock<ISecurityContext>(); var pipe = new Pipe(); repoPipe.Setup(x => x.GetActiveByNumber(pipe)).Returns(new List<Pipe>()); repoProject.Setup(x => x.GetSingle()).Returns(new Project() { IsNative = true}); repoPipeTest.Setup(x => x.GetByCriteria(It.IsAny<NHibernate.Criterion.DetachedCriteria>())).Returns(new List<PipeTest>()); Mock<IMillRepository> millRepos = new Mock<IMillRepository>(); millRepos.SetupGet(_ => _.RepoPipe).Returns(repoPipe.Object); millRepos.SetupGet(_ => _.RepoPlate).Returns(repoPlate.Object); millRepos.SetupGet(_ => _.RepoHeat).Returns(repoHeat.Object); millRepos.SetupGet(_ => _.RepoWeld).Returns(repoWeld.Object); millRepos.SetupGet(_ => _.RepoPipeType).Returns(repoPipeType.Object); millRepos.SetupGet(_ => _.RepoPurchaseOrder).Returns(repoPurchaseOrder.Object); millRepos.SetupGet(_ => _.WelderRepo).Returns(repoWelder.Object); millRepos.SetupGet(_ => _.RepoPipeTestResult).Returns(repoPipeTestResult.Object); millRepos.SetupGet(_ => _.RepoPipeTest).Returns(repoPipeTest.Object); millRepos.SetupGet(_ => _.RepoInspector).Returns(repoInspector.Object); millRepos.SetupGet(_ => _.RepoProject).Returns(repoProject.Object); modifiableView.SetupGet(x => x.IsModified).Returns(false); var viewModel = new MillPipeNewEditViewModel( millRepos.Object, Guid.Empty, notify.Object, ctx.Object); var validatable = new Mock<IValidatable>(); validatable.Setup(x => x.Validate()).Returns(true); viewModel.ValidatableView = validatable.Object; viewModel.Pipe = pipe; viewModel.ModifiableView = modifiableView.Object; var command = new NewSavePipeCommand( viewModel, millRepos.Object, notify.Object, ctx.Object); command.Execute(); millRepos.Verify(_ => _.BeginTransaction(), Times.Once()); repoPipe.Verify(_ => _.SaveOrUpdate(It.IsAny<Pipe>()), Times.Once()); millRepos.Verify(_ => _.Commit(), Times.Once()); repoPipe.Verify(_ => _.Evict(It.IsAny<Pipe>()), Times.Once()); }