public ComponentNewEditViewModel( IComponentRepositories repos, Guid id, IUserNotify notify, ISecurityContext context) { this.repos = repos; this.notify = notify; this.context = context; try { this.componentTypes = new BindingList <ComponentType>(repos.ComponentTypeRepo.GetAll()); this.Inspectors = repos.RepoInspector.GetAll(); } catch (RepositoryException ex) { log.Warn("ComponentNewEditViewModel " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } saveCommand = ViewModelSource .Create(() => new SaveComponentCommand(this, repos, notify, context)); newSaveCommand = ViewModelSource .Create(() => new NewSaveComponentCommand(this, repos, notify, context)); deactivationCommand = ViewModelSource .Create(() => new ComponentDeactivationCommand(this, repos, notify, context)); if (id == Guid.Empty) { NewComponent(); } else { try { this.Component = repos.ComponentRepo.Get(id); } catch (RepositoryException ex) { log.Warn("ComponentNewEditViewModel " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } } if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn(string.Format("Componentry (id:{0}) creation: List of Inspectors is NULL or empty", id)); } }
public ComponentNewEditViewModel( IComponentRepositories repos, Guid id, IUserNotify notify, ISecurityContext context) { this.repos = repos; this.notify = notify; this.context = context; try { this.componentTypes = new BindingList<ComponentType>(repos.ComponentTypeRepo.GetAll()); this.Inspectors = repos.RepoInspector.GetAll(); } catch(RepositoryException ex) { log.Warn("ComponentNewEditViewModel " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } saveCommand = ViewModelSource .Create(() => new SaveComponentCommand(this, repos, notify, context)); newSaveCommand = ViewModelSource .Create(() => new NewSaveComponentCommand(this, repos, notify, context)); deactivationCommand = ViewModelSource .Create(() => new ComponentDeactivationCommand(this, repos, notify, context)); if (id == Guid.Empty) { NewComponent(); } else { try { this.Component = repos.ComponentRepo.Get(id); } catch(RepositoryException ex) { log.Warn("ComponentNewEditViewModel " + ex.ToString()); notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message), Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header)); } } if(this.Inspectors == null || this.Inspectors.Count <=0) log.Warn(string.Format("Componentry (id:{0}) creation: List of Inspectors is NULL or empty", id)); }
public void TestNewSaveComponent() { var modifiableView = new Mock<IModifiable>(); var validatableView = new Mock<IValidatable>(); var notify = new Mock<IUserNotify>(); var securityContext = new Mock<ISecurityContext>(); var componentRepo = new Mock<IComponentRepository>(); var componentTypeRepo = new Mock<IComponentTypeRepository>(); var repoInspector = new Mock<IInspectorRepository>(); var component = new Prizm.Domain.Entity.Construction.Component() { Number = string.Empty}; componentRepo.Setup(x => x.GetActiveByNumber(component)).Returns(new List<Prizm.Domain.Entity.Construction.Component>()); componentTypeRepo.Setup(x => x.GetAll()).Returns(new List<ComponentType>()); componentTypeRepo.Setup(x => x.GetAll()).Returns(new List<ComponentType>()); var componentsRepos = new Mock<IComponentRepositories>(); componentsRepos.SetupGet(_ => _.ComponentRepo).Returns(componentRepo.Object); componentsRepos.SetupGet(_ => _.ComponentTypeRepo).Returns(componentTypeRepo.Object); componentsRepos.SetupGet(_ => _.RepoInspector).Returns(repoInspector.Object); modifiableView.SetupGet(x => x.IsModified).Returns(false); validatableView.Setup(t => t.Validate()).Returns(true); var viewModel = new ComponentNewEditViewModel( componentsRepos.Object, Guid.Empty, notify.Object, securityContext.Object); viewModel.Component = component; viewModel.ModifiableView = modifiableView.Object; viewModel.ValidatableView = validatableView.Object; var command = new NewSaveComponentCommand( viewModel, componentsRepos.Object, notify.Object, securityContext.Object); command.Execute(); componentsRepos.Verify(_ => _.BeginTransaction(), Times.Once()); componentRepo.Verify(_ => _.SaveOrUpdate(It.IsAny<Prizm.Domain.Entity.Construction.Component>()), Times.Once()); componentsRepos.Verify(_ => _.Commit(), Times.Once()); componentRepo.Verify(_ => _.Evict(It.IsAny<Prizm.Domain.Entity.Construction.Component>()), Times.Once()); }
public ComponentNewEditViewModel( IComponentRepositories repos, Guid id, IUserNotify notify, ISecurityContext context) { this.repos = repos; this.notify = notify; this.context = context; this.componentTypes = new BindingList <ComponentType>(repos.ComponentTypeRepo.GetAll()); this.Inspectors = repos.RepoInspector.GetAll(); saveCommand = ViewModelSource .Create(() => new SaveComponentCommand(this, repos, notify, context)); newSaveCommand = ViewModelSource .Create(() => new NewSaveComponentCommand(this, repos, notify, context)); deactivationCommand = ViewModelSource .Create(() => new ComponentDeactivationCommand(this, repos, notify, context)); if (id == Guid.Empty) { NewComponent(); } else { this.Component = repos.ComponentRepo.Get(id); } if (this.Inspectors == null || this.Inspectors.Count <= 0) { log.Warn(string.Format("Componentry (id:{0}) creation: List of Inspectors is NULL or empty", id)); } }