public async Task Then_If_Throws_Exception_Returns_False()
        {
            //Arrange
            var response = new HttpResponseMessage
            {
                Content        = new StringContent(JsonConvert.SerializeObject("test")),
                StatusCode     = HttpStatusCode.BadRequest,
                ReasonPhrase   = "test",
                RequestMessage = new HttpRequestMessage()
            };
            var httpMessageHandler = SetupMessageHandlerMock(response, new Uri("https://test.local/ping"), HttpMethod.Get);

            var mockClient = new Mock <IRoatpApiHttpClientFactory>();

            mockClient.Setup(x => x.CreateRestHttpClient()).Returns(new RestHttpClient(new HttpClient(httpMessageHandler.Object)
            {
                BaseAddress = new Uri("https://test.local/")
            }));
            var service = new RoatpService(mockClient.Object);

            //Act
            var actual = await service.Ping();

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #2
0
        public ImportProvidersJobTestsFixture SetProviders(int count)
        {
            Providers = Enumerable.Range(1, count)
                        .Select(i => new ProviderRegistration
            {
                Ukprn        = i,
                ProviderName = i.ToString()
            })
                        .ToList();

            RoatpService.Setup(c => c.GetProviders()).ReturnsAsync(Providers);

            return(this);
        }
        public async Task Then_The_Endpoint_Is_Called_And_Roatp_Data_Returned()
        {
            //Arrange
            var responseModel = new List <ProviderRegistration>
            {
                new ProviderRegistration
                {
                    Ukprn        = 1,
                    ProviderName = "Test"
                },
                new ProviderRegistration
                {
                    Ukprn        = 2,
                    ProviderName = "Test 2"
                },
            };
            var content = new StringContent(JsonConvert.SerializeObject(responseModel));

            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            var response = new HttpResponseMessage
            {
                Content    = content,
                StatusCode = HttpStatusCode.Accepted
            };
            var httpMessageHandler = SetupMessageHandlerMock(response, new Uri("https://test.local/api/v1/fat-data-export"), HttpMethod.Get);
            var mockClient         = new Mock <IRoatpApiHttpClientFactory>();

            mockClient.Setup(x => x.CreateRestHttpClient()).Returns(new RestHttpClient(new HttpClient(httpMessageHandler.Object)
            {
                BaseAddress = new Uri("https://test.local/"),
            }));
            var service = new RoatpService(mockClient.Object);

            //Act
            var actual = await service.GetProviders();

            actual.Should().BeEquivalentTo(responseModel);
        }
        public async Task Then_The_Url_Is_Called_And_Data_Returned()
        {
            //Arrange
            var fixture         = new Fixture();
            var identifier      = fixture.Create <string>();
            var providersUrl    = fixture.Create <string>();
            var authToken       = fixture.Create <string>();
            var importProviders = fixture.CreateMany <ProviderRegistration>();

            providersUrl = $"https://test.local/{providersUrl}/";

            var azureClientCredentialHelper = new Mock <IAzureClientCredentialHelper>();

            azureClientCredentialHelper.Setup(x => x.GetAccessTokenAsync(identifier)).ReturnsAsync(authToken);

            var configuration = new Mock <IOptions <RoatpApiConfiguration> >();

            configuration.Setup(x => x.Value).Returns(new RoatpApiConfiguration
            {
                Identifier = identifier,
                Url        = providersUrl
            });
            var response = new HttpResponseMessage
            {
                Content    = new StringContent(JsonConvert.SerializeObject(importProviders)),
                StatusCode = HttpStatusCode.Accepted
            };
            var httpMessageHandler    = SetupMessageHandlerMock(response, new Uri(providersUrl + "v1/fat-data-export"), HttpMethod.Get, authToken);
            var client                = new HttpClient(httpMessageHandler.Object);
            var apprenticeshipService = new RoatpService(client, azureClientCredentialHelper.Object, Mock.Of <IHostingEnvironment>(), configuration.Object);

            //Act
            var providers = await apprenticeshipService.GetAll();

            //Assert
            providers.Should().BeEquivalentTo(importProviders);
        }
        public async Task Then_The_Endpoint_Is_Called_And_True_Returned_If_Ok_Response()
        {
            //Arrange
            var response = new HttpResponseMessage
            {
                Content    = new StringContent(JsonConvert.SerializeObject("test")),
                StatusCode = HttpStatusCode.Accepted
            };
            var httpMessageHandler = SetupMessageHandlerMock(response, new Uri("https://test.local/ping"), HttpMethod.Get);

            var mockClient = new Mock <IRoatpApiHttpClientFactory>();

            mockClient.Setup(x => x.CreateRestHttpClient()).Returns(new RestHttpClient(new HttpClient(httpMessageHandler.Object)
            {
                BaseAddress = new Uri("https://test.local/")
            }));
            var service = new RoatpService(mockClient.Object);

            //Act
            var actual = await service.Ping();

            //Assert
            Assert.IsTrue(actual);
        }