public void Setup() { _factory = new WebApplicationFactory <Startup>(); _client = _factory.CreateClient(); }
public WoodshopControllerTestsUnauthorized(WebApplicationFactory <Project.Startup> fixture) { Client = fixture.CreateClient(); }
public IntegrationTests(WebApplicationFactory <Startup> factory) { _factory = factory; _client = _factory.CreateClient(); }
public HttpClientBase() { appFactory = new WebApplicationFactory <Startup>(); HttpClient = appFactory.CreateClient(); }
public GetARideControllerTests() { var webApplicationFactory = new WebApplicationFactory <GetARideWebApp.Startup>(); _httpClient = webApplicationFactory.CreateClient(); }
public TaxaDeJurosIntegrationTests(WebApplicationFactory<Startup> factory) { _httpClient = factory.CreateClient(); }
public async void Should_GetRoom_WithShowingOnSpecifiedDate() { var client = _factory.CreateClient(); // spoof admin access IJwtManager jwtManager = new InMemoryJwtManager(_configuration); string testToken = await jwtManager.GenerateJwtStringAsync("*****@*****.**", new List <Claim> { new Claim(ClaimTypes.Role, "admin") }); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + testToken); // get antiforgery token, and add to header var aftResponse = await client.GetAsync("/api/account/getCSRFToken"); var tokenData = JsonConvert.DeserializeAnonymousType(aftResponse.Content.ReadAsStringAsync().Result, new { Token = "", TokenName = "" }); client.DefaultRequestHeaders.Add(tokenData.TokenName, tokenData.Token); // add seed data for dependencies Event @event = new Event { Name = "Test Event", Description = "Event Desc", Image = "", Duration = 120, AgeRating = AgeRatingType.BBFC_PG }; string json = JsonConvert.SerializeObject(@event); var content = new StringContent(json, Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync("api/events", content); Venue venue = new Venue { Name = "Test Venue", Description = "Venue Desc", Address1 = "Addr1", Address2 = "Addr2", Address3 = "Addr3", Address4 = "Addr4", Address5 = "Addr5", ContactPhone = "", Image = "", Website = "", Instagram = "", Facebook = "", Twitter = "", Facilities = FacilityFlags.Bar | FacilityFlags.GuideDogsPermitted, LatLong = "" }; json = JsonConvert.SerializeObject(venue); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/venues", content); Room room = new Room { Name = "Test Room", Description = "Room Desc", Columns = 10, Rows = 10, Isles = "", VenueId = 1 }; json = JsonConvert.SerializeObject(room); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/rooms", content); PricingStrategy strategy = new PricingStrategy { Name = "Test Strategy", Description = "Strategy Desc" }; json = JsonConvert.SerializeObject(strategy); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/pricingstrategies", content); Showing showing = new Showing { Id = 0, StartTime = new DateTime(2018, 12, 1), EndTime = new DateTime(2018, 12, 2), PricingStrategyId = 1, EventId = 1, RoomId = 1 }; json = JsonConvert.SerializeObject(showing); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/showings", content); var filterResponse = await client.GetAsync($"api/rooms?$expand=Showings&$filter=Showings/any(s : date(s/StartTime) ge 2018-12-1 and date(s/StartTime) lt 2018-12-2 and s/EventId eq 1)&$select=Id,Name,Showings"); string data = await filterResponse.Content.ReadAsStringAsync(); List <Room> getRooms = await filterResponse.Content.ReadAsAsync <List <Room> >(); if (getRooms != null && getRooms.Count() > 0) { Assert.True(getRooms[0].Showings != null); } else { if (getRooms.Count == 0) { Assert.NotEmpty(getRooms); } Assert.NotNull(getRooms); } }
public async Task GET_helloAnonymous_should_not_require_token(string url, HttpStatusCode expectedStatusCode) { // Arrange var client = _factory.CreateClient(new WebApplicationFactoryClientOptions()); // Act var response = await client.GetAsync(url); // Assert Assert.Equal(expectedStatusCode, response.StatusCode); }
public FunctionalTests(WebApplicationFactory <Startup> factory) { _client = factory.CreateClient(); _services = factory.Server.Host.Services; }
private async Task GetCustomer(string customerId) { var client = _factory.CreateClient(); string result = await client.GetStringAsync($"/api/v1/Customers/{customerId}/?api-version=1"); }
public static void Initialize(TestContext context) { factory = new WebApplicationFactory <Startup>(); factory.Server.AllowSynchronousIO = true; client = factory.CreateClient(); }
public TestsBase(WebApplicationFactory <DemoApi.Startup> factory) { _factory = factory; Client = _factory.CreateClient(); }
public ParcelsControllerTests(WebApplicationFactory <Startup> factory) { _client = factory.CreateClient(); }
public CreateTokenServiceTest() { var appFactory = new WebApplicationFactory <Startup>(); _cliente = appFactory.CreateClient(); }
public async System.Threading.Tasks.Task DeleteRate_Should_ReturnSuccessfully() { // ---------------------------------------------------------------- // Arrange // ---------------------------------------------------------------- var application = new WebApplicationFactory <Program>() .WithWebHostBuilder(builder => { builder.ConfigureAppConfiguration((hostingContext, configurationBuilder) => { configurationBuilder.AddJsonFile("appsettings.json"); }); }); var client = application.CreateClient(); // User will be authenticated var currentUser = _context.Users .Where(u => u.EmailAddress == "*****@*****.**") .FirstOrDefault(); var token = GenerateJSONWebToken(currentUser !.Id, currentUser !.EmailAddress !); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); // ---------------------------------------------------------------- // Act // ---------------------------------------------------------------- var content = new { Name = "Regular Hourly", Type = "Payroll" }; var json = JsonSerializer.Serialize(content, options); var buffer = Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseCreate = await client.PostAsync($"odata/Rates", byteContent); // ---------------------------------------------------------------- // Assert // ---------------------------------------------------------------- Assert.IsTrue(responseCreate.IsSuccessStatusCode); // ---------------------------------------------------------------- // Act again // ---------------------------------------------------------------- var rateId = _context.Rates .Where(r => r.Name == "Regular Hourly") .Select(r => r.Id) .FirstOrDefault(); var responseDelete = await client.DeleteAsync($"odata/Rates({rateId})"); // ---------------------------------------------------------------- // Assert again // ---------------------------------------------------------------- Assert.IsTrue(responseDelete.IsSuccessStatusCode); }
public static async Task ClassStartup(TestContext context) { webApplicationFactory = new WebApplicationFactory <Startup>(); httpClient = webApplicationFactory.CreateClient(); }
public DeptHistoryIntergrationTests(WebApplicationFactory <Startup> factory) { _factory = factory; _client = factory.CreateClient(); rootAddress = "api/employees"; }
public FoodProductCategoriesTests(WebApplicationFactory <Startup> factory) { factory.ClientOptions.BaseAddress = new System.Uri("http://localhost/api/foodproducts/categories"); _client = factory.CreateClient(); }
public static HttpClient GetTestClient( CustomWebApplicationFactory <Startup> customFactory, string org, string app) { WebApplicationFactory <Startup> factory = customFactory.WithWebHostBuilder(builder => { string path = GetAppPath(org, app); builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(path + "appsettings.json"); }); var configuration = new ConfigurationBuilder() .AddJsonFile(path + "appsettings.json") .Build(); configuration.GetSection("AppSettings:AppBasePath").Value = path; IConfigurationSection appSettingSection = configuration.GetSection("AppSettings"); builder.ConfigureTestServices(services => { services.Configure <AppSettings>(appSettingSection); services.AddSingleton <Altinn.Common.PEP.Interfaces.IPDP, PepWithPDPAuthorizationMockSI>(); services.AddSingleton <IValidation, ValidationAppSI>(); services.AddTransient <IApplication, ApplicationMockSI>(); services.AddTransient <IInstance, InstanceMockSI>(); services.AddTransient <IData, DataMockSI>(); services.AddTransient <IInstanceEvent, InstanceEventAppSIMock>(); services.AddTransient <IEvents, EventsMockSI>(); services.AddTransient <IDSF, DSFMockSI>(); services.AddTransient <IER, ERMockSI>(); services.AddTransient <IRegister, RegisterMockSI>(); services.AddTransient <IPDF, PDFMockSI>(); services.AddTransient <IProfile, ProfileMockSI>(); services.AddTransient <IText, TextMockSI>(); services.AddSingleton <ISigningKeysRetriever, SigningKeysRetrieverStub>(); services.AddSingleton <IPostConfigureOptions <JwtCookieOptions>, JwtCookiePostConfigureOptionsStub>(); switch (app) { case "endring-av-navn": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.endring_av_navn.AltinnApp>(); break; case "custom-validation": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.custom_validation.AltinnApp>(); break; case "task-validation": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.task_validation.AltinnApp>(); break; case "platform-fails": services.AddSingleton <IInstance, InstancePlatformFailsMock>(); services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.platform_fails.AltinnApp>(); break; case "contributor-restriction": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.contributer_restriction.AltinnApp>(); break; case "sirius": services.AddSingleton <ISiriusApi, SiriusAPI>(); services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.sirius.App>(); break; case "events": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.ttd.events.AltinnApp>(); break; case "autodelete-true": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.autodelete_true.AltinnApp>(); break; case "nabovarsel": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.dibk.nabovarsel.AltinnApp>(); break; case "klareringsportalen": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.nsm.klareringsportalen.AppLogic.App>(); break; case "issue-5740": services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.ttd.issue5740.App>(); break; default: services.AddSingleton <IAltinnApp, IntegrationTests.Mocks.Apps.tdd.endring_av_navn.AltinnApp>(); break; } }); }); factory.Server.AllowSynchronousIO = true; return(factory.CreateClient()); }
public MovieControllerTest(WebApplicationFactory <popcorn.Startup> fixture) { Client = fixture.CreateClient(); }
public UnitTest1() { var appFactory = new WebApplicationFactory <Startup>(); _client = appFactory.CreateClient(); }
public System.Net.Http.HttpClient CreateClient() { return(_factory.CreateClient()); }
public AuthorizationTest(WebApplicationFactory <Startup> factory) { _factory = factory; _client = _factory.CreateClient(new WebApplicationFactoryClientOptions()); }
public FinancialInstrumentControllerTest(WebApplicationFactory <RBC_GAM.Startup> appFactory) { _httpClient = appFactory.CreateClient(); }
public PathSchemeSelectionTests(WebApplicationFactory <PathSchemeSelection.Startup> fixture) { Client = fixture.CreateClient(); }
protected Task <HttpResponseMessage> GetAsync(string actionName) { var client = Factory.CreateClient(); return(client.GetAsync($"/{ControllerName}/{actionName}")); }
public PetControllerTests(WebApplicationFactory <PetShopAtlanticoWebApi.Startup> fixture) { _client = fixture.CreateClient(); }
public HomePageShould(WebApplicationFactory <Startup> factory) { _client = factory.CreateClient(); }
public HttpClient GetHttpClient() => _client ??= _factory?.CreateClient();
public EmployeeTests(WebApplicationFactory <BangazonWorkforce.Startup> factory) { _client = factory.CreateClient(); }