コード例 #1
0
        public async Task UnvoidStep_AsAdmin_ShouldUnvoidStep_AndUpdateRowVersion()
        {
            // Arrange
            var journeyIdUnderTest = TwoStepJourneyWithTagsIdUnderTest;
            var stepId             = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode);

            var step = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            var currentRowVersion = await JourneysControllerTestsHelper.VoidStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                stepId,
                step.RowVersion);

            // Act
            var newRowVersion = await JourneysControllerTestsHelper.UnvoidStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                stepId,
                currentRowVersion);

            // Assert
            AssertRowVersionChange(currentRowVersion, newRowVersion);
            step = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            Assert.IsFalse(step.IsVoided);
        }
コード例 #2
0
        public async Task UpdateStep_AsAdmin_ShouldUpdateStepAndRowVersion()
        {
            // Arrange
            var journeyIdUnderTest = TwoStepJourneyWithTagsIdUnderTest;
            var stepIdUnderTest    = FirstStepInJourneyWithTagsIdUnderTest;
            var step = await GetStepDetailsAsync(journeyIdUnderTest, stepIdUnderTest);

            var currentRowVersion = step.RowVersion;
            var newTitle          = Guid.NewGuid().ToString();

            // Act
            var newRowVersion = await JourneysControllerTestsHelper.UpdateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                step.Id,
                newTitle,
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode,
                currentRowVersion);

            // Assert
            AssertRowVersionChange(currentRowVersion, newRowVersion);
            step = await GetStepDetailsAsync(journeyIdUnderTest, stepIdUnderTest);

            Assert.AreEqual(newTitle, step.Title);
        }
コード例 #3
0
 public async Task DeleteStep_AsAdmin_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.DeleteStepAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithoutAccess,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.Forbidden);
コード例 #4
0
        public async Task DeleteStep_AsAdmin_ShouldDeleteStep()
        {
            // Arrange
            var journeyIdUnderTest = JourneyNotInUseIdUnderTest;
            var stepId             = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode);

            var step = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            var currentRowVersion = await JourneysControllerTestsHelper.VoidStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                stepId,
                step.RowVersion);

            // Act
            await JourneysControllerTestsHelper.DeleteStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                stepId,
                currentRowVersion);

            // Assert
            step = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            Assert.IsNull(step);
        }
コード例 #5
0
 public async Task DeleteStep_AsPreserver_ShouldReturnForbidden_WhenPermissionMissing()
 => await JourneysControllerTestsHelper.DeleteStepAsync(
     UserType.Preserver, TestFactory.PlantWithAccess,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.Forbidden);
コード例 #6
0
 public async Task DeleteStep_AsAnonymous_ShouldReturnUnauthorized()
 => await JourneysControllerTestsHelper.DeleteStepAsync(
     UserType.Anonymous, TestFactory.UnknownPlant,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.Unauthorized);
コード例 #7
0
        public async Task CreateStep_AsAdmin_ShouldCreateStep()
        {
            // Arrange
            var journeyIdUnderTest = await JourneysControllerTestsHelper.CreateJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                Guid.NewGuid().ToString());

            var title = Guid.NewGuid().ToString();

            // Act
            var stepId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                title,
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode);

            // Assert
            var step = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            Assert.IsNotNull(step);
            Assert.AreEqual(title, step.Title);
        }
コード例 #8
0
 public async Task UnvoidStep_AsHacker_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.UnvoidStepAsync(
     UserType.Hacker, TestFactory.PlantWithoutAccess,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.Forbidden);
コード例 #9
0
        public async Task TestInitialize()
        {
            OtherModeIdUnderTest = TestFactory.Instance.SeededData[KnownPlantData.PlantA].OtherModeId;
            SupModeAIdUnderTest  = TestFactory.Instance.SeededData[KnownPlantData.PlantA].SupModeAId;
            SupModeBIdUnderTest  = TestFactory.Instance.SeededData[KnownPlantData.PlantA].SupModeBId;

            var journeys = await JourneysControllerTestsHelper.GetJourneysAsync(UserType.LibraryAdmin, TestFactory.PlantWithAccess);

            var journeyWithTags = journeys.Single(j => j.Title == KnownTestData.TwoStepJourneyWithTags);

            TwoStepJourneyWithTagsIdUnderTest     = journeyWithTags.Id;
            FirstStepInJourneyWithTagsIdUnderTest = journeyWithTags.Steps.First().Id;
            var journeyNotInUse = journeys.Single(j => j.Title == KnownTestData.JourneyNotInUse);

            JourneyNotInUseIdUnderTest       = journeyNotInUse.Id;
            StepInJourneyNotInUseIdUnderTest = journeyNotInUse.Steps.First().Id;

            TestFactory.Instance
            .ResponsibleApiServiceMock
            .Setup(service => service.TryGetResponsibleAsync(TestFactory.PlantWithAccess, KnownTestData.ResponsibleCode))
            .Returns(Task.FromResult(new PCSResponsible
            {
                Code = KnownTestData.ResponsibleCode, Description = KnownTestData.ResponsibleDescription
            }));
        }
コード例 #10
0
        public async Task CreateStep_AsAdmin_ShouldCreateTwoSupplierSteps()
        {
            // Arrange
            var journeyIdUnderTest = await JourneysControllerTestsHelper.CreateJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                Guid.NewGuid().ToString());

            var stepAId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                SupModeAIdUnderTest,
                KnownTestData.ResponsibleCode);

            // Act
            var stepBId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                SupModeBIdUnderTest,
                KnownTestData.ResponsibleCode);

            // Assert
            await AssertStepIsForSupplier(journeyIdUnderTest, stepAId);
            await AssertStepIsForSupplier(journeyIdUnderTest, stepBId);
        }
コード例 #11
0
 public async Task DeleteStep_AsAdmin_ShouldReturnBadRequest_WhenUnknownJourneyOrStepId()
 => await JourneysControllerTestsHelper.DeleteStepAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithAccess,
     JourneyNotInUseIdUnderTest,
     FirstStepInJourneyWithTagsIdUnderTest,     // step in other Journey
     TestFactory.AValidRowVersion,
     HttpStatusCode.BadRequest,
     "Journey and/or step doesn't exist!");
コード例 #12
0
 public async Task DeleteStep_AsAdmin_ShouldReturnBadRequest_WhenUnknownPlant()
 => await JourneysControllerTestsHelper.DeleteStepAsync(
     UserType.LibraryAdmin, TestFactory.UnknownPlant,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.BadRequest,
     "is not a valid plant");
コード例 #13
0
 public async Task UnvoidStep_AsHacker_ShouldReturnBadRequest_WhenUnknownPlant()
 => await JourneysControllerTestsHelper.UnvoidStepAsync(
     UserType.Hacker, TestFactory.UnknownPlant,
     9999,
     8888,
     TestFactory.AValidRowVersion,
     HttpStatusCode.BadRequest,
     "is not a valid plant");
コード例 #14
0
 public async Task CreateStep_AsPreserver_ShouldReturnForbidden_WhenPermissionMissing()
 => await JourneysControllerTestsHelper.CreateStepAsync(
     UserType.Preserver, TestFactory.PlantWithAccess,
     9999,
     "Step1",
     7777,
     "RC",
     HttpStatusCode.Forbidden);
コード例 #15
0
 public async Task CreateStep_AsAdmin_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.CreateStepAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithoutAccess,
     9999,
     "Step1",
     7777,
     "RC",
     HttpStatusCode.Forbidden);
コード例 #16
0
 public async Task CreateStep_AsAnonymous_ShouldReturnUnauthorized()
 => await JourneysControllerTestsHelper.CreateStepAsync(
     UserType.Anonymous, TestFactory.UnknownPlant,
     9999,
     "Step1",
     7777,
     "RC",
     HttpStatusCode.Unauthorized);
コード例 #17
0
 public async Task CreateStep_AsAdmin_ShouldReturnBadRequest_WhenUnknownPlant()
 => await JourneysControllerTestsHelper.CreateStepAsync(
     UserType.LibraryAdmin, TestFactory.UnknownPlant,
     9999,
     "Step1",
     7777,
     "RC",
     HttpStatusCode.BadRequest,
     "is not a valid plant");
コード例 #18
0
        private async Task <StepDetailsDto> GetStepDetailsAsync(int journeyId, int stepId)
        {
            var journey = await JourneysControllerTestsHelper.GetJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyId);

            return(journey.Steps.SingleOrDefault(s => s.Id == stepId));
        }
コード例 #19
0
 public async Task UpdateStep_AsAdmin_ShouldReturnBadRequest_WhenUnknownJourneyOrStepId()
 => await JourneysControllerTestsHelper.UpdateStepAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithAccess,
     JourneyNotInUseIdUnderTest,
     FirstStepInJourneyWithTagsIdUnderTest,     // step in other Journey
     Guid.NewGuid().ToString(),
     OtherModeIdUnderTest,
     KnownTestData.ResponsibleCode,
     TestFactory.AValidRowVersion,
     HttpStatusCode.BadRequest,
     "Journey and/or step doesn't exist!");
コード例 #20
0
        public async Task GetJourneys_AsAdmin_ShouldGetJourneysWithSteps()
        {
            // Act
            var journeys = await JourneysControllerTestsHelper.GetJourneysAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess);

            // Assert
            Assert.IsNotNull(journeys);
            Assert.AreNotEqual(0, journeys.Count);
            var step = journeys.First().Steps.FirstOrDefault();

            Assert.IsNotNull(step);
        }
コード例 #21
0
 public async Task SwapSteps_AsPreserver_ShouldReturnForbidden_WhenPermissionMissing()
 => await JourneysControllerTestsHelper.SwapStepsAsync(
     UserType.Preserver,
     TestFactory.PlantWithAccess,
     9999,
     new StepIdAndRowVersion
 {
     Id         = 2,
     RowVersion = TestFactory.AValidRowVersion
 },
     new StepIdAndRowVersion
 {
     Id         = 12,
     RowVersion = TestFactory.AValidRowVersion
 },
     HttpStatusCode.Forbidden);
コード例 #22
0
        public async Task GetJourney_AsAdmin_ShouldGetJourneyWithStep()
        {
            // Act
            var journey = await JourneysControllerTestsHelper.GetJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                TwoStepJourneyWithTagsIdUnderTest);

            // Assert
            Assert.IsNotNull(journey);
            Assert.IsNotNull(journey.Steps);
            Assert.AreNotEqual(0, journey.Steps.Count());
            var step = journey.Steps.SingleOrDefault(s => s.Id == FirstStepInJourneyWithTagsIdUnderTest);

            Assert.IsNotNull(step);
        }
コード例 #23
0
 public async Task SwapSteps_AsAnonymous_ShouldReturnUnauthorized()
 => await JourneysControllerTestsHelper.SwapStepsAsync(
     UserType.Anonymous,
     TestFactory.UnknownPlant,
     9999,
     new StepIdAndRowVersion
 {
     Id         = 2,
     RowVersion = TestFactory.AValidRowVersion
 },
     new StepIdAndRowVersion
 {
     Id         = 12,
     RowVersion = TestFactory.AValidRowVersion
 },
     HttpStatusCode.Unauthorized);
コード例 #24
0
 public async Task SwapSteps_AsAdmin_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.SwapStepsAsync(
     UserType.LibraryAdmin,
     TestFactory.PlantWithoutAccess,
     9999,
     new StepIdAndRowVersion
 {
     Id         = 2,
     RowVersion = TestFactory.AValidRowVersion
 },
     new StepIdAndRowVersion
 {
     Id         = 12,
     RowVersion = TestFactory.AValidRowVersion
 },
     HttpStatusCode.Forbidden);
コード例 #25
0
 public async Task SwapSteps_AsAdmin_ShouldReturnBadRequest_WhenUnknownPlant()
 => await JourneysControllerTestsHelper.SwapStepsAsync(
     UserType.LibraryAdmin,
     TestFactory.UnknownPlant,
     9999,
     new StepIdAndRowVersion
 {
     Id         = 2,
     RowVersion = TestFactory.AValidRowVersion
 },
     new StepIdAndRowVersion
 {
     Id         = 12,
     RowVersion = TestFactory.AValidRowVersion
 },
     HttpStatusCode.BadRequest,
     "is not a valid plant");
コード例 #26
0
        public async Task UpdateStep_AsAdmin_ShouldUpdateSecondStepToBeSupplier()
        {
            // Arrange
            var journeyIdUnderTest = await JourneysControllerTestsHelper.CreateJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                Guid.NewGuid().ToString());

            var firstStepId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                SupModeAIdUnderTest,
                KnownTestData.ResponsibleCode);

            var secondStepId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode);

            var secondStep = await GetStepDetailsAsync(journeyIdUnderTest, secondStepId);

            Assert.IsFalse(secondStep.Mode.ForSupplier);
            var currentRowVersion = secondStep.RowVersion;

            // Act
            var newRowVersion = await JourneysControllerTestsHelper.UpdateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                secondStep.Id,
                secondStep.Title,
                SupModeBIdUnderTest,
                secondStep.Responsible.Code,
                currentRowVersion);

            // Assert
            AssertRowVersionChange(currentRowVersion, newRowVersion);
            await AssertStepIsForSupplier(journeyIdUnderTest, firstStepId);
            await AssertStepIsForSupplier(journeyIdUnderTest, secondStep.Id);
        }
コード例 #27
0
        public async Task CreateJourney_AsAdmin_ShouldCreateJourney()
        {
            // Arrange
            var title = Guid.NewGuid().ToString();

            // Act
            var journeyId = await JourneysControllerTestsHelper.CreateJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                title);

            // Assert
            var journey = await JourneysControllerTestsHelper.GetJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyId);

            Assert.IsNotNull(journey);
            Assert.AreEqual(title, journey.Title);
        }
コード例 #28
0
        public async Task SwapSteps_AsAdmin_ShouldSwapSteps_AndUpdateRowVersions()
        {
            // Arrange
            var journeyIdUnderTest = await JourneysControllerTestsHelper.CreateJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                Guid.NewGuid().ToString());

            var stepId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                SupModeAIdUnderTest,
                KnownTestData.ResponsibleCode);

            var originalFirstStep = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            Assert.IsTrue(originalFirstStep.Mode.ForSupplier);
            stepId = await JourneysControllerTestsHelper.CreateStepAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                Guid.NewGuid().ToString(),
                OtherModeIdUnderTest,
                KnownTestData.ResponsibleCode);

            var originalSecondStep = await GetStepDetailsAsync(journeyIdUnderTest, stepId);

            Assert.IsFalse(originalSecondStep.Mode.ForSupplier);

            // Act
            var newRowVersions = await JourneysControllerTestsHelper.SwapStepsAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest,
                new StepIdAndRowVersion
            {
                Id         = originalFirstStep.Id,
                RowVersion = originalFirstStep.RowVersion
            },
                new StepIdAndRowVersion
            {
                Id         = originalSecondStep.Id,
                RowVersion = originalSecondStep.RowVersion
            });

            // Assert
            var updatedJourney = await JourneysControllerTestsHelper.GetJourneyAsync(
                UserType.LibraryAdmin,
                TestFactory.PlantWithAccess,
                journeyIdUnderTest);

            var swappedStepA = updatedJourney.Steps.ElementAt(0);
            var swappedStepB = updatedJourney.Steps.ElementAt(1);

            Assert.AreEqual(originalSecondStep.Id, swappedStepA.Id);
            Assert.AreEqual(originalFirstStep.Id, swappedStepB.Id);
            Assert.IsFalse(swappedStepA.Mode.ForSupplier);
            Assert.IsTrue(swappedStepB.Mode.ForSupplier);

            var updatedFirstStepRowVersion  = updatedJourney.Steps.Single(s => s.Id == originalFirstStep.Id).RowVersion;
            var updatedSecondStepRowVersion = updatedJourney.Steps.Single(s => s.Id == originalSecondStep.Id).RowVersion;

            AssertRowVersionChange(originalFirstStep.RowVersion, updatedFirstStepRowVersion);
            AssertRowVersionChange(originalSecondStep.RowVersion, updatedSecondStepRowVersion);

            Assert.AreEqual(updatedFirstStepRowVersion, newRowVersions.Single(r => r.Id == originalFirstStep.Id).RowVersion);
            Assert.AreEqual(updatedSecondStepRowVersion, newRowVersions.Single(r => r.Id == originalSecondStep.Id).RowVersion);
        }
コード例 #29
0
 public async Task GetJourneys_AsPlanner_ShouldReturnForbidden_WhenPermissionMissing()
 => await JourneysControllerTestsHelper.GetJourneysAsync(
     UserType.Planner, TestFactory.PlantWithAccess,
     HttpStatusCode.Forbidden);
コード例 #30
0
 public async Task GetJourneys_AsAdmin_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.GetJourneysAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithoutAccess,
     HttpStatusCode.Forbidden);