Exemplo n.º 1
0
        public void WhenAddressesGatewayThrowsAnExceptionThenUsecasePopulatesTheMetadataErrorField()
        {
            // arrange
            var request = Randomm.Create <GetServiceByIdRequest>();

            request.PostCode = Randomm.Postcode();

            var expectedService = EntityHelpers.CreateService().ToDomain();

            _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService);

            var expectedException = new Exception(Randomm.Text());

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Throws(expectedException);

            // act
            var usecaseResponse = _classUnderTest.ExecuteGet(request);

            // assert
            usecaseResponse.Service.Locations.Should().OnlyContain(l => l.Distance == null);
            usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode);
            usecaseResponse.Metadata.PostCodeLatitude.Should().Be(null);
            usecaseResponse.Metadata.PostCodeLongitude.Should().Be(null);
            usecaseResponse.Metadata.Error.Should().Be(expectedException.Message);
        }
        public void GivenSearchParametersWhenSearchServicesGatewayMethodIsCalledThenItReturnsMatchingRecordsWithOrgNameHigherThanServiceName()
        {
            // arrange
            var services   = EntityHelpers.CreateServices(10);
            var searchTerm = Randomm.Text();

            services.First().Name += searchTerm;
            services[1].Organization.Name += searchTerm;
            var expectedData = new List <Service>();

            expectedData.Add(services.First());
            expectedData.Add(services[1]);
            var requestParams = new SearchServicesRequest();

            requestParams.Search = searchTerm;
            DatabaseContext.Services.AddRange(services);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.SearchServices(requestParams);
            var fullMatches   = gatewayResult.FullMatchServices;

            // assert
            gatewayResult.Should().NotBeNull();
            fullMatches.Should().NotBeNull();
            fullMatches.Count.Should().Be(2);
            fullMatches[0].Name.Should().Be(services[1].Name);
            fullMatches[1].Name.Should().Be(services[0].Name);
        }
Exemplo n.º 3
0
        public void WhenAddressesGatewayThrowsAnExceptionThenGetMultipleUsecasePopulatesTheMetadataErrorField()
        {
            // arrange
            var request = Randomm.Create <SearchServicesRequest>();

            request.PostCode = Randomm.Postcode();

            var gatewayResponse = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(gatewayResponse);

            var expectedException = new Exception(Randomm.Text());

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Throws(expectedException);

            // act
            var usecaseResponse = _classUnderTest.ExecuteGet(request);

            // assert
            usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode);
            usecaseResponse.Metadata.PostCodeLatitude.Should().Be(null);
            usecaseResponse.Metadata.PostCodeLongitude.Should().Be(null);
            usecaseResponse.Metadata.Error.Should().Be(expectedException.Message);
            usecaseResponse.Services.Should().OnlyContain(s => s.Locations.All(l => l.Distance == null));
        }
Exemplo n.º 4
0
        public async Task PatchOrganisationUpdatesOrganisation()
        {
            var session = EntityHelpers.CreateSession("Admin");

            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Organisations.Add(organisation);
            DatabaseContext.SaveChanges();
            var updOrganisation = new OrganisationRequest();

            updOrganisation.Name            = Randomm.Text();
            updOrganisation.ReviewerMessage = null; // we are assuming null means no change to the record
            var         organisationString = JsonConvert.SerializeObject(updOrganisation);
            HttpContent patchContent       = new StringContent(organisationString, Encoding.UTF8, "application/json");
            var         requestUri         = new Uri($"api/v1/organisations/{organisation.Id}", UriKind.Relative);
            var         response           = await Client.PatchAsync(requestUri, patchContent).ConfigureAwait(false);

            patchContent.Dispose();
            response.StatusCode.Should().Be(200);
            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <OrganisationResponse>(stringResponse);
            var organisationId   = deserializedBody.Id;
            var dbOrganisation   = DatabaseContext.Organisations.Find(organisationId);

            dbOrganisation.Should().NotBeNull();
            dbOrganisation.Name.Should().Be(organisation.Name);
            dbOrganisation.ReviewerMessage.Should().Be(organisation.ReviewerMessage);  //should not be set to null if not changed
        }
        public void GivenSearchParametersWhenSearchServicesGatewayMethodIsCalledThenItReturnsResultsMatchingNameAndDescription()
        {
            // arrange
            var services   = EntityHelpers.CreateServices(10);
            var searchTerm = Randomm.Text();

            searchTerm = " " + searchTerm;//15 Feb 2021 - Change made so we only search for whole words in the service description! - So we add a space.

            services.First().Name += searchTerm;
            services[1].Description += searchTerm;
            var expectedData = new List <Service>();

            expectedData.Add(services.First());
            expectedData.Add(services[1]);
            var requestParams = new SearchServicesRequest();

            requestParams.Search = searchTerm;
            DatabaseContext.Services.AddRange(services);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.SearchServices(requestParams);
            var fullMatches   = gatewayResult.FullMatchServices;

            // assert
            gatewayResult.Should().NotBeNull();
            fullMatches.Should().NotBeNull();
            fullMatches.Count.Should().Be(2);
        }
Exemplo n.º 6
0
        public async Task GetServicesBySearchParamsReturnServicesIfMatched()
        {
            var services         = EntityHelpers.CreateServices().ToList();
            var expectedResponse = new GetServiceResponseList();

            expectedResponse.Services = new List <R.Service>();
            var serviceToFind1 = EntityHelpers.CreateService();
            var serviceToFind2 = EntityHelpers.CreateService();
            var searchTerm     = Randomm.Text();

            serviceToFind1.Name += searchTerm;
            serviceToFind2.Name += searchTerm;
            expectedResponse.Services.Add(serviceToFind1.ToDomain().ToResponse().Service);
            expectedResponse.Services.Add(serviceToFind2.ToDomain().ToResponse().Service);
            await DatabaseContext.Services.AddRangeAsync(services).ConfigureAwait(true);

            await DatabaseContext.Services.AddAsync(serviceToFind1).ConfigureAwait(true);

            await DatabaseContext.Services.AddAsync(serviceToFind2).ConfigureAwait(true);

            await DatabaseContext.SaveChangesAsync().ConfigureAwait(true);

            var requestUri = new Uri($"api/v1/services?search={searchTerm}", UriKind.Relative);
            var response   = Client.GetAsync(requestUri).Result;

            response.StatusCode.Should().Be(200);
            var content       = response.Content;
            var stringContent = await content.ReadAsStringAsync().ConfigureAwait(false);

            var deserializedBody = JsonConvert.DeserializeObject <GetServiceResponseList>(stringContent);

            deserializedBody.Services.Count.Should().Be(2);
        }
        public void PercentCharacterStringGetsReturned()
        {
            var searchTerm    = Randomm.Text().Replace(" ", "%");
            var decodedParams = UrlHelper.DecodeParams(searchTerm);

            decodedParams.Should().Be(searchTerm);
        }
        public void DoubleUrlEncodedStringGetsDecoded()
        {
            var searchTerm       = Randomm.Text();
            var urlencodedSearch = searchTerm.Replace(" ", "%2520");
            var decodedParams    = UrlHelper.DecodeParams(urlencodedSearch);

            decodedParams.Should().Be(searchTerm);
        }
Exemplo n.º 9
0
        public void GivenAUrlEncodedSearchTermGatewayIsCalledWithDecodedTerm() // implementation of this test fixes a front-end bug, where front-end app accidentally encodes the url twice before calling an API - I don't we should be 'fixing' this on back-end API.
        {
            var expectedServices = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(expectedServices); // dummy setup - irrelevant for the test
            var searchTerm       = Randomm.Text();
            var urlencodedSearch = searchTerm.Replace(" ", "%2520");
            var reqParams        = new SearchServicesRequest();

            reqParams.Search = urlencodedSearch;
            _classUnderTest.ExecuteGet(reqParams);
            _mockServicesGateway.Verify(g => g.SearchServices(It.Is <SearchServicesRequest>(p => p.Search == searchTerm)), Times.Once);
        }
        public void GivenAnyNumberOfErrorStringParametersWhenErrorResponseConstructorIsCalledThenItInitializesErrorsFieldToAListOfErrorStringsCorrespondingToPassedInParameters()
        {
            //act
            Func <string> error = () => { return(Randomm.Text()); };

            var singleParameterErrorResponse = new ErrorResponse(error());
            var fourParameterErrorResponse   = new ErrorResponse(error(), error(), error(), error());
            var sevenParameterErrorResponse  = new ErrorResponse(error(), error(), error(), error(), error(), error(), error());

            //assert
            singleParameterErrorResponse.Errors.Count.Should().Be(1);
            fourParameterErrorResponse.Errors.Count.Should().Be(4);
            sevenParameterErrorResponse.Errors.Count.Should().Be(7);
        }
Exemplo n.º 11
0
        public void GivenAnSynonymWordAMatchingSynonymWordGetsUpdated()
        {
            var synonymWord = EntityHelpers.CreateSynonymWord();

            DatabaseContext.Add(synonymWord);
            DatabaseContext.SaveChanges();
            var synonymWordDomain = _mapper.ToDomain(synonymWord);

            synonymWordDomain.Word = Randomm.Text();
            _classUnderTest.PatchSynonymWord(synonymWordDomain);
            var expectedResult = DatabaseContext.SynonymWords.Find(synonymWord.Id);

            expectedResult.Should().BeEquivalentTo(synonymWordDomain, options =>
            {
                return(options);
            });
        }
        public void GivenATaxonomyTaxonomyGetsUpdated()
        {
            var taxonomy = EntityHelpers.CreateTaxonomy();

            DatabaseContext.Add(taxonomy);
            DatabaseContext.SaveChanges();
            var newTaxonomy = taxonomy;

            newTaxonomy.Description = Randomm.Text();
            _classUnderTest.PatchTaxonomy(taxonomy.Id, newTaxonomy);
            var gatewayResult = DatabaseContext.Taxonomies.Find(taxonomy.Id);

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(_mapper.ToDomain(newTaxonomy), options =>
            {
                return(options);
            });
        }
Exemplo n.º 13
0
        public void GivenAnSynonymGroupAMatchingSynonymGroupGetsUpdated()
        {
            var synonymGroup = EntityHelpers.CreateSynonymGroup();

            DatabaseContext.Add(synonymGroup);
            DatabaseContext.SaveChanges();
            var synonymGroupDomain = _mapper.ToDomain(synonymGroup);

            synonymGroupDomain.Name = Randomm.Text();
            _classUnderTest.PatchSynonymGroup(synonymGroupDomain);
            var expectedResult = DatabaseContext.SynonymGroups.Find(synonymGroup.Id);

            expectedResult.Should().BeEquivalentTo(synonymGroupDomain, options =>
            {
                options.Excluding(ex => ex.SynonymWords);
                return(options);
            });
        }
Exemplo n.º 14
0
        public void FactoryPopulatesTheMetadataFieldWithWhatIsPassedInAsAnArgument()
        {
            // arrange
            var expectedMetadata = new Metadata
            {
                Error             = Randomm.Text(),
                PostCode          = Randomm.Postcode(),
                PostCodeLatitude  = Randomm.Latitude(),
                PostCodeLongitude = Randomm.Longitude()
            };

            // act
            var factoryResult = ServiceFactory.SearchServiceUsecaseResponse(null, null, expectedMetadata);

            // assert
            factoryResult.Metadata.Error.Should().Be(expectedMetadata.Error);
            factoryResult.Metadata.PostCode.Should().Be(expectedMetadata.PostCode);
            factoryResult.Metadata.PostCodeLatitude.Should().Be(expectedMetadata.PostCodeLatitude);
            factoryResult.Metadata.PostCodeLongitude.Should().Be(expectedMetadata.PostCodeLongitude);
        }
        public void GivenAnOrganisationAMatchingOrganisationGetsUpdated()
        {
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Add(organisation);
            DatabaseContext.SaveChanges();
            var organisationDomain = _mapper.ToDomain(organisation);

            organisationDomain.Name = Randomm.Text();
            _classUnderTest.PatchOrganisation(organisationDomain);
            var expectedResult = DatabaseContext.Organisations.Find(organisation.Id);

            expectedResult.Should().BeEquivalentTo(organisationDomain, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                options.Excluding(ex => ex.StatusMessage);
                return(options);
            });
        }