Add Accept-Language header in the AbpAspNetCoreTestBase

pull/1810/head
Halil İbrahim Kalkan 6 years ago
parent bd2c5b4761
commit 03b47aee23

@ -69,6 +69,9 @@ namespace Volo.Abp.AspNetCore.Mvc
typeof(AbpUiResource),
typeof(AbpValidationResource)
).AddVirtualJson("/Volo/Abp/AspNetCore/Mvc/Localization/Resource");
options.Languages.Add(new LanguageInfo("en", "en", "English"));
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
});
}
@ -78,6 +81,7 @@ namespace Volo.Abp.AspNetCore.Mvc
app.UseCorrelationId();
app.UseVirtualFiles();
app.UseAbpRequestLocalization();
app.UseRouting();
app.UseMiddleware<FakeAuthenticationMiddleware>();
app.UseAuthorization();

@ -1,5 +1,7 @@
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
@ -30,15 +32,23 @@ namespace Volo.Abp.AspNetCore
protected virtual async Task<string> GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
{
var response = await GetResponseAsync(url, expectedStatusCode);
return await response.Content.ReadAsStringAsync();
using (var response = await GetResponseAsync(url, expectedStatusCode))
{
return await response.Content.ReadAsStringAsync();
}
}
protected virtual async Task<HttpResponseMessage> GetResponseAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
{
var response = await Client.GetAsync(url);
response.StatusCode.ShouldBe(expectedStatusCode);
return response;
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
{
requestMessage.Headers.Add("Accept-Language", CultureInfo.CurrentUICulture.Name);
var response = await Client.SendAsync(requestMessage);
response.StatusCode.ShouldBe(expectedStatusCode);
return response;
}
}
}
}

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Autofac;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
@ -20,7 +21,7 @@ namespace Volo.Abp.AspNetCore
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
Configure<VirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpAspNetCoreTestModule>();
@ -45,7 +46,7 @@ namespace Volo.Abp.AspNetCore
directory = directory.Parent;
}
return directory?.FullName
return directory?.FullName
?? throw new Exception("Could not find the project path by beginning from " + hostEnvironment.ContentRootPath + ", going through to parents and looking for Volo.Abp.AspNetCore.Tests");
}
}

Loading…
Cancel
Save