Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CleanArchitecture
Commits
1118e817
Commit
1118e817
authored
Oct 23, 2017
by
Steve Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
00ffecbe
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
147 additions
and
287 deletions
+147
-287
CleanArchitecture.Core.csproj
src/CleanArchitecture.Core/CleanArchitecture.Core.csproj
+1
-12
AssemblyInfo.cs
src/CleanArchitecture.Core/Properties/AssemblyInfo.cs
+0
-19
CleanArchitecture.Infrastructure.csproj
...re.Infrastructure/CleanArchitecture.Infrastructure.csproj
+11
-12
AssemblyInfo.cs
...eanArchitecture.Infrastructure/Properties/AssemblyInfo.cs
+0
-19
CleanArchitecture.Web.csproj
src/CleanArchitecture.Web/CleanArchitecture.Web.csproj
+16
-22
launchSettings.json
src/CleanArchitecture.Web/Properties/launchSettings.json
+0
-27
Startup.cs
src/CleanArchitecture.Web/Startup.cs
+2
-2
CleanArchitecture.Tests.csproj
tests/CleanArchitecture.Tests/CleanArchitecture.Tests.csproj
+15
-27
ApiToDoItemsControllerListShould.cs
...Tests/Integration/Web/ApiToDoItemsControllerListShould.cs
+8
-40
BaseWebTest.cs
tests/CleanArchitecture.Tests/Integration/Web/BaseWebTest.cs
+91
-0
HomeControllerContactShould.cs
...ture.Tests/Integration/Web/HomeControllerContactShould.cs
+3
-88
AssemblyInfo.cs
tests/CleanArchitecture.Tests/Properties/AssemblyInfo.cs
+0
-19
No files found.
src/CleanArchitecture.Core/CleanArchitecture.Core.csproj
View file @
1118e817
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<AssemblyName>CleanArchitecture.Core</AssemblyName>
<PackageId>CleanArchitecture.Core</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
</ItemGroup>
</Project>
src/CleanArchitecture.Core/Properties/AssemblyInfo.cs
deleted
100644 → 0
View file @
00ffecbe
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
""
)]
[
assembly
:
AssemblyProduct
(
"CleanArchitecture.Core"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[
assembly
:
ComVisible
(
false
)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[
assembly
:
Guid
(
"af4ab14a-200a-492b-ad62-e8d6f1ac8cc2"
)]
src/CleanArchitecture.Infrastructure/CleanArchitecture.Infrastructure.csproj
View file @
1118e817
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<AssemblyName>CleanArchitecture.Infrastructure</AssemblyName>
<PackageId>CleanArchitecture.Infrastructure</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
...
...
@@ -16,11 +12,14 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="StructureMap.Microsoft.DependencyInjection" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
</ItemGroup>
</Project>
src/CleanArchitecture.Infrastructure/Properties/AssemblyInfo.cs
deleted
100644 → 0
View file @
00ffecbe
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
""
)]
[
assembly
:
AssemblyProduct
(
"CleanArchitecture.Infrastructure"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[
assembly
:
ComVisible
(
false
)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[
assembly
:
Guid
(
"7262ed0f-c789-4014-be31-e93d5869811e"
)]
src/CleanArchitecture.Web/CleanArchitecture.Web.csproj
View file @
1118e817
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>CleanArchitecture.Web</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>CleanArchitecture.Web</PackageId>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
...
...
@@ -22,20 +19,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.1.0" />
<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
...
...
src/CleanArchitecture.Web/Properties/launchSettings.json
deleted
100644 → 0
View file @
00ffecbe
{
"iisSettings"
:
{
"windowsAuthentication"
:
false
,
"anonymousAuthentication"
:
true
,
"iisExpress"
:
{
"applicationUrl"
:
"http://localhost:7455/"
,
"sslPort"
:
0
}
},
"profiles"
:
{
"IIS Express"
:
{
"commandName"
:
"IISExpress"
,
"launchBrowser"
:
true
,
"environmentVariables"
:
{
"ASPNETCORE_ENVIRONMENT"
:
"Development"
}
},
"CleanArchitecture.Web"
:
{
"commandName"
:
"Project"
,
"launchBrowser"
:
true
,
"launchUrl"
:
"http://localhost:5000"
,
"environmentVariables"
:
{
"ASPNETCORE_ENVIRONMENT"
:
"Development"
}
}
}
}
\ No newline at end of file
src/CleanArchitecture.Web/Startup.cs
View file @
1118e817
...
...
@@ -38,8 +38,9 @@ namespace CleanArchitecture.Web
// Add framework services.
// TODO: Add DbContext and IOC
string
dbName
=
Guid
.
NewGuid
().
ToString
();
services
.
AddDbContext
<
AppDbContext
>(
options
=>
options
.
UseInMemoryDatabase
(
Guid
.
NewGuid
().
ToString
()
));
options
.
UseInMemoryDatabase
(
dbName
));
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services
.
AddMvc
();
...
...
@@ -67,7 +68,6 @@ namespace CleanArchitecture.Web
});
return
container
.
GetInstance
<
IServiceProvider
>();
services
.
AddTransient
<
IRepository
<
ToDoItem
>,
EfRepository
<
ToDoItem
>>();
}
public
void
ConfigureTesting
(
IApplicationBuilder
app
,
...
...
tests/CleanArchitecture.Tests/CleanArchitecture.Tests.csproj
View file @
1118e817
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>CleanArchitecture.Tests</AssemblyName>
<PackageId>CleanArchitecture.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6</PackageTargetFallback>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<!-- Solves Problem#1 (binding error) https://github.com/Microsoft/vstest/issues/428. -->
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- https://github.com/NuGet/Home/issues/4412. -->
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''">
<ItemGroup>
...
...
@@ -42,15 +31,14 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
<PackageReference Include="Moq" Version="4.7.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Moq" Version="4.7.142" />
<PackageReference Include="NETStandard.Library" Version="2.0.1" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
...
...
tests/CleanArchitecture.Tests/Integration/Web/ApiToDoItemsControllerListShould.cs
View file @
1118e817
using
System
;
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Web
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.TestHost
;
using
Newtonsoft.Json
;
using
System.Collections.Generic
;
using
System.IO
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
Xunit
;
using
CleanArchitecture.Infrastructure.Data
;
using
CleanArchitecture.Core.Entities
;
using
System.Linq
;
using
System.Net.Http
;
using
System.Net.Http.Headers
;
using
System.Threading.Tasks
;
using
CleanArchitecture.Core.Events
;
using
CleanArchitecture.Core.Interfaces
;
using
CleanArchitecture.Web
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.TestHost
;
using
Moq
;
using
Newtonsoft.Json
;
using
Xunit
;
namespace
CleanArchitecture.Tests.Integration.Web
{
public
class
ApiToDoItemsControllerList
Should
public
class
ApiToDoItemsControllerList
:
BaseWebTest
{
private
readonly
HttpClient
_client
;
public
ApiToDoItemsControllerListShould
()
{
_client
=
GetClient
();
}
protected
HttpClient
GetClient
()
{
var
builder
=
new
WebHostBuilder
()
.
UseContentRoot
(
Directory
.
GetCurrentDirectory
())
.
UseStartup
<
Startup
>()
.
UseEnvironment
(
"Testing"
);
// ensure ConfigureTesting is called in Startup
var
server
=
new
TestServer
(
builder
);
var
client
=
server
.
CreateClient
();
// client always expects json results
client
.
DefaultRequestHeaders
.
Clear
();
client
.
DefaultRequestHeaders
.
Accept
.
Add
(
new
MediaTypeWithQualityHeaderValue
(
"application/json"
));
return
client
;
}
[
Fact
]
public
async
Task
ReturnTwoItems
()
public
async
Task
Return
s
TwoItems
()
{
var
response
=
await
_client
.
GetAsync
(
"/api/todoitems"
);
response
.
EnsureSuccessStatusCode
();
...
...
@@ -58,7 +27,6 @@ namespace CleanArchitecture.Tests.Integration.Web
Assert
.
Equal
(
2
,
result
.
Count
());
Assert
.
Equal
(
1
,
result
.
Count
(
a
=>
a
.
Title
==
"Test Item 1"
));
Assert
.
Equal
(
1
,
result
.
Count
(
a
=>
a
.
Title
==
"Test Item 2"
));
}
}
}
\ No newline at end of file
tests/CleanArchitecture.Tests/Integration/Web/BaseWebTest.cs
0 → 100644
View file @
1118e817
using
CleanArchitecture.Web
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Mvc.ApplicationParts
;
using
Microsoft.AspNetCore.Mvc.Controllers
;
using
Microsoft.AspNetCore.Mvc.ViewComponents
;
using
Microsoft.AspNetCore.TestHost
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.PlatformAbstractions
;
using
System
;
using
System.IO
;
using
System.Net.Http
;
using
System.Reflection
;
namespace
CleanArchitecture.Tests.Integration.Web
{
public
abstract
class
BaseWebTest
{
protected
readonly
HttpClient
_client
;
public
BaseWebTest
()
{
_client
=
GetClient
();
}
protected
HttpClient
GetClient
()
{
var
startupAssembly
=
typeof
(
Startup
).
GetTypeInfo
().
Assembly
;
var
contentRoot
=
GetProjectPath
(
"src"
,
startupAssembly
);
var
builder
=
new
WebHostBuilder
()
.
UseContentRoot
(
contentRoot
)
.
ConfigureServices
(
InitializeServices
)
.
UseStartup
<
Startup
>()
.
UseEnvironment
(
"Testing"
);
// ensure ConfigureTesting is called in Startup
var
server
=
new
TestServer
(
builder
);
var
client
=
server
.
CreateClient
();
return
client
;
}
protected
virtual
void
InitializeServices
(
IServiceCollection
services
)
{
var
startupAssembly
=
typeof
(
Startup
).
GetTypeInfo
().
Assembly
;
// Inject a custom application part manager. Overrides AddMvcCore() because that uses TryAdd().
var
manager
=
new
ApplicationPartManager
();
manager
.
ApplicationParts
.
Add
(
new
AssemblyPart
(
startupAssembly
));
manager
.
FeatureProviders
.
Add
(
new
ControllerFeatureProvider
());
manager
.
FeatureProviders
.
Add
(
new
ViewComponentFeatureProvider
());
services
.
AddSingleton
(
manager
);
}
/// <summary>
/// Gets the full path to the target project path that we wish to test
/// </summary>
/// <param name="solutionRelativePath">
/// The parent directory of the target project.
/// e.g. src, samples, test, or test/Websites
/// </param>
/// <param name="startupAssembly">The target project's assembly.</param>
/// <returns>The full path to the target project.</returns>
private
static
string
GetProjectPath
(
string
solutionRelativePath
,
Assembly
startupAssembly
)
{
// Get name of the target project which we want to test
var
projectName
=
startupAssembly
.
GetName
().
Name
;
// Get currently executing test project path
var
applicationBasePath
=
PlatformServices
.
Default
.
Application
.
ApplicationBasePath
;
// Find the folder which contains the solution file. We then use this information to find the target
// project which we want to test.
var
directoryInfo
=
new
DirectoryInfo
(
applicationBasePath
);
do
{
var
solutionFileInfo
=
new
FileInfo
(
Path
.
Combine
(
directoryInfo
.
FullName
,
"CleanArchitecture.sln"
));
if
(
solutionFileInfo
.
Exists
)
{
return
Path
.
GetFullPath
(
Path
.
Combine
(
directoryInfo
.
FullName
,
solutionRelativePath
,
projectName
));
}
directoryInfo
=
directoryInfo
.
Parent
;
}
while
(
directoryInfo
.
Parent
!=
null
);
throw
new
Exception
(
$"Solution root could not be located using application root
{
applicationBasePath
}
."
);
}
}
}
tests/CleanArchitecture.Tests/Integration/Web/HomeControllerContactShould.cs
View file @
1118e817
using
System.
IO
;
using
System.
Threading.Tasks
;
using
Xunit
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
CleanArchitecture.Web
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.TestHost
;
using
Microsoft.Extensions.PlatformAbstractions
;
using
Microsoft.AspNetCore.Mvc.ApplicationParts
;
using
Microsoft.AspNetCore.Mvc.Controllers
;
using
Microsoft.AspNetCore.Mvc.ViewComponents
;
using
System.Reflection
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
namespace
CleanArchitecture.Tests.Integration.Web
{
public
class
HomeControllerContactShould
public
class
HomeControllerContactShould
:
BaseWebTest
{
private
readonly
HttpClient
_client
;
public
HomeControllerContactShould
()
{
_client
=
GetClient
();
}
protected
HttpClient
GetClient
()
{
var
startupAssembly
=
typeof
(
Startup
).
GetTypeInfo
().
Assembly
;
var
contentRoot
=
GetProjectPath
(
"src"
,
startupAssembly
);
var
builder
=
new
WebHostBuilder
()
.
UseContentRoot
(
contentRoot
)
.
ConfigureServices
(
InitializeServices
)
.
UseStartup
<
Startup
>()
.
UseEnvironment
(
"Testing"
);
// ensure ConfigureTesting is called in Startup
var
server
=
new
TestServer
(
builder
);
var
client
=
server
.
CreateClient
();
return
client
;
}
[
Fact
]
public
async
Task
ReturnViewWithCorrectMessage
()
{
...
...
@@ -47,59 +13,8 @@ namespace CleanArchitecture.Tests.Integration.Web
response
.
EnsureSuccessStatusCode
();
var
stringResponse
=
await
response
.
Content
.
ReadAsStringAsync
();
Assert
.
True
(
stringResponse
.
Contains
(
"Your contact page"
)
);
Assert
.
Contains
(
"Your contact page"
,
stringResponse
);
}
protected
virtual
void
InitializeServices
(
IServiceCollection
services
)
{
var
startupAssembly
=
typeof
(
Startup
).
GetTypeInfo
().
Assembly
;
// Inject a custom application part manager. Overrides AddMvcCore() because that uses TryAdd().
var
manager
=
new
ApplicationPartManager
();
manager
.
ApplicationParts
.
Add
(
new
AssemblyPart
(
startupAssembly
));
manager
.
FeatureProviders
.
Add
(
new
ControllerFeatureProvider
());
manager
.
FeatureProviders
.
Add
(
new
ViewComponentFeatureProvider
());
services
.
AddSingleton
(
manager
);
}
/// <summary>
/// Gets the full path to the target project path that we wish to test
/// </summary>
/// <param name="solutionRelativePath">
/// The parent directory of the target project.
/// e.g. src, samples, test, or test/Websites
/// </param>
/// <param name="startupAssembly">The target project's assembly.</param>
/// <returns>The full path to the target project.</returns>
private
static
string
GetProjectPath
(
string
solutionRelativePath
,
Assembly
startupAssembly
)
{
// Get name of the target project which we want to test
var
projectName
=
startupAssembly
.
GetName
().
Name
;
// Get currently executing test project path
var
applicationBasePath
=
PlatformServices
.
Default
.
Application
.
ApplicationBasePath
;
// Find the folder which contains the solution file. We then use this information to find the target
// project which we want to test.
var
directoryInfo
=
new
DirectoryInfo
(
applicationBasePath
);
do
{
var
solutionFileInfo
=
new
FileInfo
(
Path
.
Combine
(
directoryInfo
.
FullName
,
"CleanArchitecture.sln"
));
if
(
solutionFileInfo
.
Exists
)
{
return
Path
.
GetFullPath
(
Path
.
Combine
(
directoryInfo
.
FullName
,
solutionRelativePath
,
projectName
));
}
directoryInfo
=
directoryInfo
.
Parent
;
}
while
(
directoryInfo
.
Parent
!=
null
);
throw
new
Exception
(
$"Solution root could not be located using application root
{
applicationBasePath
}
."
);
}
}
}
\ No newline at end of file
tests/CleanArchitecture.Tests/Properties/AssemblyInfo.cs
deleted
100644 → 0
View file @
00ffecbe
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
""
)]
[
assembly
:
AssemblyProduct
(
"CleanArchitecture.Tests"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[
assembly
:
ComVisible
(
false
)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[
assembly
:
Guid
(
"0f6a8976-f61a-4eb3-a38c-0a2ed39f157b"
)]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment