Esempio n. 1
0
        public static async Task GetBuyerOrganisationByOdsCode_WithValidResponse_Returns_BuyerOrganisation()
        {
            var context = OdsRepositoryTestContext.Setup();

            using var httpTest = new HttpTest();
            httpTest.RespondWith(status: 200, body: ValidResponseBody);

            var expected = new OdsOrganisation
            {
                OdsCode          = OdsCode,
                OrganisationName = "SOUTH EAST - H&J COMMISSIONING HUB",
                PrimaryRoleId    = "RO98",
                Address          = new Address
                {
                    Line1    = "C/O NHS ENGLAND",
                    Line2    = "1W09, 1ST FLOOR, QUARRY HOUSE",
                    Line3    = "QUARRY HILL",
                    Town     = "LEEDS",
                    Postcode = "LS2 7UA",
                    Country  = "ENGLAND",
                },
                IsActive            = true,
                IsBuyerOrganisation = true,
            };
            var actual = await context.OdsRepository.GetBuyerOrganisationByOdsCodeAsync(OdsCode);

            actual.Should().BeOfType <OdsOrganisation>();
            actual.Should().NotBeNull();

            actual.Should().BeEquivalentTo(expected);
        }
Esempio n. 2
0
        public static void GetBuyerOrganisationByOdsCode_WithInternalServerErrorResponseFromOdsApi_Throws()
        {
            var context = OdsRepositoryTestContext.Setup();

            using var httpTest = new HttpTest();
            httpTest.RespondWith(status: 500);

            Assert.ThrowsAsync <FlurlHttpException>(async() => await context.OdsRepository.GetBuyerOrganisationByOdsCodeAsync("invalid"));
        }
Esempio n. 3
0
        public static void GetBuyerOrganisationByOdsCode_InvalidOdsCode_ThrowsException(string invalid)
        {
            var context = OdsRepositoryTestContext.Setup();

            using var httpTest = new HttpTest();
            httpTest.RespondWith(status: 500);

            Assert.ThrowsAsync <ArgumentException>(
                async() => await context.OdsRepository.GetBuyerOrganisationByOdsCodeAsync(invalid))
            .Message.Should().Be($"A valid odsCode is required for this call");
        }
        public async Task GetBuyerOrganisationByOdsCode_WithNotFoundResponseFromOdsApi_Returns_Null()
        {
            var context = OdsRepositoryTestContext.Setup();

            using var httpTest = new HttpTest();
            httpTest.RespondWithJson(new { ErrorCode = 404, ErrorText = "Not Found." }, 404);

            var result = await context.OdsRepository.GetBuyerOrganisationByOdsCodeAsync(OdsCode);

            result.Should().BeNull();
        }
        public async Task GetBuyerOrganisationByOdsCode_CallsOdsApi_Once()
        {
            var context = OdsRepositoryTestContext.Setup();

            using var httpTest = new HttpTest();
            httpTest.RespondWith(status: 200, body: ValidResponseBody);

            await context.OdsRepository.GetBuyerOrganisationByOdsCodeAsync(OdsCode);

            httpTest.ShouldHaveCalled($"{context.OdsSettings.ApiBaseUrl}/organisations/{OdsCode}")
            .WithVerb(HttpMethod.Get)
            .Times(1);
        }
Esempio n. 6
0
        public static async Task GetBuyerOrganisationByOdsCode_WithNotFoundResponseFromOdsApi_Returns_Null()
        {
            const string odsCode        = "ods-code-839";
            var          context        = OdsRepositoryTestContext.Setup();
            var          url            = $"{context.OdsSettings.ApiBaseUrl}/organisations/{odsCode}";
            var          cachingService = new CachingService();

            cachingService.CacheProvider.Remove(odsCode);

            var repository = new OdsRepository(context.OdsSettings, cachingService);

            using var httpTest = new HttpTest();
            httpTest
            .ForCallsTo(url)
            .RespondWithJson(new { ErrorCode = 404, ErrorText = "Not Found." }, 404);

            var result = await repository.GetBuyerOrganisationByOdsCodeAsync(odsCode);

            httpTest.ShouldHaveCalled(url)
            .WithVerb(HttpMethod.Get)
            .Times(1);
            result.Should().BeNull();
        }