protected IntegrationTest() { // Create an in memory api client to send test requests to var appFactory = new WebApplicationFactory <Startup>() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { // Replace storage client service with one we can run tests against var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IApiRepository)); if (descriptor != null) { services.Remove(descriptor); } services.Add(new ServiceDescriptor(typeof(IApiRepository), BlobStorageApiRepository.Init(Constants.BlobStorageConnectionString))); }); }); TestClient = appFactory.CreateClient(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add api storage service services.Add(new ServiceDescriptor(typeof(IApiRepository), BlobStorageApiRepository.Init(Configuration[Constants.BlobStorageConnectionStringName]))); // Return appropriate error if incorrect content type requested services.AddControllers(configure => { configure.ReturnHttpNotAcceptable = true; }); // Configure swagger api documentation services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Chambers TechTest API", Version = "v1" }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); }
public async static Task ClassInitialize(TestContext context) { // Remove the existing pdfs container before running tests var storage = BlobStorageApiRepository.Init(Constants.BlobStorageConnectionString); await storage.DeleteContainer(BlobStorage.Constants.PdfsContainerName); }