Example #1
0
        public async Task Get_ProviderIsNotTLevelsProvider_ReturnsForbidden(ProviderType providerType)
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(providerType : providerType);

            var venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                yourReference,
                startDate,
                locationVenueIds: new[] { venueId },
                website,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/details?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Example #2
0
        public async Task Get_VenueIdPassedFromCreateVenueCallack_AddsVenueToLocationVenueIds()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId        = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;
            var anotherVenueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo(), venueName: "Second Venue")).VenueId;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/details?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}&venueId={venueId}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var doc = await response.GetDocument();

            doc.GetElementByTestId($"LocationVenueIds-{venueId}").GetAttribute("checked").Should().Be("checked");
        }
Example #3
0
        public async Task Get_ProviderIsNotTLevelsProvider_ReturnsForbidden(ProviderType providerType)
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : providerType);

            var venueId = (await TestData.CreateVenue(provider.ProviderId)).Id;

            var selectedTLevel = tLevelDefinitions.First();

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                "Who for",
                "Entry requirements",
                "What you'll learn",
                "How you'll learn",
                "How you'll be assessed",
                "What you can do next",
                isComplete: true);

            journeyState.SetDetails(
                "YOUR-REF",
                startDate: new DateTime(2021, 4, 1),
                locationVenueIds: new[] { venueId },
                website: "http://example.com/tlevel",
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/check-publish?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Example #4
0
        public async Task Post_SavesDetailsMarksStageNotCompletedAndRedirects()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId        = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;
            var anotherVenueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo(), venueName: "Second Venue")).VenueId;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add/add-location?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("YourReference", yourReference)
                          .Add("StartDate.Day", startDate.Day)
                          .Add("StartDate.Month", startDate.Month)
                          .Add("StartDate.Year", startDate.Year)
                          .Add("LocationVenueIds", venueId)
                          .Add("Website", website)
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Found);
            response.Headers.Location.OriginalString.Should().StartWith($"/venues/add");

            journeyState = GetJourneyInstance <AddTLevelJourneyModel>(journeyInstanceId).State;

            using (new AssertionScope())
            {
                journeyState.YourReference.Should().Be(yourReference);
                journeyState.StartDate.Should().Be(startDate);
                journeyState.LocationVenueIds.Should().BeEquivalentTo(new[] { venueId });
                journeyState.Website.Should().Be(website);

                journeyState.CompletedStages.Should().Be(
                    AddTLevelJourneyCompletedStages.SelectTLevel |
                    AddTLevelJourneyCompletedStages.Description);
            }
        }
        public async Task Post_ProviderIsNotTLevelsProvider_ReturnsForbidden(ProviderType providerType)
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(providerType : providerType);

            var venueId        = (await TestData.CreateVenue(provider.ProviderId)).Id;
            var anotherVenueId = (await TestData.CreateVenue(provider.ProviderId, venueName: "Second Venue")).Id;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add/add-location?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("YourReference", yourReference)
                          .Add("StartDate.Day", startDate.Day)
                          .Add("StartDate.Month", startDate.Month)
                          .Add("StartDate.Year", startDate.Year)
                          .Add("LocationVenueIds", venueId)
                          .Add("Website", website)
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Example #6
0
        public async Task Post_InvalidData_RendersError(
            string yourReference,
            DateTime?startDate,
            bool addTLevelWithSameStartDate,
            bool populateLocationVenueIds,
            string website,
            string expectedErrorField,
            string expectedErrorMessage)
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;

            var selectedTLevel = tLevelDefinitions.First();

            if (addTLevelWithSameStartDate)
            {
                await TestData.CreateTLevel(
                    provider.ProviderId,
                    selectedTLevel.TLevelDefinitionId,
                    startDate : startDate.Value,
                    locationVenueIds : new[] { venueId },
                    createdBy : User.ToUserInfo());
            }

            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add/details?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("YourReference", yourReference)
                          .Add("StartDate.Day", startDate?.Day)
                          .Add("StartDate.Month", startDate?.Month)
                          .Add("StartDate.Year", startDate?.Year)
                          .Add("LocationVenueIds", populateLocationVenueIds ? venueId.ToString() : null)
                          .Add("Website", website)
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var doc = await response.GetDocument();

            doc.AssertHasError(expectedErrorField, expectedErrorMessage);

            GetJourneyInstance <AddTLevelJourneyModel>(journeyInstanceId).State
            .CompletedStages.Should().NotHaveFlag(AddTLevelJourneyCompletedStages.Details);
        }
Example #7
0
        public async Task Get_ValidRequest_ReturnsExpectedContent()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId        = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;
            var anotherVenueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo(), venueName: "Second Venue")).VenueId;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                yourReference,
                startDate,
                locationVenueIds: new[] { venueId },
                website,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/details?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var doc = await response.GetDocument();

            using (new AssertionScope())
            {
                doc.GetElementById("YourReference").GetAttribute("value").Should().Be(yourReference);
                doc.GetElementById("StartDate.Day").GetAttribute("value").Should().Be(startDate.Day.ToString());
                doc.GetElementById("StartDate.Month").GetAttribute("value").Should().Be(startDate.Month.ToString());
                doc.GetElementById("StartDate.Year").GetAttribute("value").Should().Be(startDate.Year.ToString());
                doc.GetElementByTestId($"LocationVenueIds-{venueId}").GetAttribute("checked").Should().Be("checked");
                doc.GetElementByTestId($"LocationVenueIds-{anotherVenueId}").GetAttribute("checked").Should().NotBe("checked");
                doc.GetElementById("Website").GetAttribute("value").Should().Be(website);
            }
        }
        public async Task Get_ValidRequest_ReturnsExpectedContent()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;

            var createdTLevel = await TestData.CreateTLevel(
                provider.ProviderId,
                tLevelDefinitionId : tLevelDefinitions.First().TLevelDefinitionId,
                whoFor : "Who for",
                entryRequirements : "Entry requirements",
                whatYoullLearn : "What you'll learn",
                howYoullLearn : "How you'll learn",
                howYoullBeAssessed : "How you'll be assessed",
                whatYouCanDoNext : "What you can do next",
                yourReference : "YOUR-REF",
                startDate : new DateTime(2021, 4, 1),
                locationVenueIds : new[] { venueId },
                website : "http://example.com/tlevel",
                createdBy : User.ToUserInfo());

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                createdTLevel.TLevelDefinition.TLevelDefinitionId,
                createdTLevel.TLevelDefinition.Name);

            journeyState.SetDescription(
                createdTLevel.WhoFor,
                createdTLevel.EntryRequirements,
                createdTLevel.WhatYoullLearn,
                createdTLevel.HowYoullLearn,
                createdTLevel.HowYoullBeAssessed,
                createdTLevel.WhatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                createdTLevel.YourReference,
                createdTLevel.StartDate,
                createdTLevel.Locations.Select(l => l.VenueId),
                createdTLevel.Website,
                isComplete: true);

            journeyState.SetCreatedTLevel(createdTLevel.TLevelId);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            journeyInstance.Complete();

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/success?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var doc = await response.GetDocument();

            doc.GetElementByTestId("TLevelName").TextContent.Should().Be(createdTLevel.TLevelDefinition.Name);
        }
        public async Task Post_SelectedTLevelIsSameAsCurrent_DoesNotOverwriteDescriptionOrResetJourneyStage()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray());

            var selectedTLevel = tLevelDefinitions.First();

            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);
            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);
            journeyState.CompletedStages.Should().Be(AddTLevelJourneyCompletedStages.SelectTLevel | AddTLevelJourneyCompletedStages.Description);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("SelectedTLevelDefinitionId", selectedTLevel.TLevelDefinitionId)
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Found);

            journeyState = GetJourneyInstance <AddTLevelJourneyModel>(journeyInstanceId).State;

            using (new AssertionScope())
            {
                journeyState.WhoFor.Should().Be(whoFor);
                journeyState.EntryRequirements.Should().Be(entryRequirements);
                journeyState.WhatYoullLearn.Should().Be(whatYoullLearn);
                journeyState.HowYoullLearn.Should().Be(howYoullLearn);
                journeyState.HowYoullBeAssessed.Should().Be(howYoullBeAssessed);
                journeyState.WhatYouCanDoNext.Should().Be(whatYouCanDoNext);
                journeyState.CompletedStages.Should().Be(AddTLevelJourneyCompletedStages.SelectTLevel | AddTLevelJourneyCompletedStages.Description);
            }
        }
        public async Task Post_SelectedTLevelIsDifferentToCurrent_OverwritesDescriptionWithExemplarAndResetsJourneyStage()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray());

            var currentlySelectedTLevel = tLevelDefinitions.First();

            var currentWhoFor             = "Who for";
            var currentEntryRequirements  = "Entry requirements";
            var currentWhatYoullLearn     = "What you'll learn";
            var currentHowYoullLearn      = "How you'll learn";
            var currentHowYoullBeAssessed = "How you'll be assessed";
            var currentWhatYouCanDoNext   = "What you can do next";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                currentlySelectedTLevel.TLevelDefinitionId,
                currentlySelectedTLevel.Name);
            journeyState.SetDescription(
                currentWhoFor,
                currentEntryRequirements,
                currentWhatYoullLearn,
                currentHowYoullLearn,
                currentHowYoullBeAssessed,
                currentWhatYouCanDoNext,
                isComplete: true);
            journeyState.CompletedStages.Should().Be(AddTLevelJourneyCompletedStages.SelectTLevel | AddTLevelJourneyCompletedStages.Description);

            var newSelectedTLevelDefinitionId = tLevelDefinitions.Last().TLevelDefinitionId;

            newSelectedTLevelDefinitionId.Should().NotBe(currentlySelectedTLevel.TLevelDefinitionId);

            var newTLevelExemplarContent = await WithSqlQueryDispatcher(dispatcher =>
                                                                        dispatcher.ExecuteQuery(new GetTLevelDefinitionExemplarContent()
            {
                TLevelDefinitionId = newSelectedTLevelDefinitionId
            }));

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("SelectedTLevelDefinitionId", newSelectedTLevelDefinitionId)
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Found);

            journeyState = GetJourneyInstance <AddTLevelJourneyModel>(journeyInstanceId).State;

            using (new AssertionScope())
            {
                journeyState.WhoFor.Should().Be(newTLevelExemplarContent.WhoFor);
                journeyState.EntryRequirements.Should().Be(newTLevelExemplarContent.EntryRequirements);
                journeyState.WhatYoullLearn.Should().Be(newTLevelExemplarContent.WhatYoullLearn);
                journeyState.HowYoullLearn.Should().Be(newTLevelExemplarContent.HowYoullLearn);
                journeyState.HowYoullBeAssessed.Should().Be(newTLevelExemplarContent.HowYoullBeAssessed);
                journeyState.WhatYouCanDoNext.Should().Be(newTLevelExemplarContent.WhatYouCanDoNext);
                journeyState.CompletedStages.Should().Be(AddTLevelJourneyCompletedStages.SelectTLevel);
            }
        }
Example #11
0
        public async Task Post_CreatesTLevelUpdatesJourneyStateAndRedirects()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId = (await TestData.CreateVenue(provider.ProviderId)).Id;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                yourReference,
                startDate,
                locationVenueIds: new[] { venueId },
                website,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            Guid createdTLevelId = default;

            SqlQuerySpy.Callback <CreateTLevel, OneOf <CreateTLevelFailedReason, Success> >(
                q => createdTLevelId = q.TLevelId);

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add/check-publish?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Found);
            response.Headers.Location.OriginalString
            .Should().Be($"/t-levels/add/success?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            SqlQuerySpy.VerifyQuery <CreateTLevel, OneOf <CreateTLevelFailedReason, Success> >(q =>
                                                                                               q.CreatedBy.UserId == User.UserId &&
                                                                                               q.CreatedOn == Clock.UtcNow &&
                                                                                               q.EntryRequirements == entryRequirements &&
                                                                                               q.HowYoullBeAssessed == howYoullBeAssessed &&
                                                                                               q.HowYoullLearn == howYoullLearn &&
                                                                                               q.LocationVenueIds.Single() == venueId &&
                                                                                               q.ProviderId == provider.ProviderId &&
                                                                                               q.StartDate == startDate &&
                                                                                               q.TLevelDefinitionId == selectedTLevel.TLevelDefinitionId &&
                                                                                               q.Website == website &&
                                                                                               q.WhatYouCanDoNext == whatYouCanDoNext &&
                                                                                               q.WhatYoullLearn == q.WhatYoullLearn &&
                                                                                               q.WhoFor == whoFor &&
                                                                                               q.YourReference == q.YourReference);

            GetJourneyInstance <AddTLevelJourneyModel>(journeyInstanceId)
            .State.TLevelId.Should().Be(createdTLevelId);
        }
Example #12
0
        public async Task Post_TLevelAlreadyExistsForStartDate_RendersError()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueId = (await TestData.CreateVenue(provider.ProviderId)).Id;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            await TestData.CreateTLevel(
                provider.ProviderId,
                selectedTLevel.TLevelDefinitionId,
                whoFor : whoFor,
                entryRequirements : entryRequirements,
                whatYoullLearn : whatYoullLearn,
                howYoullLearn : howYoullLearn,
                howYoullBeAssessed : howYoullBeAssessed,
                whatYouCanDoNext : whatYouCanDoNext,
                yourReference : yourReference,
                startDate : startDate,
                locationVenueIds : new[] { venueId },
                website : website,
                createdBy : User.ToUserInfo());

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                yourReference,
                startDate,
                locationVenueIds: new[] { venueId },
                website,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            Guid createdTLevelId = default;

            SqlQuerySpy.Callback <CreateTLevel, OneOf <CreateTLevelFailedReason, Success> >(
                q => createdTLevelId = q.TLevelId);

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/t-levels/add/check-publish?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .ToContent()
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var doc = await response.GetDocument();

            doc.GetElementByTestId("duplicate-date-error").Should().NotBeNull();
        }
Example #13
0
        public async Task Get_ValidRequest_ReturnsExpectedContent()
        {
            // Arrange
            var tLevelDefinitions = await TestData.CreateInitialTLevelDefinitions();

            var authorizedTLevelDefinitionIds = tLevelDefinitions.Select(tld => tld.TLevelDefinitionId).ToArray();

            var provider = await TestData.CreateProvider(
                providerType : ProviderType.TLevels,
                tLevelDefinitionIds : authorizedTLevelDefinitionIds);

            var venueName = "T Level test venue";
            var venueId   = (await TestData.CreateVenue(provider.ProviderId, venueName: venueName)).Id;

            var selectedTLevel     = tLevelDefinitions.First();
            var whoFor             = "Who for";
            var entryRequirements  = "Entry requirements";
            var whatYoullLearn     = "What you'll learn";
            var howYoullLearn      = "How you'll learn";
            var howYoullBeAssessed = "How you'll be assessed";
            var whatYouCanDoNext   = "What you can do next";
            var yourReference      = "YOUR-REF";
            var startDate          = new DateTime(2021, 4, 1);
            var website            = "http://example.com/tlevel";

            var journeyState = new AddTLevelJourneyModel();

            journeyState.SetTLevel(
                selectedTLevel.TLevelDefinitionId,
                selectedTLevel.Name);

            journeyState.SetDescription(
                whoFor,
                entryRequirements,
                whatYoullLearn,
                howYoullLearn,
                howYoullBeAssessed,
                whatYouCanDoNext,
                isComplete: true);

            journeyState.SetDetails(
                yourReference,
                startDate,
                locationVenueIds: new[] { venueId },
                website,
                isComplete: true);

            var journeyInstance   = CreateJourneyInstance(provider.ProviderId, journeyState);
            var journeyInstanceId = journeyInstance.InstanceId;

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/t-levels/add/check-publish?providerId={provider.ProviderId}&ffiid={journeyInstanceId.UniqueKey}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var doc = await response.GetDocument();

            using (new AssertionScope())
            {
                doc.GetSummaryListValueWithKey("Your reference").Should().Be(yourReference);
                doc.GetSummaryListValueWithKey("Start date").Should().Be($"{startDate:d MMMM yyyy}");
                doc.GetSummaryListValueWithKey("Venue").Should().Be(venueName);
                doc.GetSummaryListValueWithKey("T Level webpage").Should().Be(website);
                doc.GetSummaryListValueWithKey("Who this T Level is for").Should().Be(whoFor);
                doc.GetSummaryListValueWithKey("Entry requirements").Should().Be(entryRequirements);
                doc.GetSummaryListValueWithKey("What you'll learn").Should().Be(whatYoullLearn);
                doc.GetSummaryListValueWithKey("How you'll learn").Should().Be(howYoullLearn);
                doc.GetSummaryListValueWithKey("How you'll be assessed").Should().Be(howYoullBeAssessed);
                doc.GetSummaryListValueWithKey("What you can do next").Should().Be(whatYouCanDoNext);
            }
        }