Beispiel #1
0
        public void Should_GetSchoolById_returns_exception_when_api_returns_not_ok_response()
        {
            // Arrange
            const string errorMessage = "not found error";

            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 = errorMessage
            });

            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 ex = Assert.Throws <OdsApiConnectionException>(() => _facade.GetSchoolById(SchoolId));

            // Assert
            Assert.AreEqual(errorMessage, ex.Message);
        }
Beispiel #2
0
        public void Should_GetSchoolById_returns_expected_school()
        {
            // Arrange
            var edfiSchool = new EdFiSchool(SchoolId, SchoolName, 1234, new List <EdFiEducationOrganizationAddress>(),
                                            new List <EdFiEducationOrganizationCategory>(), new List <EdFiSchoolGradeLevel>());
            var mockOdsRestClient = new Mock <IOdsRestClient>();

            mockOdsRestClient.Setup(x => x.GetById <EdFiSchool>(ResourcePaths.SchoolById, SchoolId)).Returns(edfiSchool);

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

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

            // Assert
            result.ShouldNotBeNull();
            result.Id.ShouldBe(SchoolId);
            result.Name.ShouldBe(SchoolName);
        }