Skip to content

Commit 284c7e7

Browse files
committed
Upgraded to ABP 0.9.7, AspNet Core 1.0. Also made test working properly.
1 parent 71744b7 commit 284c7e7

File tree

12 files changed

+176
-99
lines changed

12 files changed

+176
-99
lines changed

src/AbpCompanyName.AbpProjectName.Application/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp.AutoMapper": "0.9.6",
5+
"Abp.AutoMapper": "0.9.7",
66
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*"
77
},
88

src/AbpCompanyName.AbpProjectName.Core/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp": "0.9.6"
5+
"Abp": "0.9.7"
66
},
77

88
"frameworks": {

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/EntityFrameworkCore/AbpProjectNameDbContextFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore
77
*/
88
public class AbpProjectNameDbContextFactory : IDbContextFactory<AbpProjectNameDbContext>
99
{
10-
public AbpProjectNameDbContext Create()
10+
public AbpProjectNameDbContext Create(DbContextFactoryOptions options)
1111
{
1212
var builder = new DbContextOptionsBuilder<AbpProjectNameDbContext>();
1313
builder.UseSqlServer("Server=localhost; Database=AbpProjectNameDb; Trusted_Connection=True;");

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/project.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22
"version": "1.0.0.0-*",
33

44
"dependencies": {
5-
"Abp.EntityFrameworkCore": "0.9.6",
5+
"Abp.EntityFrameworkCore": "0.9.7",
66
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*",
7-
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
8-
"Microsoft.EntityFrameworkCore.Tools": {
9-
"version": "1.0.0-preview1-final",
10-
"type": "build"
11-
}
7+
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
8+
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
129
},
1310

1411
"tools": {
15-
"Microsoft.EntityFrameworkCore.Tools": {
16-
"version": "1.0.0-preview1-final",
17-
"imports": [
18-
"portable-net45+win8+dnxcore50",
19-
"portable-net45+win8"
20-
]
21-
}
2212
},
2313

2414
"buildOptions": {

src/AbpCompanyName.AbpProjectName.Web/Controllers/HomeController.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using System;
12
using System.Threading.Tasks;
23
using Abp.AspNetCore.Mvc.Controllers;
3-
using Abp.Json;
44
using Abp.UI;
55
using AbpCompanyName.AbpProjectName.Products;
66
using Microsoft.AspNetCore.Mvc;
@@ -19,16 +19,10 @@ public HomeController(IProductAppService productAppService)
1919
public async Task<ActionResult> Index()
2020
{
2121
var model = await _productAppService.GetAllProducts();
22-
//return Content(model.ToJsonString());
2322
return View(model);
2423
}
2524

26-
public ActionResult Exception1()
27-
{
28-
throw new UserFriendlyException("Test User Friendly Exception", "This is a user friendly exception directly shown to the user.");
29-
}
30-
31-
public JsonResult Exception2()
25+
public JsonResult GetUserFriendlyException()
3226
{
3327
throw new UserFriendlyException("Test User Friendly Exception", "This is a user friendly exception directly shown to the user.");
3428
}

src/AbpCompanyName.AbpProjectName.Web/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
3434

3535
services.AddMvc(options =>
3636
{
37-
options.AddAbp(); //Add ABP infrastructure to MVC
38-
}).AddControllersAsServices();
37+
options.AddAbp(services); //Add ABP infrastructure to MVC
38+
});
3939

4040
//Configure Abp and Dependency Injection
4141
return services.AddAbp(abpBootstrapper =>

src/AbpCompanyName.AbpProjectName.Web/project.json

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,28 @@
11
{
22
"dependencies": {
3-
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
4-
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
5-
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
6-
"Microsoft.AspNetCore.Razor.Tools": {
7-
"version": "1.0.0-preview1-final",
8-
"type": "build"
9-
},
10-
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
11-
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
12-
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
13-
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
14-
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
15-
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
16-
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
17-
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
18-
"version": "1.0.0-preview1-final",
19-
"type": "build"
20-
},
21-
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
22-
"version": "1.0.0-preview1-final",
23-
"type": "build"
24-
},
25-
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
26-
"Microsoft.EntityFrameworkCore.Tools": {
27-
"version": "1.0.0-preview1-final",
28-
"type": "build"
29-
},
303
"Castle.Windsor-log4net": "3.3.0",
314
"AbpCompanyName.AbpProjectName.Application": "1.0.0.0-*",
325
"AbpCompanyName.AbpProjectName.EntityFrameworkCore": "1.0.0.0-*",
336
"Castle.LoggingFacility.MsLogging": "0.1.0",
34-
"Abp.AspNetCore": "0.9.6"
7+
"Abp.AspNetCore": "0.9.7",
8+
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
9+
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
10+
"Microsoft.AspNetCore.Mvc": "1.0.0",
11+
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
12+
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
13+
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
14+
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
15+
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
16+
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
17+
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
18+
"Microsoft.Extensions.Configuration.Json": "1.0.0",
19+
"Microsoft.Extensions.Logging": "1.0.0",
20+
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
21+
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final",
22+
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final"
3523
},
3624

3725
"tools": {
38-
"Microsoft.AspNetCore.Razor.Tools": {
39-
"version": "1.0.0-preview1-final",
40-
"imports": "portable-net45+win8+dnxcore50"
41-
},
42-
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
43-
"version": "1.0.0-preview1-final",
44-
"imports": "portable-net45+win8+dnxcore50"
45-
},
46-
"Microsoft.EntityFrameworkCore.Tools": {
47-
"version": "1.0.0-preview1-final",
48-
"imports": [
49-
"portable-net45+win8+dnxcore50",
50-
"portable-net45+win8"
51-
]
52-
},
53-
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
54-
"version": "1.0.0-preview1-final",
55-
"imports": [
56-
"portable-net45+win8+dnxcore50",
57-
"portable-net45+win8"
58-
]
59-
}
6026
},
6127

6228
"frameworks": {

test/AbpCompanyName.AbpProjectName.Tests/project.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
"testRunner": "xunit",
55

66
"dependencies": {
7-
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final",
8-
"xunit": "2.1.0",
9-
"xunit.runner.visualstudio": "2.1.0",
10-
"xunit.extensibility.execution": "2.1.0",
11-
"dotnet-test-xunit": "1.0.0-rc2-build10025",
127
"NSubstitute": "1.10.0",
138
"AbpCompanyName.AbpProjectName.Application": "1.0.0.0-*",
149
"AbpCompanyName.AbpProjectName.EntityFrameworkCore": "1.0.0.0-*",
1510
"Shouldly": "2.8.0",
16-
"Abp.TestBase": "0.9.6",
17-
"Castle.Windsor.MsDependencyInjection": "0.2.0"
11+
"Castle.Windsor.MsDependencyInjection": "0.2.0",
12+
"Abp.TestBase": "0.9.7",
13+
"dotnet-test-xunit": "2.2.0-preview2-build1029",
14+
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
15+
"xunit": "2.2.0-beta2-build3300",
16+
"xunit.extensibility.execution": "2.2.0-beta2-build3300",
17+
"xunit.runner.visualstudio": "2.2.0-beta2-build1149"
1818
},
1919

2020
"frameworks": {

test/AbpCompanyName.AbpProjectName.Web.Tests/AbpProjectNameWebTestBase.cs

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,104 @@
11
using System;
2+
using System.IO;
3+
using System.Linq;
24
using System.Net;
35
using System.Net.Http;
46
using System.Threading.Tasks;
5-
using Abp.AspNetCore.TestBase;
7+
using Abp.Dependency;
8+
using Abp.Extensions;
9+
using Abp.TestBase.Runtime.Session;
610
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
711
using AbpCompanyName.AbpProjectName.Tests.TestDatas;
12+
using Microsoft.AspNetCore.Hosting;
13+
using Microsoft.AspNetCore.Routing;
14+
using Microsoft.AspNetCore.TestHost;
815
using Newtonsoft.Json;
916
using Newtonsoft.Json.Serialization;
1017
using Shouldly;
18+
using Microsoft.Extensions.DependencyInjection;
19+
using Abp.Collections.Extensions;
1120

1221
namespace AbpCompanyName.AbpProjectName.Web.Tests
1322
{
14-
public abstract class AbpProjectNameWebTestBase : AbpAspNetCoreIntegratedTestBase<Startup>
23+
public abstract class AbpProjectNameWebTestBase
1524
{
25+
protected TestServer Server { get; private set; }
26+
27+
protected HttpClient Client { get; private set; }
28+
29+
protected IServiceProvider ServiceProvider { get; private set; }
30+
31+
protected IIocManager IocManager { get; private set; }
32+
33+
protected TestAbpSession AbpSession { get; private set; }
34+
35+
protected static readonly Lazy<string> ContentRootFolder;
36+
37+
static AbpProjectNameWebTestBase()
38+
{
39+
ContentRootFolder = new Lazy<string>(CalculateContentRootFolder, true);
40+
}
41+
1642
protected AbpProjectNameWebTestBase()
1743
{
44+
45+
46+
var builder = new WebHostBuilder()
47+
.UseContentRoot(ContentRootFolder.Value)
48+
.UseStartup<Startup>();
49+
50+
Server = new TestServer(builder);
51+
Client = Server.CreateClient();
52+
53+
ServiceProvider = Server.Host.Services;
54+
IocManager = ServiceProvider.GetRequiredService<IIocManager>();
55+
AbpSession = ServiceProvider.GetRequiredService<TestAbpSession>();
56+
1857
UsingDbContext(context => new TestDataBuilder(context).Build());
1958
}
2059

21-
protected virtual async Task<T> GetResponseAsObjectAsync<T>(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
60+
private static bool DirectoryContains(string directory, string fileName)
61+
{
62+
return Directory.GetFiles(directory).Any(filePath => string.Equals(Path.GetFileName(filePath), fileName));
63+
}
64+
65+
#region GetUrl
66+
67+
protected virtual string GetUrl<TController>()
68+
{
69+
var controllerName = typeof(TController).Name;
70+
if (controllerName.EndsWith("Controller"))
71+
{
72+
controllerName = controllerName.Left(controllerName.Length - "Controller".Length);
73+
}
74+
75+
return "/" + controllerName;
76+
}
77+
78+
protected virtual string GetUrl<TController>(string actionName)
79+
{
80+
return GetUrl<TController>() + "/" + actionName;
81+
}
82+
83+
protected virtual string GetUrl<TController>(string actionName, object queryStringParamsAsAnonymousObject)
84+
{
85+
var url = GetUrl<TController>(actionName);
86+
87+
var dictionary = new RouteValueDictionary(queryStringParamsAsAnonymousObject);
88+
if (dictionary.Any())
89+
{
90+
url += "?" + dictionary.Select(d => $"{d.Key}={d.Value}").JoinAsString("&");
91+
}
92+
93+
return url;
94+
}
95+
96+
#endregion
97+
98+
#region Get response
99+
100+
protected async Task<T> GetResponseAsObjectAsync<T>(string url,
101+
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
22102
{
23103
var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode);
24104
return JsonConvert.DeserializeObject<T>(strResponse, new JsonSerializerSettings
@@ -27,20 +107,26 @@ protected virtual async Task<T> GetResponseAsObjectAsync<T>(string url, HttpStat
27107
});
28108
}
29109

30-
protected virtual async Task<string> GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
110+
protected async Task<string> GetResponseAsStringAsync(string url,
111+
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
31112
{
32113
var response = await GetResponseAsync(url, expectedStatusCode);
33114
return await response.Content.ReadAsStringAsync();
34115
}
35116

36-
protected virtual async Task<HttpResponseMessage> GetResponseAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
117+
protected async Task<HttpResponseMessage> GetResponseAsync(string url,
118+
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
37119
{
38120
var response = await Client.GetAsync(url);
39121
response.StatusCode.ShouldBe(expectedStatusCode);
40122
return response;
41123
}
42124

43-
protected virtual void UsingDbContext(Action<AbpProjectNameDbContext> action)
125+
#endregion
126+
127+
#region UsingDbContext
128+
129+
protected void UsingDbContext(Action<AbpProjectNameDbContext> action)
44130
{
45131
using (var context = IocManager.Resolve<AbpProjectNameDbContext>())
46132
{
@@ -49,7 +135,7 @@ protected virtual void UsingDbContext(Action<AbpProjectNameDbContext> action)
49135
}
50136
}
51137

52-
protected virtual T UsingDbContext<T>(Func<AbpProjectNameDbContext, T> func)
138+
protected T UsingDbContext<T>(Func<AbpProjectNameDbContext, T> func)
53139
{
54140
T result;
55141

@@ -62,7 +148,7 @@ protected virtual T UsingDbContext<T>(Func<AbpProjectNameDbContext, T> func)
62148
return result;
63149
}
64150

65-
protected virtual async Task UsingDbContextAsync(Func<AbpProjectNameDbContext, Task> action)
151+
protected async Task UsingDbContextAsync(Func<AbpProjectNameDbContext, Task> action)
66152
{
67153
using (var context = IocManager.Resolve<AbpProjectNameDbContext>())
68154
{
@@ -71,7 +157,7 @@ protected virtual async Task UsingDbContextAsync(Func<AbpProjectNameDbContext, T
71157
}
72158
}
73159

74-
protected virtual async Task<T> UsingDbContextAsync<T>(Func<AbpProjectNameDbContext, Task<T>> func)
160+
protected async Task<T> UsingDbContextAsync<T>(Func<AbpProjectNameDbContext, Task<T>> func)
75161
{
76162
T result;
77163

@@ -83,5 +169,27 @@ protected virtual async Task<T> UsingDbContextAsync<T>(Func<AbpProjectNameDbCont
83169

84170
return result;
85171
}
172+
173+
#endregion
174+
175+
#region Other private methods
176+
177+
private static string CalculateContentRootFolder()
178+
{
179+
var directoryInfo = new DirectoryInfo(Path.GetDirectoryName(typeof(AbpProjectNameWebTestBase).Assembly.Location));
180+
while (!DirectoryContains(directoryInfo.FullName, "AbpCompanyName.AbpProjectName.sln"))
181+
{
182+
if (directoryInfo.Parent == null)
183+
{
184+
throw new Exception("Could not find content root folder!");
185+
}
186+
187+
directoryInfo = directoryInfo.Parent;
188+
}
189+
190+
return Path.Combine(directoryInfo.FullName, @"src\AbpCompanyName.AbpProjectName.Web");
191+
}
192+
193+
#endregion
86194
}
87195
}

0 commit comments

Comments
 (0)