public void Should_GetAllSchools_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.GetAllSchools()); // Assert Assert.AreEqual(errorMessage, ex.Message); }
public void Should_GetAllSchools_returns_expected_schools_list() { // Arrange var edfiSchool = new EdFiSchool("id", "TestSchool", 1234, new List <EdFiEducationOrganizationAddress>(), new List <EdFiEducationOrganizationCategory>(), new List <EdFiSchoolGradeLevel>()); var mockOdsRestClient = new Mock <IOdsRestClient>(); mockOdsRestClient.Setup(x => x.GetAll <EdFiSchool>(ResourcePaths.Schools)).Returns(new List <EdFiSchool> { edfiSchool }); _facade = new OdsApiFacade(_mapper, mockOdsRestClient.Object); //Act var result = _facade.GetAllSchools(); // Assert result.ShouldNotBeNull(); result.Count.ShouldBeGreaterThan(0); result.First().Name.ShouldBe("TestSchool"); }