Commit bfa24cee authored by yangxiaodong's avatar yangxiaodong

add unit test case

parent 9609c432
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>7442c942-1ddc-40e4-8f1b-654e721eaa45</ProjectGuid> <ProjectGuid>7442c942-1ddc-40e4-8f1b-654e721eaa45</ProjectGuid>
...@@ -13,9 +12,11 @@ ...@@ -13,9 +12,11 @@
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project> </Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Cap.Consistency.EntityFrameworkCore.Test
{
public class DefaultPocoTest : IClassFixture<ScratchDatabaseFixture>
{
private readonly ApplicationBuilder _builder;
public DefaultPocoTest(ScratchDatabaseFixture fixture) {
var services = new ServiceCollection();
services
.AddDbContext<ConsistencyDbContext>(o => o.UseSqlServer(fixture.ConnectionString))
.AddConsistency<ConsistencyMessage>()
.AddEntityFrameworkStores<ConsistencyDbContext>();
services.AddLogging();
var provider = services.BuildServiceProvider();
_builder = new ApplicationBuilder(provider);
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var db = scoped.ServiceProvider.GetRequiredService<ConsistencyDbContext>()) {
db.Database.EnsureCreated();
}
}
[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task EnsureStartupUsageWorks() {
var messageStore = _builder.ApplicationServices.GetRequiredService<IConsistencyMessageStore<ConsistencyMessage>>();
var messageManager = _builder.ApplicationServices.GetRequiredService<ConsistencyMessageManager<ConsistencyMessage>>();
Assert.NotNull(messageStore);
Assert.NotNull(messageManager);
var user = new ConsistencyMessage();
var operateResult = await messageManager.CreateAsync(user);
Assert.True(operateResult.Succeeded);
operateResult = await messageManager.DeleteAsync(user);
Assert.True(operateResult.Succeeded);
}
}
}
using System; using System;
using Cap.Consistency.EntityFrameworkCore.Test.Utilities;
using Cap.Consistency.Test; using Cap.Consistency.Test;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
......
...@@ -4,7 +4,7 @@ using System.Data.SqlClient; ...@@ -4,7 +4,7 @@ using System.Data.SqlClient;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
namespace Cap.Consistency.EntityFrameworkCore.Test.Utilities namespace Cap.Consistency.EntityFrameworkCore.Test
{ {
public class SqlServerTestStore : IDisposable public class SqlServerTestStore : IDisposable
{ {
......
using System.IO; using System.IO;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
namespace Cap.Consistency.EntityFrameworkCore.Test.Utilities namespace Cap.Consistency.EntityFrameworkCore.Test
{ {
public class TestEnvironment public class TestEnvironment
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment