Exemplo n.º 1
0
        public void Should_DeleteSchool_returns_not_success_result_when_api_returns_not_ok_response()
        {
            // Arrange
            const string errorMsg       = "exception";
            var          mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(x => x.BaseUrl).Returns(new Uri(_connectionInformation.ApiBaseUrl));
            mockRestClient.Setup(x => x.Execute(It.IsAny <RestRequest>())).Returns(new RestResponse
            {
                StatusCode = HttpStatusCode.NotFound, ErrorMessage = errorMsg
            });

            var mockTokenRetriever = new Mock <ITokenRetriever>();

            mockTokenRetriever.Setup(x => x.ObtainNewBearerToken()).Returns("Token");

            var mockOdsRestClient =
                new OdsRestClient(_connectionInformation, mockRestClient.Object, mockTokenRetriever.Object);

            _facade = new OdsApiFacade(_mapper, mockOdsRestClient);

            // Act
            var result = _facade.DeleteSchool(SchoolId);

            // Assert
            result.Success.ShouldBe(false);
            result.ErrorMessage.ShouldBe(errorMsg);
        }
Exemplo n.º 2
0
        public void Should_DeleteSchool_successfully_delete_school()
        {
            // Arrange
            var mockOdsRestClient = new Mock <IOdsRestClient>();

            mockOdsRestClient
            .Setup(x => x.DeleteResource(ResourcePaths.SchoolById, SchoolId, It.IsAny <bool>()))
            .Returns(new OdsApiResult());

            _facade = new OdsApiFacade(_mapper, mockOdsRestClient.Object);

            // Act
            var result = _facade.DeleteSchool(SchoolId);

            // Assert
            result.Success.ShouldBe(true);
        }