public PartInspectionViewModel(ISession session, IPartInspectionRepository repos, IUserNotify notify, ISecurityContext ctx) { try { this.session = session; this.repos = repos; this.notify = notify; this.ctx = ctx; this.Inspectors = repos.RepoInspector.GetAll(); if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn("Incoming Inspection of Componentry: List of Inspectors is NULL or empty"); } searchCommand = ViewModelSource.Create(() => new SearchPartForInspectionCommand(this, session, ctx)); saveInspectionTestResultsCommand = ViewModelSource.Create(() => new SaveInspectionTestResultsCommand(repos.RepoInspectionTestResult, this, notify, ctx)); saveAndClearTestResultsCommand = ViewModelSource.Create(() => new SaveAndClearTestResultsCommand(this)); this.Inspectors = repos.RepoInspector.GetAll(); } catch (RepositoryException ex) { log.Warn(this.GetType().Name + " | " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } }
public PartInspectionViewModel(ISession session, IPartInspectionRepository repos, IUserNotify notify, ISecurityContext ctx) { try { this.session = session; this.repos = repos; this.notify = notify; this.ctx = ctx; this.Inspectors = repos.RepoInspector.GetAll(); if(this.Inspectors == null || this.Inspectors.Count <= 0) log.Warn("Incoming Inspection of Componentry: List of Inspectors is NULL or empty"); searchCommand = ViewModelSource.Create(() => new SearchPartForInspectionCommand(this, session, ctx)); saveInspectionTestResultsCommand = ViewModelSource.Create(() => new SaveInspectionTestResultsCommand(repos.RepoInspectionTestResult, this, notify, ctx)); saveAndClearTestResultsCommand = ViewModelSource.Create(() => new SaveAndClearTestResultsCommand(this)); this.Inspectors = repos.RepoInspector.GetAll(); } catch(RepositoryException ex) { log.Warn(this.GetType().Name + " | " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } }
public PartInspectionViewModel(ISession session, IPartInspectionRepository repos, IUserNotify notify, ISecurityContext ctx) { this.session = session; this.repos = repos; this.notify = notify; this.ctx = ctx; this.Inspectors = repos.RepoInspector.GetAll(); if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn("Incoming Inspection of Componentry: List of Inspectors is NULL or empty"); } searchCommand = ViewModelSource.Create(() => new SearchPartForInspectionCommand(this, session, ctx)); saveInspectionTestResultsCommand = ViewModelSource.Create(() => new SaveInspectionTestResultsCommand(repos.RepoInspectionTestResult, this, notify, ctx)); saveAndClearTestResultsCommand = ViewModelSource.Create(() => new SaveAndClearTestResultsCommand(this)); this.Inspectors = repos.RepoInspector.GetAll(); }
public void TestSaveInspectionTestResults() { var session = new Mock<ISession>(); var notify = new Mock<IUserNotify>(); var repoInspector = new Mock<IInspectorRepository>(); var repoPipe = new Mock<IPipeRepository>(); var repoSpool = new Mock<ISpoolRepository>(); var repoComponent = new Mock<IComponentRepository>(); var repoInspectionTestResult = new Mock<IInspectionTestResultRepository>(); var modifiableView = new Mock<IModifiable>(); var ctx = new Mock<ISecurityContext>(); Mock<IPartInspectionRepository> repos = new Mock<IPartInspectionRepository>(); repos.SetupGet(_ => _.RepoComponent).Returns(repoComponent.Object); repos.SetupGet(_ => _.RepoInspectionTestResult).Returns(repoInspectionTestResult.Object); repos.SetupGet(_ => _.RepoInspector).Returns(repoInspector.Object); repos.SetupGet(_ => _.RepoPipe).Returns(repoPipe.Object); repos.SetupGet(_ => _.RepoSpool).Returns(repoSpool.Object); List<InspectionTestResult> list = new List<InspectionTestResult>() { new InspectionTestResult(){ Inspectors = new List<Inspector>() { new Inspector() } } }; var viewModel = new PartInspectionViewModel(session.Object, repos.Object, notify.Object, ctx.Object); viewModel.ModifiableView = modifiableView.Object; Pipe part = new Pipe() { InspectionTestResults = list}; repos.Setup(_ => _.RepoPipe.Get(It.IsAny<Guid>())).Returns(part); Main.Forms.Parts.Search.Part notConverted = new Main.Forms.Parts.Search.Part() { Id = part.Id, Type = new EnumWrapper<PartType>(PartType.Pipe) }; repoInspectionTestResult.Setup(_ => _.GetByPartId(notConverted.Id)).Returns(list); viewModel.SelectedElement = notConverted; var command = new SaveInspectionTestResultsCommand(repoInspectionTestResult.Object, viewModel, notify.Object, ctx.Object); command.Execute(); repoInspectionTestResult.Verify(_ => _.BeginTransaction(), Times.Once()); repoInspectionTestResult.Verify(_ => _.SaveOrUpdate(It.IsAny<InspectionTestResult>()), Times.AtLeastOnce()); }