public JointNewEditViewModel( IConstructionRepository repoConstruction, IUserNotify notify, Guid id, Prizm.Data.DAL.IMillReportsRepository adoRepo, ISecurityContext ctx) { this.repoConstruction = repoConstruction; this.JointId = id; this.notify = notify; this.adoRepo = adoRepo; this.ctx = ctx; #region Commands saveOrUpdateJointCommand = ViewModelSource.Create(() => new SaveOrUpdateJointCommand(repoConstruction, this, notify, ctx)); saveJointCommand = ViewModelSource.Create(() => new SaveJointCommand(repoConstruction, this, notify, ctx)); newSaveJointCommand = ViewModelSource.Create(() => new NewSaveJointCommand(repoConstruction, this, notify, ctx)); extractOperationsCommand = ViewModelSource.Create(() => new ExtractOperationsCommand(repoConstruction, this)); jointdeactivationCommand = ViewModelSource.Create(() => new JointDeactivationCommand(repoConstruction, this, notify, ctx)); jointCutCommand = ViewModelSource.Create(() => new JointCutCommand(repoConstruction, this, notify)); #endregion Inspectors = repoConstruction.RepoInspector.GetAll(); if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: List of Inspectors is NULL or empty", this.JointId)); } Welders = repoConstruction.RepoWelder.GetAll(); if (this.Welders == null || this.Welders.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: List of Welders is NULL or empty", this.JointId)); } Pieces = adoRepo.GetPipelineElements(); if (this.Pieces == null || this.Pieces.Rows.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: Data Table of Pieces is NULL or empty", this.JointId)); } extractOperationsCommand.Execute(); if (id == Guid.Empty) { NewJoint(); } else { this.Joint = repoConstruction.RepoJoint.Get(id); if (Joint.FirstElement != null && Joint.SecondElement != null && Joint.Status != Domain.Entity.Construction.JointStatus.Withdrawn) { this.firstElement = GetPartDataFromList(Joint.FirstElement, GetPart(Joint.FirstElement)); this.secondElement = GetPartDataFromList(Joint.SecondElement, GetPart(Joint.SecondElement)); Joint.FirstElement = this.firstElement; Joint.SecondElement = this.secondElement; } else { log.Warn(string.Format("Joint #{0} do not has connected Parts or is Withdrawn.", Joint.Number)); } var weldResults = repoConstruction.RepoJointWeldResult.GetByJoint(this.Joint); if (weldResults != null) { jointWeldResults = new BindingList <JointWeldResult>(weldResults); } else { log.Warn(string.Format("Joint #{0} do not have Welding Results.", Joint.Number)); } var testResults = repoConstruction.RepoJointTestResult.GetByJoint(this.Joint); if (testResults != null) { jointTestResults = new BindingList <JointTestResult>(testResults); } else { log.Warn(string.Format("Joint #{0} do not have Test Results.", Joint.Number)); } } }
public JointNewEditViewModel( IConstructionRepository repoConstruction, IUserNotify notify, Guid id, Prizm.Data.DAL.IMillReportsRepository adoRepo, ISecurityContext ctx) { this.repoConstruction = repoConstruction; this.JointId = id; this.notify = notify; this.adoRepo = adoRepo; this.ctx = ctx; #region Commands saveOrUpdateJointCommand = ViewModelSource.Create(() => new SaveOrUpdateJointCommand(repoConstruction, this, notify, ctx)); saveJointCommand = ViewModelSource.Create(() => new SaveJointCommand(repoConstruction, this, notify, ctx)); newSaveJointCommand = ViewModelSource.Create(() => new NewSaveJointCommand(repoConstruction, this, notify, ctx)); extractOperationsCommand = ViewModelSource.Create(() => new ExtractOperationsCommand(repoConstruction, this, notify)); jointdeactivationCommand = ViewModelSource.Create(() => new JointDeactivationCommand(repoConstruction, this, notify, ctx)); jointCutCommand = ViewModelSource.Create(() => new JointCutCommand(repoConstruction, this, notify)); quickSearchCommand = ViewModelSource.Create(() => new QuickSearchCommand(this, repoConstruction.RepoJoint, notify)); #endregion try { Inspectors = repoConstruction.RepoInspector.GetAll(); if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: List of Inspectors is NULL or empty", this.JointId)); } Welders = repoConstruction.RepoWelder.GetAll(); if (this.Welders == null || this.Welders.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: List of Welders is NULL or empty", this.JointId)); } Pieces = adoRepo.GetPipelineElements(); if (this.Pieces == null || this.Pieces.Rows.Count <= 0) { log.Warn(string.Format("Joint (id:{0}) creation: Data Table of Pieces is NULL or empty", this.JointId)); } extractOperationsCommand.Execute(); if (id == Guid.Empty) { NewJoint(); } else { this.Joint = repoConstruction.RepoJoint.Get(id); RefreshJointData(); } } catch (RepositoryException ex) { log.Warn("JointNewEditViewModel " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } }
public void TestJointNewEdit() { var modifiableView = new Mock<IModifiable>(); var notify = new Mock<IUserNotify>(); var repoJoint = new Mock<IJointRepository>(); var repoJointTestResult = new Mock<IJointTestResultRepository>(); var repoJointWeldResult = new Mock<IJointWeldResultRepository>(); var repoJointOperation = new Mock< IJointOperationRepository>(); var repoInspector = new Mock<IInspectorRepository>(); var repoWelder = new Mock<IWelderRepository>(); var repoAdo = new Mock<IMillReportsRepository>(); var securityCtx = new Mock<ISecurityContext>(); var repoSpool = new Mock<ISpoolRepository>(); var repoPipe = new Mock<IPipeRepository>(); var repoComponent = new Mock<IComponentRepository>(); var joint = new Prizm.Domain.Entity.Construction.Joint() { Status = Domain.Entity.Construction.JointStatus.Withdrawn}; BindingList<JointOperation> operations = new BindingList<JointOperation>(); Mock<IConstructionRepository> repoConstruction = new Mock<IConstructionRepository>(); repoConstruction.SetupGet(_ => _.RepoJoint).Returns(repoJoint.Object); repoConstruction.SetupGet(_ => _.RepoJointTestResult).Returns(repoJointTestResult.Object); repoConstruction.SetupGet(_ => _.RepoJointWeldResult).Returns(repoJointWeldResult.Object); repoConstruction.SetupGet(_ => _.RepoJointOperation).Returns(repoJointOperation.Object); repoConstruction.SetupGet(_ => _.RepoInspector).Returns(repoInspector.Object); repoConstruction.SetupGet(_ => _.RepoWelder).Returns(repoWelder.Object); repoConstruction.SetupGet(_ => _.RepoSpool).Returns(repoSpool.Object); repoConstruction.SetupGet(_ => _.RepoPipe).Returns(repoPipe.Object); repoConstruction.SetupGet(_ => _.RepoComponent).Returns(repoComponent.Object); repoJointOperation.Setup(_ => _.GetControlOperations()).Returns(operations); repoJointOperation.Setup(_ => _.GetRepairOperations()).Returns(operations); repoJoint.Setup(_ => _.GetActiveByNumber(joint)).Returns(new List<Prizm.Domain.Entity.Construction.Joint>()); repoSpool.Setup(_ => _.Get(It.IsAny<Guid>())).Returns(new Domain.Entity.Construction.Spool()); repoAdo.Setup(x => x.GetPipelineElements()).Returns(new System.Data.DataTable()); modifiableView.SetupGet(x => x.IsModified).Returns(false); var viewModel = new JointNewEditViewModel(repoConstruction.Object, notify.Object, Guid.Empty, repoAdo.Object, securityCtx.Object); viewModel.Joint = joint; viewModel.FirstElement = new PartData(); viewModel.SecondElement = new PartData(); viewModel.ModifiableView = modifiableView.Object; var validatable = new Mock<IValidatable>(); validatable.Setup(x => x.Validate()).Returns(true); viewModel.ValidatableView = validatable.Object; viewModel.Joint.LoweringDate = DateTime.Now; viewModel.Joint.Number = string.Empty; var welder = new Welder(); var weldResult = new JointWeldResult(); weldResult.Welders.Add(welder); weldResult.IsCompleted = true; viewModel.JointWeldResults.Add(weldResult); var command = new SaveJointCommand(repoConstruction.Object,viewModel, notify.Object, securityCtx.Object); command.Execute(); repoConstruction.Verify(_ => _.BeginTransaction(), Times.Once()); repoJoint.Verify(_ => _.SaveOrUpdate(It.IsAny<Prizm.Domain.Entity.Construction.Joint>()), Times.Once()); repoConstruction.Verify(_ => _.Commit(), Times.Once()); repoJoint.Verify(_ => _.Evict(It.IsAny<Prizm.Domain.Entity.Construction.Joint>()), Times.Once()); }