public IntegrationTestFixture() { TestServer testServer = new TestServer(Program.CreateWebHostBuilder(new string[] { }).UseEnvironment("Development")); var httpClient = testServer.CreateClient(); FooServiceClient = new FooServiceClient(httpClient); }
public DeploymentTestsFixture() { string serviceUrl = Environment.GetEnvironmentVariable("StudentsServiceDeploymentTestsUrl"); if (string.IsNullOrWhiteSpace(serviceUrl)) { throw new Exception("Could not find StudentsServiceUrl environment variable"); } FooServiceClient = new FooServiceClient(new System.Net.Http.HttpClient { BaseAddress = new Uri(serviceUrl) }); }
public async Task AddStudentReturnsCorrectStatusCodeOnStorageErrors(HttpStatusCode statusCode) { var studentsStoreMock = new Mock <IStudentStore>(); studentsStoreMock.Setup(store => store.AddStudent(_courseName, _testStudent)) .ThrowsAsync(new StorageErrorException("Test Exception", (int)statusCode)); TestServer testServer = new TestServer( Program.CreateWebHostBuilder(new string[] { }) .ConfigureTestServices(services => { services.AddSingleton(studentsStoreMock.Object); }).UseEnvironment("Development")); var httpClient = testServer.CreateClient(); var fooServiceClient = new FooServiceClient(httpClient); FooServiceException e = await Assert.ThrowsAsync <FooServiceException>(() => fooServiceClient.AddStudent(_courseName, _testStudent)); Assert.Equal(statusCode, e.StatusCode); }