Example #1
0
        public async Task GetTagRequirements_AsPreserver_ShouldGetTagRequirements()
        {
            // Arrange
            var tagIdUnderTest = TagIdUnderTest_ForStandardTagWithAttachmentRequirement_Started;

            // Act
            var requirementDetailDtos = await TagsControllerTestsHelper.GetTagRequirementsAsync(
                UserType.Preserver, TestFactory.PlantWithAccess,
                tagIdUnderTest);

            // Assert
            Assert.IsNotNull(requirementDetailDtos);
            Assert.IsTrue(requirementDetailDtos.Count > 0);

            var requirementDetailDto = requirementDetailDtos.First();

            Assert.IsNotNull(requirementDetailDto.RowVersion);
        }
Example #2
0
        public async Task UpdateTagStepAndRequirements_AsPlanner_ShouldDeleteRequirement()
        {
            // Arrange
            var newReqDefId = await CreateRequirementDefinitionAsync(UserType.LibraryAdmin, TestFactory.PlantWithAccess);

            var tagIdUnderTest = await CreateAreaTagAsync(AreaTagType.PreArea,
                                                          TwoStepJourneyWithTags.Steps.First().Id,
                                                          null,
                                                          false);

            var tag = await TagsControllerTestsHelper.GetTagAsync(UserType.Planner, TestFactory.PlantWithAccess,
                                                                  tagIdUnderTest);

            var requirementsToAdd = new List <TagRequirementDto>
            {
                new TagRequirementDto
                {
                    IntervalWeeks           = 4,
                    RequirementDefinitionId = newReqDefId
                }
            };
            await TagsControllerTestsHelper.UpdateTagStepAndRequirementsAsync(
                UserType.Planner, TestFactory.PlantWithAccess,
                tag.Id,
                tag.Description,
                tag.Step.Id,
                tag.RowVersion,
                requirementsToAdd);

            var oldRequirements = await TagsControllerTestsHelper.GetTagRequirementsAsync(UserType.Planner,
                                                                                          TestFactory.PlantWithAccess, tagIdUnderTest);

            Assert.IsTrue(oldRequirements.Count > 1);
            var requirementToDelete = oldRequirements.First();

            // Act
            var requirementsToUpdate = new List <UpdatedTagRequirementDto>
            {
                new UpdatedTagRequirementDto
                {
                    IntervalWeeks = requirementToDelete.IntervalWeeks,
                    IsVoided      = true,
                    RequirementId = requirementToDelete.Id,
                    RowVersion    = requirementToDelete.RowVersion
                }
            };
            var requirementsToDelete = new List <DeletedTagRequirementDto>
            {
                new DeletedTagRequirementDto
                {
                    RequirementId = requirementToDelete.Id,
                    RowVersion    = requirementToDelete.RowVersion
                }
            };
            await TagsControllerTestsHelper.UpdateTagStepAndRequirementsAsync(
                UserType.Planner, TestFactory.PlantWithAccess,
                tag.Id,
                tag.Description,
                tag.Step.Id,
                tag.RowVersion,
                updatedRequirements : requirementsToUpdate,
                deletedRequirements : requirementsToDelete);

            // Assert
            var updatedRequirements = await TagsControllerTestsHelper.GetTagRequirementsAsync(UserType.Planner, TestFactory.PlantWithAccess, tagIdUnderTest);

            Assert.AreEqual(oldRequirements.Count - 1, updatedRequirements.Count);
            await AssertInHistoryAsLatestEventAsync(tagIdUnderTest, UserType.Planner, EventType.RequirementDeleted);
            await AssertInHistoryAsExistingEventAsync(tagIdUnderTest, UserType.Planner, EventType.RequirementVoided);
        }
Example #3
0
        public async Task UpdateTagStepAndRequirements_AsPlanner_ShouldUpdateAndAddRequirements()
        {
            // Arrange
            var newReqDefId = await CreateRequirementDefinitionAsync(UserType.LibraryAdmin, TestFactory.PlantWithAccess);

            var tagIdUnderTest = await CreateAreaTagAsync(AreaTagType.PreArea,
                                                          TwoStepJourneyWithTags.Steps.First().Id,
                                                          null,
                                                          false);

            var tag = await TagsControllerTestsHelper.GetTagAsync(
                UserType.Planner,
                TestFactory.PlantWithAccess,
                tagIdUnderTest);

            var oldDescription  = tag.Description;
            var oldRequirements = await TagsControllerTestsHelper.GetTagRequirementsAsync(
                UserType.Planner,
                TestFactory.PlantWithAccess,
                tagIdUnderTest);

            var requirementToUpdate  = oldRequirements.First();
            var updatedIntervalWeeks = requirementToUpdate.IntervalWeeks + 1;
            var requirementsToAdd    = new List <TagRequirementDto>
            {
                new TagRequirementDto
                {
                    IntervalWeeks           = 4,
                    RequirementDefinitionId = newReqDefId
                }
            };
            var requirementsToUpdate = new List <UpdatedTagRequirementDto>
            {
                new UpdatedTagRequirementDto
                {
                    IntervalWeeks = updatedIntervalWeeks,
                    IsVoided      = false,
                    RequirementId = requirementToUpdate.Id,
                    RowVersion    = requirementToUpdate.RowVersion
                }
            };

            // Act
            await TagsControllerTestsHelper.UpdateTagStepAndRequirementsAsync(
                UserType.Planner, TestFactory.PlantWithAccess,
                tagIdUnderTest,
                oldDescription,
                tag.Step.Id,
                tag.RowVersion,
                requirementsToAdd,
                requirementsToUpdate);

            // Assert
            var updatedRequirements = await TagsControllerTestsHelper.GetTagRequirementsAsync(UserType.Planner, TestFactory.PlantWithAccess, tagIdUnderTest);

            Assert.AreEqual(oldRequirements.Count + 1, updatedRequirements.Count);
            var addedRequirement = updatedRequirements.SingleOrDefault(r => r.RequirementDefinition.Id == newReqDefId);

            Assert.IsNotNull(addedRequirement);
            var updatedRequirement = updatedRequirements.SingleOrDefault(r => r.Id == requirementToUpdate.Id);

            Assert.IsNotNull(updatedRequirement);
            Assert.AreEqual(updatedIntervalWeeks, updatedRequirement.IntervalWeeks);

            await AssertInHistoryAsLatestEventAsync(tagIdUnderTest, UserType.Planner, EventType.RequirementAdded);
            await AssertInHistoryAsExistingEventAsync(tagIdUnderTest, UserType.Planner, EventType.IntervalChanged);
        }