示例#1
0
        public GetTests(CustomWebApplicationFactory <EmployeeManagement.Api.Startup> factory)
        {
            _client = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddDbContext <ApplicationDataContext>(options =>
                    {
                        options.UseSqlServer(GetTestDatabaseConnection.GetConnection());
                    });

                    services.AddCors(options =>
                    {
                        options.AddPolicy("FirstPolicy",
                                          builder =>
                        {
                            builder.WithOrigins("http://127.0.0.1:5500")
                            .AllowAnyHeader()
                            .AllowAnyMethod();
                        });
                    });

                    services.AddAutoMapper(e => e.AddProfile <EmployeeProfile>());

                    services.AddControllers();
                });
            }).CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
        }
示例#2
0
        public GetDepartmentTests(CustomWebApplicationFactory <Startup> factory)
        {
            _client = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddCors(options =>
                    {
                        options.AddPolicy("FirstPolicy",
                                          builder =>
                        {
                            builder.WithOrigins("https://localhost:44374")
                            .AllowAnyHeader()
                            .AllowAnyMethod();
                        });
                    });

                    services.AddDbContext <ApplicationDataContext>(options =>
                    {
                        options.UseSqlServer(GetTestDatabaseConnection.GetConnection());
                    });

                    services.AddSingleton <IEmployeeRepo, EmployeeRepo>();
                    services.AddSingleton <IDepartmentRepo, DepartmentRepo>();

                    services.AddAutoMapper(e => e.AddProfile <EmployeeProfile>());
                    services.AddAutoMapper(e => e.AddProfile <DepartmentProfile>());

                    services.AddControllers();
                });
            }).CreateClient();
        }