Ejemplo n.º 1
0
            public async Task SerialisesContentStringToNullWhenInvalid(string content)
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(content)));

                // Act
                var response = await Service.GetAsync();

                // Assert
                Assert.IsNull(response.Response);
            }
Ejemplo n.º 2
0
            public async Task SerialisesContentStringToCorrectObject(string content, string expectedName)
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(content)));

                // Act
                var response = await Service.GetAsync();

                // Assert
                Assert.AreEqual(response.Response.Data[0].Name, expectedName);
            }
Ejemplo n.º 3
0
            public async Task ProvidesCorrectApiUrl(int id)
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                await Service.GetAsync(id);

                // Assert
                var expected = $"{HttpConstants.FhrHttpProtocol}://{HttpConstants.FhrBaseApiUrl}/Regions/{id}";

                MockHttpProvider.Verify(http => http.GetAsync(It.Is <string>(response => response == expected), It.IsAny <IDictionary <string, string> >()));
            }
            public async Task ProvidesCorrectApiUrl(int page, int size)
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                await Service.GetPagedBasicAsync(page, size);

                // Assert
                var expected = $"{HttpConstants.FhrHttpProtocol}://{HttpConstants.FhrBaseApiUrl}/Authorities/basic/{page}/{size}";

                MockHttpProvider.Verify(http => http.GetAsync(It.Is <string>(response => response == expected), It.IsAny <IDictionary <string, string> >()));
            }
            public async Task ProvidesCorrectApiUrlWhenCriteriaNull()
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                await Service.GetBasicAsync(null);

                // Assert
                var expected = $"{HttpConstants.FhrHttpProtocol}://{HttpConstants.FhrBaseApiUrl}/Establishments/basic";

                MockHttpProvider.Verify(http => http.GetAsync(It.Is <string>(response => response == expected), It.IsAny <IDictionary <string, string> >()));
            }
            public async Task ProvidesCorrectEncodedApiUrlWhenCriteriaExists(string name)
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                var criteria = new EstablishmentSearchCriteria {
                    Name = name
                };
                await Service.GetBasicAsync(criteria);

                // Assert
                var expected = $"{HttpConstants.FhrHttpProtocol}://{HttpConstants.FhrBaseApiUrl}/Establishments/basic?name={WebUtility.UrlEncode(name)}&address=&longitude=&latitude=&maxDistanceLimit=&businessTypeId=&schemeTypeKey=&ratingKey=&ratingOperatorKey=&localAuthorityId=&countryId=&sortOptionKey=&pageNumber=&pageSize=";

                MockHttpProvider.Verify(http => http.GetAsync(It.Is <string>(s => s == expected), It.IsAny <IDictionary <string, string> >()));
            }
Ejemplo n.º 7
0
            public async Task ProvidesCorrectApiHeaders()
            {
                // Arrange
                MockHttpProvider
                .Setup(http => http.GetAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >()))
                .Returns(Task.FromResult(GenerateHttpResponse(string.Empty)));

                // Act
                await Service.GetPagedBasicAsync(0, 0);

                // Assert
                const string expectedKey   = "x-api-version";
                const string expectedValue = "2";

                MockHttpProvider
                .Verify(http => http.GetAsync(It.IsAny <string>(), It.Is <IDictionary <string, string> >
                                              (
                                                  response =>
                                                  response[expectedKey] != null &&
                                                  response[expectedKey] == expectedValue
                                              )));
            }