public async Task Put_Removes_Obsoleted_And_Removes_Usages_In_Projects() { //Arrange await PrepareForDetailedTest(); var project = await ItProjectHelper.CreateProject(A <string>(), TestEnvironment.DefaultOrganizationId); //Add some task refs to a project and save the expected keys (keys not removed) MutateDatabase(context => { using (var taskRefs = new GenericRepository <TaskRef>(context)) using (var projects = new GenericRepository <ItProject>(context)) { var itProject = projects.GetByKey(project.Id); var toKeep = taskRefs.AsQueryable().Take(2).ToList(); toKeep.ForEach(itProject.TaskRefs.Add); projects.Save(); } }); var expectedTaskRefs = GetProjectTaskRefKeys(project.Id); Assert.Equal(2, expectedTaskRefs.Count); //Add the task refs subject to removal MutateDatabase(db => { using (var projects = new GenericRepository <ItProject>(db)) using (var taskRefs = new GenericRepository <TaskRef>(db)) { var other = taskRefs.AsQueryable().First(); var objectOwnerId = other.ObjectOwnerId; var organizationUnitId = other.OwnedByOrganizationUnitId; var taskRef1 = taskRefs.Insert(CreateTaskRef(objectOwnerId, organizationUnitId)); var taskRef2 = taskRefs.Insert(CreateTaskRef(objectOwnerId, organizationUnitId)); taskRefs.Save(); //Add usages which we expect to be removed var itProject = projects.GetByKey(project.Id); itProject.TaskRefs.Add(taskRef1); itProject.TaskRefs.Add(taskRef2); projects.Save(); } }); //Act await PutKle(); //Assert var actualTaskRefs = GetProjectTaskRefKeys(project.Id); VerifyTaskRefUsageKeys(expectedTaskRefs, actualTaskRefs); }
public async Task Can_Create_Reference_In_ItProject() { //Arrange var project = await ItProjectHelper.CreateProject(A <string>(), TestEnvironment.DefaultOrganizationId); //Act - create two similar references... we expect the first one to be the master var expectedMasterReference = await ReferencesHelper.CreateReferenceAsync(_title, _externalReferenceId, _referenceUrl, _display, dto => dto.ItProject_Id = project.Id); await ReferencesHelper.CreateReferenceAsync(_title, _externalReferenceId, _referenceUrl, _display, dto => dto.ItProject_Id = project.Id); //Assert AssertCreatedReference(_title, expectedMasterReference, _externalReferenceId, _referenceUrl, _display); project = await ItProjectHelper.GetProjectAsync(project.Id); Assert.Equal(2, project.ExternalReferences.Count); Assert.Equal(expectedMasterReference.Id, project.ReferenceId.GetValueOrDefault(-1)); //First reference must be marked as "the reference" }
public async Task InitializeAsync() { _root = await ItProjectHelper.CreateProject(A <string>(), OrganizationId); }
private static async Task <ItProjectDTO> CreateProjectAsync(int organizationId = TestEnvironment.DefaultOrganizationId) { return(await ItProjectHelper.CreateProject(CreateName(), organizationId)); }