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()); }
void OnAdd() { ShortDepartment parentDepartment = null; var hasParentDepartment = SelectedDepartment != null; if (hasParentDepartment) parentDepartment = SelectedDepartment.Department; var departmentDetailsViewModel = new DepartmentDetailsViewModel(); departmentDetailsViewModel.Initialize(_organisationUID, parentDepartment, Models); if (DialogService.ShowModalWindow(departmentDetailsViewModel)) { var department = departmentDetailsViewModel.Model; var departmentViewModel = new DepartmentSelectionItemViewModel(department); if (hasParentDepartment) { SelectedDepartment.AddChild(departmentViewModel); } else { RootDepartments.Add(departmentViewModel); OnPropertyChanged(() => RootDepartments); } departmentViewModel.ExpandToThis(); SelectedDepartment = departmentViewModel; ServiceFactory.Events.GetEvent<NewDepartmentEvent>().Publish(department); } }