public async Task TLevelGetAsyncReturnsHttpRequestExceptionWhenApiReturnsNotSuccessful()
        {
            // Arrange
            var httpResponse = new HttpResponseMessage {
                StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("{}")
            };

            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            var auditService = A.Fake <IAuditService>();

            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            var httpClient             = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri("http://SomeDummyUrl")
            };
            var findACourseClient = new FindACourseClient(httpClient, defaultSettings, auditService, defaultLogger);

            // Act
            await Assert.ThrowsAsync <HttpRequestException>(async() => await findACourseClient.TLevelGetAsync(tLevelId.ToString()).ConfigureAwait(false)).ConfigureAwait(false);

            // Assert
            httpResponse.Dispose();
            httpClient.Dispose();
            fakeHttpMessageHandler.Dispose();
        }
        public async Task TLevelGetAsyncReturnsResponseObjectWhenApiCallIsSuccessful()
        {
            // Arrange
            var expectedResponse = new TLevelDetailResponse
            {
                TLevelId      = tLevelId,
                Qualification = new TLevelQualification()
                {
                    TLevelName = "testTLevel"
                },
                Provider = new TLevelProvider()
                {
                    ProviderName = "testProvider"
                },
            };

            var httpResponse = new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(expectedResponse))
            };

            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            var auditService = A.Fake <IAuditService>();

            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            var httpClient             = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri("http://SomeDummyUrl")
            };

            var findACourseClient = new FindACourseClient(httpClient, defaultSettings, auditService, defaultLogger);

            // Act
            var result = await findACourseClient.TLevelGetAsync(tLevelId.ToString()).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedResponse.Qualification.TLevelName, result.Qualification.TLevelName);
            Assert.Equal(expectedResponse.Provider.ProviderName, result.Provider.ProviderName);
            Assert.Equal(expectedResponse.TLevelId, result.TLevelId);

            httpResponse.Dispose();
            httpClient.Dispose();
            fakeHttpMessageHandler.Dispose();
        }
        public async Task TLevelGetAsyncCatchesExceptionWhenApiReturnsNotSuccessful()
        {
            // Arrange
            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Throws <Exception>();

            var auditService = A.Fake <IAuditService>();

            using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            using var httpClient             = new HttpClient(fakeHttpMessageHandler)
                  {
                      BaseAddress = new Uri("http://SomeDummyUrl")
                  };
            var findACourseClient = new FindACourseClient(httpClient, defaultSettings, auditService, defaultLogger);

            // Act
            var result = await findACourseClient.TLevelGetAsync(tLevelId.ToString()).ConfigureAwait(false);

            // Assert
            Assert.Null(result);
        }