Exemple #1
0
        public async Task GivenRequestWithFilterParameterWhenGetTaxonomiesEndpointIsCalledThenItReturnsOnlyFilteredTaxonomies()
        {
            // arrange
            var vocabularyFP = Randomm.Create <string>();

            var taxonomies = EntityHelpers.CreateTaxonomies(5).ToList();

            taxonomies[1].Vocabulary = vocabularyFP;
            taxonomies[3].Vocabulary = vocabularyFP;
            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            // act
            var requestUri = new Uri($"api/v1/taxonomies?vocabulary={vocabularyFP}", UriKind.Relative);
            var response   = Client.GetAsync(requestUri).Result;

            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <TaxonomyResponseList>(stringResponse);

            // assert
            response.StatusCode.Should().Be(200);
            deserializedBody.Taxonomies.Count.Should().Be(2);
        }
        public void GivenIdThatDoesNotHaveAMatchWhenGetTaxonomyGatewayMethodIsCalledThenItReturnsNull()
        {
            // arrange
            var taxonomies = EntityHelpers.CreateTaxonomies();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var id = Randomm.Id();

            // act
            var gatewayResult = _classUnderTest.GetTaxonomy(id);

            // assert
            gatewayResult.Should().BeNull();
        }
        public void GivenNoTaxonomyVocabularyIdAllTaxonomiesAreReturned()
        {
            var taxonomies = EntityHelpers.CreateTaxonomies(3).ToList();

            DatabaseContext.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var gatewayResult  = _classUnderTest.GetAllTaxonomies();
            var expectedResult = DatabaseContext.Taxonomies.AsQueryable();

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult, options =>
            {
                options.Excluding(ex => ex.ServiceTaxonomies);
                return(options);
            });
        }
Exemple #4
0
        public async Task GivenRequestWithNoFilterParamterWhenGetTaxonomiesEndpointIsCalledThenItReturnsAllTaxonomies()
        {
            var taxonomies = EntityHelpers.CreateTaxonomies().ToList();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();
            var requestUri = new Uri("api/v1/taxonomies", UriKind.Relative);
            var response   = Client.GetAsync(requestUri).Result;

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

            var deserializedBody = JsonConvert.DeserializeObject <TaxonomyResponseList>(stringResponse);

            deserializedBody.Taxonomies.Count.Should().Be(taxonomies.Count);
        }
        public void GivenAFilterParameterAndNoMatchingResultsWhenGetTaxonomiesGatewayMethodIsCalledThenItReturnsEmptyCollection()
        {
            // arrange
            var vocabularyFP = Randomm.Create <string>();

            var taxonomies = EntityHelpers.CreateTaxonomies();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.GetTaxonomies(vocabularyFP).ToList();

            // assert
            gatewayResult.Should().NotBeNull();
            gatewayResult.Count.Should().Be(0);
        }
        public void GivenIdThatHasAMatchWhenGetTaxonomyGatewayMethodIsCalledThenItReturnsMatchingTaxonomyDomainObject()
        {
            // arrange
            var taxonomies = EntityHelpers.CreateTaxonomies();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var expectedResult = DatabaseContext.Taxonomies.First();
            var expectedId     = expectedResult.Id;

            // act
            var gatewayResult = _classUnderTest.GetTaxonomy(expectedId);

            // assert
            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult);
        }
        public void GivenAFilterParameterWhenGetTaxonomiesGatewayMethodIsCalledThenItReturnsOnlyFilteredTaxonomies() // GatewayReturnsOnlyFilteredTaxonomies
        {
            // arrange
            var vocabularyFP = Randomm.Create <string>();

            var taxonomies = EntityHelpers.CreateTaxonomies(5).ToList();

            taxonomies[1].Vocabulary = vocabularyFP;
            taxonomies[3].Vocabulary = vocabularyFP;
            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.GetTaxonomies(vocabularyFP).ToList();

            // assert
            gatewayResult.Count.Should().Be(2);
            gatewayResult.Should().BeEquivalentTo(taxonomies.Where(x => x.Vocabulary == vocabularyFP));
        }
        public void GivenATaxonomyVocabularyIdMatchingTaxonomiesAreReturned()
        {
            var taxonomies = EntityHelpers.CreateTaxonomies(3).ToList();

            taxonomies[0].Vocabulary = "category";
            taxonomies[1].Vocabulary = "demographic";
            taxonomies[2].Vocabulary = "demographic";
            DatabaseContext.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var gatewayResult  = _classUnderTest.GetTaxonomiesByVocabulary("demographic");
            var expectedResult = DatabaseContext.Taxonomies.Where(v => v.Vocabulary == "demographic");

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult, options =>
            {
                options.Excluding(ex => ex.ServiceTaxonomies);
                return(options);
            });
        }
        public void GivenAFilterParameterAndAMatchingTaxonomyWithMultipleConcatinatedFilterValuesWhenGetTaxonomiesGatewayMethodIsCalledThenItReturnsOnlyFilteredTaxonomies() // GatewayReturnsOnlyFilteredTaxonomies
        {
            // arrange
            var vocabularyFP = Randomm.Create <string>();

            var taxonomies = EntityHelpers.CreateTaxonomies(7).ToList();

            taxonomies[1].Vocabulary = $"{vocabularyFP} {Randomm.Create<string>()}";                              // matching value in front
            taxonomies[3].Vocabulary = $"{Randomm.Create<string>()} {vocabularyFP}";                              // matching value at the back
            taxonomies[4].Vocabulary = $"{Randomm.Create<string>()} {vocabularyFP} {Randomm.Create<string>()}";   // matching value in the middle
            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.GetTaxonomies(vocabularyFP).ToList();

            // assert
            gatewayResult.Count.Should().Be(3);
            gatewayResult.Should().BeEquivalentTo(taxonomies.Where(x => x.Vocabulary.Contains(vocabularyFP, System.StringComparison.OrdinalIgnoreCase)));
        }
        public void GivenAFilterParameterWhenGetTaxonomiesGatewayMethodIsCalledThenItReturnsAllCorrectlyFilteredTaxonomiesRegardlesOfStringCase() // GatewayReturnsOnlyFilteredTaxonomies
        {
            // arrange
            var vocabularyFP = Randomm.Create <string>().ToLower();

            var taxonomies = EntityHelpers.CreateTaxonomies(7).ToList();

            //DB will contain upper case, while filter param will be lower case
            taxonomies[1].Vocabulary = vocabularyFP.ToUpper();
            taxonomies[5].Vocabulary = $"{Randomm.Create<string>()} {vocabularyFP.ToUpper()} {Randomm.Create<string>()}";
            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            // act
            var gatewayResult = _classUnderTest.GetTaxonomies(vocabularyFP).ToList();

            // assert
            gatewayResult.Count.Should().Be(2);
            gatewayResult.Should().BeEquivalentTo(taxonomies.Where(x => x.Vocabulary.Contains(vocabularyFP, System.StringComparison.OrdinalIgnoreCase)));
        }
Exemple #11
0
        public async Task GivenRequestWithIdThatDoesNotHaveAMatchWhenGetTaxonomyEndpointIsCalledThenItReturnsA404Response()
        {
            // arrange
            var taxonomies = EntityHelpers.CreateTaxonomies().ToList();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var nonMatchingId = Randomm.Id();
            var expectedValue = new ErrorResponse($"Taxonomy with an Id: {nonMatchingId} was not found.");

            // act
            var requestUri = new Uri($"api/v1/taxonomies/{nonMatchingId}", UriKind.Relative);
            var response   = Client.GetAsync(requestUri).Result;

            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <ErrorResponse>(stringResponse);

            // assert
            response.StatusCode.Should().Be(404);
            deserializedBody.Should().BeEquivalentTo(expectedValue);
        }
Exemple #12
0
        public async Task GivenRequestWithIdWhenGetTaxonomyEndpointIsCalledThenItReturnsSingleMatchingTaxonomy()
        {
            // arrange
            var taxonomies = EntityHelpers.CreateTaxonomies().ToList();

            DatabaseContext.Taxonomies.AddRange(taxonomies);
            DatabaseContext.SaveChanges();

            var matchTaxonomy = DatabaseContext.Taxonomies.FirstOrDefault().ToDomain();
            var expectedId    = matchTaxonomy.Id;

            // act
            var requestUri = new Uri($"api/v1/taxonomies/{expectedId}", UriKind.Relative);
            var response   = Client.GetAsync(requestUri).Result;

            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <TaxonomyResponse>(stringResponse);

            // assert
            response.StatusCode.Should().Be(200);
            deserializedBody.Should().BeEquivalentTo(matchTaxonomy.ToResponse());
        }