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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
Exemplo n.º 6
0
 public async Task CreateJourney_AsPreserver_ShouldReturnForbidden_WhenPermissionMissing()
 => await JourneysControllerTestsHelper.CreateJourneyAsync(
     UserType.Preserver, TestFactory.PlantWithAccess,
     "Journey1",
     HttpStatusCode.Forbidden);
Exemplo n.º 7
0
 public async Task CreateJourney_AsAdmin_ShouldReturnForbidden_WhenNoAccessToPlant()
 => await JourneysControllerTestsHelper.CreateJourneyAsync(
     UserType.LibraryAdmin, TestFactory.PlantWithoutAccess,
     "Journey1",
     HttpStatusCode.Forbidden);
Exemplo n.º 8
0
 public async Task CreateJourney_AsAdmin_ShouldReturnBadRequest_WhenUnknownPlant()
 => await JourneysControllerTestsHelper.CreateJourneyAsync(
     UserType.LibraryAdmin, TestFactory.UnknownPlant,
     "Journey1",
     HttpStatusCode.BadRequest,
     "is not a valid plant");
Exemplo n.º 9
0
 public async Task CreateJourney_AsAnonymous_ShouldReturnUnauthorized()
 => await JourneysControllerTestsHelper.CreateJourneyAsync(
     UserType.Anonymous, TestFactory.UnknownPlant,
     "Journey1",
     HttpStatusCode.Unauthorized);