public SettingsViewModel(ISettingsRepositories repos, IUserNotify notify, ISecurityContext ctx) { NewPipeMillSizeType(); this.repos = repos; this.notify = notify; this.ctx = ctx; saveCommand = ViewModelSource .Create <SaveSettingsCommand>(() => new SaveSettingsCommand(this, repos, notify, ctx)); extractCategoriesCommand = ViewModelSource .Create <ExtractCategoriesCommand>(() => new ExtractCategoriesCommand(this, repos, notify)); this.ExtractCategoriesCommand.Execute(); CategoryTypes.ListChanged += (s, e) => ModifiableView.IsModified = true; PipeTests.ListChanged += (s, e) => ModifiableView.IsModified = true; }
public SettingsViewModel(ISettingsRepositories repos, IUserNotify notify, ISecurityContext ctx) { NewPipeMillSizeType(); this.repos = repos; this.notify = notify; this.ctx = ctx; saveCommand = ViewModelSource .Create<SaveSettingsCommand>(() => new SaveSettingsCommand(this, repos, notify, ctx)); extractCategoriesCommand = ViewModelSource .Create<ExtractCategoriesCommand>(() => new ExtractCategoriesCommand(this, repos, notify)); this.ExtractCategoriesCommand.Execute(); CategoryTypes.ListChanged += (s, e) => ModifiableView.IsModified = true; PipeTests.ListChanged += (s, e) => ModifiableView.IsModified = true; }
public void TestSaveSettings() { var notify = new Mock<IUserNotify>(); var repoPipeSize = new Mock<IMillPipeSizeTypeRepository>(); var repoPipeTests = new Mock<IPipeTestRepository>(); var repoWelders = new Mock<IWelderRepository>(); var repoInspectors = new Mock<IInspectorRepository>(); var repoManufacturers = new Mock<IPlateManufacturerRepository>(); var repoProjectSetting = new Mock<IProjectRepository>(); var repoUsers = new Mock<IUserRepository>(); var repoRoles = new Mock<IRoleRepository>(); var repoPerms = new Mock<IPermissionRepository>(); var repoCategory = new Mock<ICategoryRepository>(); var repoJointOperation = new Mock<IJointOperationRepository>(); var repoCertificateType = new Mock<ICertificateTypeRepository>(); var repoComponentType = new Mock<IComponentTypeRepository>(); var repoSeamType = new Mock<ISeamTypeRepository>(); var testProjectSetting = new Project() { IsNative = true}; var testSizeType = new PipeMillSizeType() { IsNative = true, Project = testProjectSetting, Diameter = 10, Thickness = 5, SeamType = new SeamType(), Length = 20, }; foreach (PipeTest t in testSizeType.PipeTests) { t.Code = "Code"; t.Name = "Name"; t.ControlType = PipeTestControlType.Monitor; t.ResultType = PipeTestResultType.Boolean; } var testWelder = new Welder() { Certificate = new Certificate() { ExpirationDate = DateTime.Now} }; var testManufacturer = new PlateManufacturer() { IsNative = true, Project = testProjectSetting}; var testInspector = new Inspector(); var testUser = new User(); var testRole = new Role(); var testPerm = new Permission() { Name = "CreateJoint" }; var modifiableView = new Mock<IModifiable>(); var jointOperations = new JointOperation(); var ctx = new Mock<ISecurityContext>(); repoPipeSize.Setup(_ => _.GetAll()).Returns(new List<PipeMillSizeType>() { testSizeType }); repoWelders.Setup(_ => _.GetAll()).Returns(new List<Welder>() { testWelder }); repoManufacturers.Setup(_ => _.GetAll()).Returns(new List<PlateManufacturer>() { testManufacturer }); repoProjectSetting.Setup(_ => _.GetSingle()).Returns(testProjectSetting); repoInspectors.Setup(_ => _.GetAll()).Returns(new List<Inspector>() { testInspector }); repoUsers.Setup(_ => _.GetAll()).Returns(new List<User>() { testUser }); repoRoles.Setup(_ => _.GetAll()).Returns(new List<Role>() { testRole }); repoPerms.Setup(_ => _.GetAll()).Returns(new List<Permission>() { testPerm }); repoJointOperation.Setup(_ => _.GetAll()).Returns(new List<JointOperation>() { jointOperations }); repoCategory.Setup(x => x.GetAll()).Returns(new List<Category>() { new Category() }); repoCertificateType.Setup(x => x.GetAll()).Returns(new List<InspectorCertificateType>() { new InspectorCertificateType() }); repoComponentType.Setup(x => x.GetAll()).Returns(new List<ComponentType>() { new ComponentType() }); Mock<ISettingsRepositories> settingsRepos = new Mock<ISettingsRepositories>(); settingsRepos.SetupGet(_ => _.PipeSizeTypeRepo).Returns(repoPipeSize.Object); settingsRepos.SetupGet(_ => _.PipeTestRepo).Returns(repoPipeTests.Object); settingsRepos.SetupGet(_ => _.WelderRepo).Returns(repoWelders.Object); settingsRepos.SetupGet(_ => _.PlateManufacturerRepo).Returns(repoManufacturers.Object); settingsRepos.SetupGet(_ => _.ProjectRepo).Returns(repoProjectSetting.Object); settingsRepos.SetupGet(_ => _.InspectorRepo).Returns(repoInspectors.Object); settingsRepos.SetupGet(_ => _.UserRepo).Returns(repoUsers.Object); settingsRepos.SetupGet(_ => _.RoleRepo).Returns(repoRoles.Object); settingsRepos.SetupGet(_ => _.PermissionRepo).Returns(repoPerms.Object); settingsRepos.SetupGet(_ => _.JointRepo).Returns(repoJointOperation.Object); settingsRepos.SetupGet(x => x.СategoryRepo).Returns(repoCategory.Object); settingsRepos.SetupGet(x => x.CertificateTypeRepo).Returns(repoCertificateType.Object); settingsRepos.SetupGet(x => x.ComponentTypeRepo).Returns(repoComponentType.Object); settingsRepos.SetupGet(x => x.SeamTypeRepo).Returns(repoSeamType.Object); var viewModel = new SettingsViewModel(settingsRepos.Object, notify.Object, ctx.Object); viewModel.ModifiableView = modifiableView.Object; viewModel.LoadData(); viewModel.ModifiableView = modifiableView.Object; var validatable = new Mock<IValidatable>(); validatable.Setup(x => x.Validate()).Returns(true); viewModel.validatableView = validatable.Object; var command = new SaveSettingsCommand(viewModel, settingsRepos.Object, notify.Object, ctx.Object); command.Execute(); settingsRepos.Verify(_ => _.BeginTransaction(), Times.Once()); repoPipeSize.Verify(_ => _.SaveOrUpdate(testSizeType), Times.Once()); settingsRepos.Verify(_ => _.Commit(), Times.Once()); repoPipeSize.Verify(_ => _.Evict(testSizeType), Times.Once()); repoWelders.Verify(_ => _.SaveOrUpdate(testWelder), Times.Once()); repoWelders.Verify(_ => _.Evict(testWelder), Times.Once()); repoManufacturers.Verify(_ => _.SaveOrUpdate(testManufacturer), Times.Once()); repoManufacturers.Verify(_ => _.Evict(testManufacturer), Times.Once()); repoProjectSetting.Verify(_ => _.SaveOrUpdate(testProjectSetting), Times.Once()); repoProjectSetting.Verify(_ => _.Evict(testProjectSetting), Times.Once()); repoInspectors.Verify(_ => _.SaveOrUpdate(testInspector), Times.Once()); repoInspectors.Verify(_ => _.Evict(testInspector), Times.Once()); repoUsers.Verify(_ => _.SaveOrUpdate(testUser), Times.Once()); repoUsers.Verify(_ => _.Evict(testUser), Times.Once()); repoRoles.Verify(_ => _.SaveOrUpdate(testRole), Times.Once()); repoRoles.Verify(_ => _.Evict(testRole), Times.Once()); }