public void AddSameNameTest() { var organisation = new Organisation(); var department = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID }; var newDepartment = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID }; var mock = new Mock<ISafeRubezhService>(); mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns<OrganisationFilter>(filter => { return new OperationResult<List<Organisation>>(new List<Organisation> { organisation }); }); mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns<DepartmentFilter>(filter => { return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department }); }); mock.Setup(x => x.GetDepartmentDetails(It.IsAny<Guid>())).Returns<Guid>(uid => { if (uid == department.UID) return new OperationResult<Department>(new Department { UID = department.UID, OrganisationUID = department.UID, Name = department.Name }); return null; }); mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() => { return new OperationResult<List<ShortEmployee>>(); }); ClientManager.RubezhService = mock.Object; var departmentsViewModel = new DepartmentsViewModel(); departmentsViewModel.Initialize(new DepartmentFilter()); var detailsViewModel = new DepartmentDetailsViewModel(); detailsViewModel.Initialize(organisation, newDepartment, departmentsViewModel); Assert.IsFalse(detailsViewModel.ValidateAndSave()); }
public void DeleteChild() { var organisation = new Organisation(); var department = new ShortDepartment { UID = Guid.NewGuid(), Name = "Name1", OrganisationUID = organisation.UID }; var childDepartment = new ShortDepartment { UID = Guid.NewGuid(), Name = "Name2", OrganisationUID = organisation.UID, ParentDepartmentUID = department.UID, IsDeleted = true }; department.ChildDepartments.Add(new TinyDepartment { Name = childDepartment.Name, UID = childDepartment.UID }); var mock = new Mock<ISafeRubezhService>(); mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns(() => { return new OperationResult<List<Organisation>>(new List<Organisation> { organisation }); }); mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns(() => { return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department, childDepartment }); }); mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() => { return new OperationResult<List<ShortEmployee>>(); }); mock.Setup(x => x.RestoreDepartment(It.IsAny<ShortDepartment>())).Returns<ShortDepartment>(shortDeaprtment => { if (shortDeaprtment.UID == department.UID) department.IsDeleted = false; if (shortDeaprtment.UID == childDepartment.UID) childDepartment.IsDeleted = false; return new OperationResult<bool>(true); }); mock.Setup(x => x.GetParentEmployeeUIDs(It.IsAny<Guid>())).Returns<Guid>(uid => { var result = new List<Guid>(); if(uid == childDepartment.UID) result.Add(department.UID); return new OperationResult<List<Guid>>(result); }); ClientManager.RubezhService = mock.Object; (ServiceFactory.MessageBoxService as MockMessageBoxService).ShowConfirmationResult = true; var departmentsViewModel = new DepartmentsViewModel(); departmentsViewModel.Initialize(new DepartmentFilter()); departmentsViewModel.SelectedItem = departmentsViewModel.Organisations.SelectMany(x => x.GetAllChildren()).FirstOrDefault(x => x.UID == childDepartment.UID); if (departmentsViewModel.RestoreCommand.CanExecute(null)) departmentsViewModel.RestoreCommand.ForceExecute(); else Assert.IsTrue(false); departmentsViewModel.Initialize(new DepartmentFilter()); var department2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == department.UID); var childDepartment2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == childDepartment.UID); Assert.IsFalse(department2.IsDeleted || childDepartment2.IsDeleted); }
public static bool SaveChief(ShortDepartment model, Guid? chiefUID) { return SaveChief(model.UID, chiefUID, model.Name); }
public static bool MarkDeleted(ShortDepartment item) { var result = ClientManager.RubezhService.MarkDeletedDepartment(item); return Common.ThrowErrorIfExists(result); }
public static bool Restore(ShortDepartment item) { var result = ClientManager.RubezhService.RestoreDepartment(item); return Common.ThrowErrorIfExists(result); }
public OperationResult<bool> RestoreDepartment(Guid clientUID, ShortDepartment department) { return SafeOperationCall(clientUID, () => RubezhService.RestoreDepartment(clientUID, department), "RestoreDepartment"); }
public DepartmentSelectionItemViewModel(ShortDepartment department) { Model = department; UID = Model.UID; Name = Model.Name; }
public OperationResult<bool> MarkDeletedDepartment(Guid clientUID, ShortDepartment department) { return SafeOperationCall(clientUID, () => RubezhService.MarkDeletedDepartment(clientUID, department), "MarkDeletedDepartment"); }
public OperationResult<bool> RestoreDepartment(ShortDepartment item) { return SafeOperationCall(() => { var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10)); using (rubezhService as IDisposable) return rubezhService.RestoreDepartment(RubezhServiceFactory.UID, item); }, "RestoreDepartment"); }
public void IsShowDeletedPosition() { var organisation = new Organisation(); var department = new ShortDepartment { Name = "DeletedDepartment", OrganisationUID = organisation.UID, IsDeleted = true }; var position = new ShortPosition { Name = "DeletedPosition", OrganisationUID = organisation.UID, IsDeleted = true }; var employee = new Employee { FirstName = "FName", SecondName = "SName", LastName = "LName", OrganisationUID = organisation.UID, DepartmentName = department.Name, DepartmentUID = department.UID, IsDepartmentDeleted = department.IsDeleted, PositionName = position.Name, PositionUID = position.UID, IsPositionDeleted = position.IsDeleted }; var shortEmployee = new ShortEmployee { UID = employee.UID, FirstName = employee.FirstName, SecondName = employee.SecondName, LastName = employee.LastName, OrganisationUID = organisation.UID, DepartmentName = department.Name, IsDepartmentDeleted = department.IsDeleted, PositionName = position.Name, IsPositionDeleted = position.IsDeleted }; ClientManager.CurrentUser.PermissionStrings.Add("Oper_SKD_Employees_Edit"); var mock = new Mock<ISafeRubezhService>(); mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns(() => { return new OperationResult<List<Organisation>>(new List<Organisation> { organisation }); }); mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() => { return new OperationResult<List<ShortEmployee>>(new List<ShortEmployee> { shortEmployee}); }); mock.Setup(x => x.GetEmployeeDetails(It.IsAny<Guid>())).Returns(() => { return new OperationResult<Employee>(employee); }); mock.Setup(x => x.GetAdditionalColumnTypes(It.IsAny<AdditionalColumnTypeFilter>())).Returns(() => { return new OperationResult<List<AdditionalColumnType>>(); }); mock.Setup(x => x.SaveEmployee(It.IsAny<Employee>(), It.IsAny<bool>())).Returns(() => { return new OperationResult<bool>(true); }); ClientManager.RubezhService = mock.Object; (ServiceFactory.DialogService as MockDialogService).OnShowModal += window => (window as EmployeeDetailsViewModel).SaveCommand.Execute(); var employeesViewModel = new EmployeesViewModel(); employeesViewModel.Initialize(new EmployeeFilter()); employeesViewModel.SelectedItem = employeesViewModel.Organisations.FirstOrDefault().Children.FirstOrDefault(); employeesViewModel.EditCommand.Execute(); Assert.IsTrue(employeesViewModel.SelectedItem.DepartmentName == null || employeesViewModel.SelectedItem.DepartmentName == ""); Assert.IsTrue(employeesViewModel.SelectedItem.PositionName == null || employeesViewModel.SelectedItem.PositionName == ""); }
public OperationResult<bool> RestoreDepartment(Guid clientUID, ShortDepartment department) { AddJournalMessage(JournalEventNameType.Редактирование_отдела, department.Name, department.UID, clientUID, JournalEventDescriptionType.Восстановление_отдел, JournalObjectType.Department); foreach (var parent in department.ParentDepartments) { AddJournalMessage(JournalEventNameType.Редактирование_отдела, parent.Name, parent.UID, clientUID, JournalEventDescriptionType.Восстановление_отдел, JournalObjectType.Department); } using (var databaseService = new RubezhDAL.DataClasses.DbService()) { return databaseService.DepartmentTranslator.Restore(department.UID); } }
public OperationResult<bool> MarkDeletedDepartment(Guid clientUID, ShortDepartment department) { AddJournalMessage(JournalEventNameType.Редактирование_отдела, department.Name, department.UID, clientUID, JournalEventDescriptionType.Удаление_отдел, JournalObjectType.Department); foreach (var childDepartment in department.ChildDepartments) { AddJournalMessage(JournalEventNameType.Редактирование_отдела, childDepartment.Name, childDepartment.UID, clientUID, JournalEventDescriptionType.Удаление_отдел, JournalObjectType.Department); } using (var databaseService = new RubezhDAL.DataClasses.DbService()) { return databaseService.DepartmentTranslator.MarkDeleted(department.UID); } }