Пример #1
0
        public SearchTests(FindACourseApiApplicationFactory factory)
            : base(factory)
        {
            FindACourseOfferingSearchClient
            .Setup(c => c.Search(It.IsAny <FindACourseOfferingSearchQuery>()))
            .Callback <FindACourseOfferingSearchQuery>(q => CapturedQuery = q)
            .ReturnsAsync(new SearchResult <FindACourseOffering>()
            {
                Facets = new Dictionary <string, IReadOnlyDictionary <object, long?> >()
                {
                    { "NotionalNVQLevelv2", new Dictionary <object, long?>() },
                    { "VenueStudyMode", new Dictionary <object, long?>() },
                    { "VenueAttendancePattern", new Dictionary <object, long?>() },
                    { "DeliveryMode", new Dictionary <object, long?>() },
                    { "ProviderName", new Dictionary <object, long?>() },
                    { "Region", new Dictionary <object, long?>() },
                },
                Items      = Array.Empty <SearchResultItem <FindACourseOffering> >(),
                TotalCount = 0
            });

            OnspdSearchClient
            .Setup(c => c.Search(It.IsAny <OnspdSearchQuery>()))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items      = Array.Empty <SearchResultItem <Onspd> >(),
                TotalCount = null
            });
        }
        public async Task PostcodeSearch_PostcodeNotInOnspdData_RendersError()
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var town     = "Town";
            var postcode = "AB1 2DE";

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == postcode)))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = Array.Empty <SearchResultItem <Onspd> >()
            });

            ConfigureAddressSearchServiceResults(postcode, town, resultCount: 3);

            var journeyInstance = CreateJourneyInstance(provider.ProviderId);

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"/venues/add/postcode-search?providerId={provider.ProviderId}&ffiid={journeyInstance.InstanceId.UniqueKey}&postcode={postcode}");

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

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

            var doc = await response.GetDocument();

            doc.AssertHasError("Postcode", "Enter a real postcode");
        }
Пример #3
0
        public async Task Post_InvalidAddress_RendersError(
            string addressLine1,
            string addressLine2,
            string town,
            string county,
            string postcode,
            string expectedErrorInputId,
            string expectedErrorMessage)
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var postcodeLatitude  = 42M;
            var postcodeLongitude = 43M;

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == postcode)))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = postcode,
                            Country = "England",
                            lat     = postcodeLatitude,
                            @long   = postcodeLongitude
                        }
                    }
                }
            });

            var journeyInstance = CreateJourneyInstance(provider.ProviderId);

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/venues/add/address?providerId={provider.ProviderId}&ffiid={journeyInstance.InstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("AddressLine1", addressLine1)
                          .Add("AddressLine2", addressLine2)
                          .Add("Town", town)
                          .Add("County", county)
                          .Add("Postcode", postcode)
                          .ToContent()
            };

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

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

            var doc = await response.GetDocument();

            doc.AssertHasError(expectedErrorInputId, expectedErrorMessage);
        }
Пример #4
0
        public async Task Post_ValidRequest_UpdatesFormFlowInstanceAndRedirects(
            string onspdRecordPostcode,
            bool expectedNewAddressIsOutsideOfEnglandValue)
        {
            // Arrange
            var providerId = await TestData.CreateProvider();

            var venueId = await TestData.CreateVenue(providerId);

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == "CV1 2AA")))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Results = new[]
                {
                    new Onspd()
                    {
                        pcds    = "CV1 2AA",
                        Country = onspdRecordPostcode,
                        lat     = 42M,
                        @long   = 43M
                    }
                }
            });

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("AddressLine1", "Updated address line 1")
                                 .Add("AddressLine2", "Updated address line 2")
                                 .Add("Town", "Updated town")
                                 .Add("County", "Updated county")
                                 .Add("Postcode", "CV1 2AA")
                                 .ToContent();

            var request = new HttpRequestMessage(HttpMethod.Post, $"venues/{venueId}/address")
            {
                Content = requestContent
            };

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

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Redirect);
            response.Headers.Location.OriginalString.Should().Be($"/venues/{venueId}");

            using (new AssertionScope())
            {
                var formFlowInstance = GetFormFlowInstance(venueId);
                formFlowInstance.State.AddressLine1.Should().Be("Updated address line 1");
                formFlowInstance.State.AddressLine2.Should().Be("Updated address line 2");
                formFlowInstance.State.Town.Should().Be("Updated town");
                formFlowInstance.State.County.Should().Be("Updated county");
                formFlowInstance.State.Postcode.Should().Be("CV1 2AA");
                formFlowInstance.State.Latitude.Should().Be(42M);
                formFlowInstance.State.Longitude.Should().Be(43M);
                formFlowInstance.State.NewAddressIsOutsideOfEngland.Should().Be(expectedNewAddressIsOutsideOfEnglandValue);
            }
        }
Пример #5
0
        public async Task Post_JourneyIsCompleted_ReturnsConflict()
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var addressLine1 = "Test Venue line 1";
            var addressLine2 = "Test Venue line 2";
            var town         = "Town";
            var county       = "County";
            var country      = "England";
            var postcode     = "AB1 2DE";

            var postcodeLatitude  = 42M;
            var postcodeLongitude = 43M;

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == postcode)))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = postcode,
                            Country = country,
                            lat     = postcodeLatitude,
                            @long   = postcodeLongitude
                        }
                    }
                }
            });

            var journeyInstance = CreateJourneyInstance(provider.ProviderId);

            GetJourneyInstance <AddVenueJourneyModel>(journeyInstance.InstanceId).Complete();

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/venues/add/address?providerId={provider.ProviderId}&ffiid={journeyInstance.InstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("AddressLine1", addressLine1)
                          .Add("AddressLine2", addressLine2)
                          .Add("Town", town)
                          .Add("County", county)
                          .Add("Postcode", postcode)
                          .ToContent()
            };

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

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Conflict);
        }
        public async Task Post_InvalidAddress_RendersError(
            string addressLine1,
            string addressLine2,
            string town,
            string county,
            string postcode,
            string expectedErrorInputId,
            string expectedErrorMessage)
        {
            // Arrange
            var provider = await TestData.CreateProvider();

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

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == "CV1 2AA")))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = postcode,
                            Country = "England",
                            lat     = 42M,
                            @long   = 43M
                        }
                    }
                }
            });

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("AddressLine1", addressLine1)
                                 .Add("AddressLine2", addressLine2)
                                 .Add("Town", town)
                                 .Add("County", county)
                                 .Add("Postcode", postcode)
                                 .ToContent();

            var request = new HttpRequestMessage(HttpMethod.Post, $"venues/{venueId}/address")
            {
                Content = requestContent
            };

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

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

            var doc = await response.GetDocument();

            doc.AssertHasError(expectedErrorInputId, expectedErrorMessage);
        }
        public async Task Post_UserCannotAccessVenue_ReturnsForbidden(TestUserType userType)
        {
            // Arrange
            var provider = await TestData.CreateProvider();

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

            var anotherProvider = await TestData.CreateProvider();

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == "CV1 2AA")))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = "CV1 2AA",
                            Country = "England",
                            lat     = 42M,
                            @long   = 43M
                        }
                    }
                }
            });

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("AddressLine1", "Updated address line 1")
                                 .Add("AddressLine2", "Updated address line 2")
                                 .Add("Town", "Updated town")
                                 .Add("County", "Updated county")
                                 .Add("Postcode", "CV1 2AA")
                                 .ToContent();

            var request = new HttpRequestMessage(HttpMethod.Post, $"venues/{venueId}/address")
            {
                Content = requestContent
            };

            await User.AsTestUser(userType, anotherProvider.ProviderId);

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

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
        public async Task Post_VenueDoesNotExist_ReturnsNotFound()
        {
            // Arrange
            var venueId = Guid.NewGuid();

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == "CV1 2AA")))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = "CV1 2AA",
                            Country = "England",
                            lat     = 42M,
                            @long   = 43M
                        }
                    }
                }
            });

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("AddressLine1", "Updated address line 1")
                                 .Add("AddressLine2", "Updated address line 2")
                                 .Add("Town", "Updated town")
                                 .Add("County", "Updated county")
                                 .Add("Postcode", "CV1 2AA")
                                 .ToContent();

            var request = new HttpRequestMessage(HttpMethod.Post, $"venues/{venueId}/address")
            {
                Content = requestContent
            };

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

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
Пример #9
0
        public async Task Post_ValidRequest_UpdatesJourneyInstanceAndRedirects(
            string onspdRecordCountry,
            bool expectedNewAddressIsOutsideOfEnglandValue)
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var addressLine1 = "Test Venue line 1";
            var addressLine2 = "Test Venue line 2";
            var town         = "Town";
            var county       = "County";
            var postcode     = "AB1 2DE";

            var postcodeLatitude  = 42M;
            var postcodeLongitude = 43M;

            OnspdSearchClient
            .Setup(c => c.Search(It.Is <OnspdSearchQuery>(q => q.Postcode == postcode)))
            .ReturnsAsync(new SearchResult <Onspd>()
            {
                Items = new[]
                {
                    new SearchResultItem <Onspd>()
                    {
                        Record = new Onspd()
                        {
                            pcds    = postcode,
                            Country = onspdRecordCountry,
                            lat     = postcodeLatitude,
                            @long   = postcodeLongitude
                        }
                    }
                }
            });

            var journeyInstance = CreateJourneyInstance(provider.ProviderId);

            var request = new HttpRequestMessage(
                HttpMethod.Post,
                $"/venues/add/address?providerId={provider.ProviderId}&ffiid={journeyInstance.InstanceId.UniqueKey}")
            {
                Content = new FormUrlEncodedContentBuilder()
                          .Add("AddressLine1", addressLine1)
                          .Add("AddressLine2", addressLine2)
                          .Add("Town", town)
                          .Add("County", county)
                          .Add("Postcode", postcode)
                          .ToContent()
            };

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

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

            response.Headers.Location.OriginalString.Should()
            .Be($"/venues/add/details?providerId={provider.ProviderId}&ffiid={journeyInstance.InstanceId.UniqueKey}");

            using (new AssertionScope())
            {
                journeyInstance = GetJourneyInstance <AddVenueJourneyModel>(journeyInstance.InstanceId);
                journeyInstance.State.AddressLine1.Should().Be(addressLine1);
                journeyInstance.State.AddressLine2.Should().Be(addressLine2);
                journeyInstance.State.Town.Should().Be(town);
                journeyInstance.State.County.Should().Be(county);
                journeyInstance.State.Postcode.Should().Be(postcode);
                journeyInstance.State.Latitude.Should().Be(postcodeLatitude);
                journeyInstance.State.Longitude.Should().Be(postcodeLongitude);
                journeyInstance.State.AddressIsOutsideOfEngland.Should().Be(expectedNewAddressIsOutsideOfEnglandValue);
            }
        }