Deleted test projects since they are not configured properly and don't work
This commit is contained in:
Родитель
3e7dc77b41
Коммит
efa865b2b2
|
@ -5,8 +5,6 @@ VisualStudioVersion = 17.8.34330.188
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F10AA149-2626-486E-85BB-9CD5365F3016}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.Web", "src\QuestionsAnswers.Web\QuestionsAnswers.Web.csproj", "{A2213374-BB48-48FD-BBD4-81E6A961D866}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.Core", "src\QuestionsAnswers.Core\QuestionsAnswers.Core.csproj", "{0FA75A5B-AB83-4FD0-B545-279774C01E87}"
|
||||
|
@ -15,10 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.Applicatio
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.EntityFrameworkCore", "src\QuestionsAnswers.EntityFrameworkCore\QuestionsAnswers.EntityFrameworkCore.csproj", "{DC780BC4-4EAC-4C63-9052-6F3169A59FA4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.Tests", "test\QuestionsAnswers.Tests\QuestionsAnswers.Tests.csproj", "{0D4C5D00-C144-4213-A007-4B8944113AB1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuestionsAnswers.Web.Tests", "test\QuestionsAnswers.Web.Tests\QuestionsAnswers.Web.Tests.csproj", "{5D441612-29CA-4DAD-9945-B9DE11CE026C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuestionsAnswers.Migrator", "src\QuestionsAnswers.Migrator\QuestionsAnswers.Migrator.csproj", "{32C6C8F8-F069-4ACD-BEE3-3DDE0333BEF0}"
|
||||
EndProject
|
||||
Global
|
||||
|
@ -43,14 +37,6 @@ Global
|
|||
{DC780BC4-4EAC-4C63-9052-6F3169A59FA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC780BC4-4EAC-4C63-9052-6F3169A59FA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC780BC4-4EAC-4C63-9052-6F3169A59FA4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0D4C5D00-C144-4213-A007-4B8944113AB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0D4C5D00-C144-4213-A007-4B8944113AB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0D4C5D00-C144-4213-A007-4B8944113AB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0D4C5D00-C144-4213-A007-4B8944113AB1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5D441612-29CA-4DAD-9945-B9DE11CE026C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5D441612-29CA-4DAD-9945-B9DE11CE026C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D441612-29CA-4DAD-9945-B9DE11CE026C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D441612-29CA-4DAD-9945-B9DE11CE026C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32C6C8F8-F069-4ACD-BEE3-3DDE0333BEF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32C6C8F8-F069-4ACD-BEE3-3DDE0333BEF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32C6C8F8-F069-4ACD-BEE3-3DDE0333BEF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@ -64,8 +50,6 @@ Global
|
|||
{0FA75A5B-AB83-4FD0-B545-279774C01E87} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC}
|
||||
{3870C648-4AEA-4B85-BA3F-F2F63B96136A} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC}
|
||||
{DC780BC4-4EAC-4C63-9052-6F3169A59FA4} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC}
|
||||
{0D4C5D00-C144-4213-A007-4B8944113AB1} = {F10AA149-2626-486E-85BB-9CD5365F3016}
|
||||
{5D441612-29CA-4DAD-9945-B9DE11CE026C} = {F10AA149-2626-486E-85BB-9CD5365F3016}
|
||||
{32C6C8F8-F069-4ACD-BEE3-3DDE0333BEF0} = {AFAA0841-BD93-466F-B8F4-FB4EEC86F1FC}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
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("QuestionsAnswers.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("0d4c5d00-c144-4213-a007-4b8944113ab1")]
|
|
@ -1,35 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<AssemblyName>QuestionsAnswers.Tests</AssemblyName>
|
||||
<PackageId>QuestionsAnswers.Tests</PackageId>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\QuestionsAnswers.Application\QuestionsAnswers.Application.csproj" />
|
||||
<ProjectReference Include="..\..\src\QuestionsAnswers.EntityFrameworkCore\QuestionsAnswers.EntityFrameworkCore.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Castle.Core" Version="5.1.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.6.2" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.6.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
<PackageReference Include="Abp.TestBase" Version="9.0.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="Castle.Windsor.MsDependencyInjection" Version="4.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,60 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Abp.TestBase;
|
||||
using QuestionsAnswers.EntityFrameworkCore;
|
||||
using QuestionsAnswers.Tests.TestDatas;
|
||||
|
||||
namespace QuestionsAnswers.Tests
|
||||
{
|
||||
public class QuestionsAnswersTestBase : AbpIntegratedTestBase<QuestionsAnswersTestModule>
|
||||
{
|
||||
public QuestionsAnswersTestBase()
|
||||
{
|
||||
UsingDbContext(context => new TestDataBuilder(context).Build());
|
||||
}
|
||||
|
||||
protected virtual void UsingDbContext(Action<QuestionsAnswersDbContext> action)
|
||||
{
|
||||
using (var context = LocalIocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
action(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual T UsingDbContext<T>(Func<QuestionsAnswersDbContext, T> func)
|
||||
{
|
||||
T result;
|
||||
|
||||
using (var context = LocalIocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
result = func(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual async Task UsingDbContextAsync(Func<QuestionsAnswersDbContext, Task> action)
|
||||
{
|
||||
using (var context = LocalIocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
await action(context);
|
||||
await context.SaveChangesAsync(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task<T> UsingDbContextAsync<T>(Func<QuestionsAnswersDbContext, Task<T>> func)
|
||||
{
|
||||
T result;
|
||||
|
||||
using (var context = LocalIocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
result = await func(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
using System.Reflection;
|
||||
using Abp.Modules;
|
||||
using Abp.Reflection.Extensions;
|
||||
using Abp.TestBase;
|
||||
using QuestionsAnswers.EntityFrameworkCore;
|
||||
using Castle.MicroKernel.Registration;
|
||||
using Castle.Windsor.MsDependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace QuestionsAnswers.Tests
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(QuestionsAnswersApplicationModule),
|
||||
typeof(QuestionsAnswersEntityFrameworkCoreModule),
|
||||
typeof(AbpTestBaseModule)
|
||||
)]
|
||||
public class QuestionsAnswersTestModule : AbpModule
|
||||
{
|
||||
public override void PreInitialize()
|
||||
{
|
||||
Configuration.UnitOfWork.IsTransactional = false; //EF Core InMemory DB does not support transactions.
|
||||
SetupInMemoryDb();
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
IocManager.RegisterAssemblyByConvention(typeof(QuestionsAnswersTestModule).GetAssembly());
|
||||
}
|
||||
|
||||
private void SetupInMemoryDb()
|
||||
{
|
||||
var services = new ServiceCollection()
|
||||
.AddEntityFrameworkInMemoryDatabase();
|
||||
|
||||
var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(
|
||||
IocManager.IocContainer,
|
||||
services
|
||||
);
|
||||
|
||||
var builder = new DbContextOptionsBuilder<QuestionsAnswersDbContext>();
|
||||
builder.UseInMemoryDatabase("Test").UseInternalServiceProvider(serviceProvider);
|
||||
|
||||
IocManager.IocContainer.Register(
|
||||
Component
|
||||
.For<DbContextOptions<QuestionsAnswersDbContext>>()
|
||||
.Instance(builder.Options)
|
||||
.LifestyleSingleton()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using QuestionsAnswers.EntityFrameworkCore;
|
||||
|
||||
namespace QuestionsAnswers.Tests.TestDatas
|
||||
{
|
||||
public class TestDataBuilder
|
||||
{
|
||||
private readonly QuestionsAnswersDbContext _context;
|
||||
|
||||
public TestDataBuilder(QuestionsAnswersDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
//create test data here...
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using QuestionsAnswers.Web.Controllers;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace QuestionsAnswers.Web.Tests.Controllers
|
||||
{
|
||||
public class HomeController_Tests: QuestionsAnswersWebTestBase
|
||||
{
|
||||
[Fact]
|
||||
public async Task Index_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await GetResponseAsStringAsync(
|
||||
GetUrl<HomeController>(nameof(HomeController.Index))
|
||||
);
|
||||
|
||||
//Assert
|
||||
response.ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
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("QuestionsAnswers.Web.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("5d441612-29ca-4dad-9945-b9de11ce026c")]
|
|
@ -1,52 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<AssemblyName>QuestionsAnswers.Web.Tests</AssemblyName>
|
||||
<PackageId>QuestionsAnswers.Web.Tests</PackageId>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QuestionsAnswers.Tests\QuestionsAnswers.Tests.csproj" />
|
||||
<ProjectReference Include="..\..\src\QuestionsAnswers.Web\QuestionsAnswers.Web.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Castle.Core" Version="5.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
<PackageReference Include="xunit" Version="2.6.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Abp.AspNetCore.TestBase" Version="9.0.0" />
|
||||
<PackageReference Include="AngleSharp" Version="1.0.7" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<!-- Below ItemGroup and Target tags are added according to https://github.com/aspnet/Hosting/issues/959#issuecomment-286351703 -->
|
||||
<!-- Solves Problem#2 (404 when executing service calls hosted in other assemblies) -->
|
||||
<!-- https://github.com/Microsoft/vstest/issues/196.-->
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -1,129 +0,0 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Abp.AspNetCore.TestBase;
|
||||
using QuestionsAnswers.EntityFrameworkCore;
|
||||
using QuestionsAnswers.Tests.TestDatas;
|
||||
using QuestionsAnswers.Web.Controllers;
|
||||
using QuestionsAnswers.Web.Startup;
|
||||
using QuestionsAnswers.Web.Tests.Controllers;
|
||||
using AngleSharp.Html.Dom;
|
||||
using AngleSharp.Html.Parser;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Shouldly;
|
||||
|
||||
namespace QuestionsAnswers.Web.Tests
|
||||
{
|
||||
public abstract class QuestionsAnswersWebTestBase : AbpAspNetCoreIntegratedTestBase<Startup>
|
||||
{
|
||||
protected static readonly Lazy<string> ContentRootFolder;
|
||||
|
||||
static QuestionsAnswersWebTestBase()
|
||||
{
|
||||
ContentRootFolder = new Lazy<string>(WebContentDirectoryFinder.CalculateContentRootFolder, true);
|
||||
}
|
||||
|
||||
protected QuestionsAnswersWebTestBase()
|
||||
{
|
||||
UsingDbContext(context => new TestDataBuilder(context).Build());
|
||||
}
|
||||
|
||||
protected override IWebHostBuilder CreateWebHostBuilder()
|
||||
{
|
||||
return base
|
||||
.CreateWebHostBuilder()
|
||||
.UseContentRoot(ContentRootFolder.Value)
|
||||
.UseSetting(WebHostDefaults.ApplicationKey, typeof(QuestionsAnswersWebModule).Assembly.FullName);
|
||||
}
|
||||
|
||||
#region Get response
|
||||
|
||||
protected async Task<T> GetResponseAsObjectAsync<T>(string url,
|
||||
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
|
||||
{
|
||||
var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode);
|
||||
return JsonConvert.DeserializeObject<T>(strResponse, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
});
|
||||
}
|
||||
|
||||
protected async Task<string> GetResponseAsStringAsync(string url,
|
||||
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
|
||||
{
|
||||
var response = await GetResponseAsync(url, expectedStatusCode);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
protected async Task<HttpResponseMessage> GetResponseAsync(string url,
|
||||
HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
|
||||
{
|
||||
var response = await Client.GetAsync(url);
|
||||
response.StatusCode.ShouldBe(expectedStatusCode);
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UsingDbContext
|
||||
|
||||
protected void UsingDbContext(Action<QuestionsAnswersDbContext> action)
|
||||
{
|
||||
using (var context = IocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
action(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected T UsingDbContext<T>(Func<QuestionsAnswersDbContext, T> func)
|
||||
{
|
||||
T result;
|
||||
|
||||
using (var context = IocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
result = func(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async Task UsingDbContextAsync(Func<QuestionsAnswersDbContext, Task> action)
|
||||
{
|
||||
using (var context = IocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
await action(context);
|
||||
await context.SaveChangesAsync(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<T> UsingDbContextAsync<T>(Func<QuestionsAnswersDbContext, Task<T>> func)
|
||||
{
|
||||
T result;
|
||||
|
||||
using (var context = IocManager.Resolve<QuestionsAnswersDbContext>())
|
||||
{
|
||||
result = await func(context);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ParseHtml
|
||||
|
||||
protected IHtmlDocument ParseHtml(string htmlString)
|
||||
{
|
||||
return new HtmlParser().ParseDocument(htmlString);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using Abp.AspNetCore.TestBase;
|
||||
using Abp.Modules;
|
||||
using Abp.Reflection.Extensions;
|
||||
using QuestionsAnswers.Web.Startup;
|
||||
namespace QuestionsAnswers.Web.Tests
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(QuestionsAnswersWebModule),
|
||||
typeof(AbpAspNetCoreTestBaseModule)
|
||||
)]
|
||||
public class QuestionsAnswersWebTestModule : AbpModule
|
||||
{
|
||||
public override void PreInitialize()
|
||||
{
|
||||
Configuration.UnitOfWork.IsTransactional = false; //EF Core InMemory DB does not support transactions.
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
IocManager.RegisterAssemblyByConvention(typeof(QuestionsAnswersWebTestModule).GetAssembly());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
using System;
|
||||
using Abp.AspNetCore;
|
||||
using Abp.AspNetCore.TestBase;
|
||||
using Abp.Dependency;
|
||||
using QuestionsAnswers.EntityFrameworkCore;
|
||||
using Castle.MicroKernel.Registration;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace QuestionsAnswers.Web.Tests
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddEntityFrameworkInMemoryDatabase();
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
//Configure Abp and Dependency Injection
|
||||
return services.AddAbp<QuestionsAnswersWebTestModule>(options =>
|
||||
{
|
||||
options.SetupTest();
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
UseInMemoryDb(app.ApplicationServices);
|
||||
|
||||
app.UseAbp(); //Initializes ABP framework.
|
||||
|
||||
app.UseExceptionHandler("/Error");
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
|
||||
private void UseInMemoryDb(IServiceProvider serviceProvider)
|
||||
{
|
||||
var builder = new DbContextOptionsBuilder<QuestionsAnswersDbContext>();
|
||||
builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);
|
||||
var options = builder.Options;
|
||||
|
||||
var iocManager = serviceProvider.GetRequiredService<IIocManager>();
|
||||
|
||||
iocManager.IocContainer
|
||||
.Register(
|
||||
Component.For<DbContextOptions<QuestionsAnswersDbContext>>()
|
||||
.Instance(options)
|
||||
.LifestyleSingleton()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"shadowCopy": false
|
||||
}
|
Загрузка…
Ссылка в новой задаче