Browse Source

add unit test case

master
yangxiaodong 7 years ago
parent
commit
bfa24ceefe
5 changed files with 63 additions and 6 deletions
  1. +4
    -3
      test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj
  2. +57
    -0
      test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs
  3. +0
    -1
      test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs
  4. +1
    -1
      test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs
  5. +1
    -1
      test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs

+ 4
- 3
test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj View File

@@ -4,7 +4,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>7442c942-1ddc-40e4-8f1b-654e721eaa45</ProjectGuid>
@@ -13,9 +12,11 @@
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>

+ 57
- 0
test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs View File

@@ -0,0 +1,57 @@
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);
}

}
}

+ 0
- 1
test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs View File

@@ -1,5 +1,4 @@
using System;
using Cap.Consistency.EntityFrameworkCore.Test.Utilities;
using Cap.Consistency.Test;
using Microsoft.AspNetCore.Testing;
using Microsoft.EntityFrameworkCore;


+ 1
- 1
test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs View File

@@ -4,7 +4,7 @@ using System.Data.SqlClient;
using System.IO;
using System.Threading;

namespace Cap.Consistency.EntityFrameworkCore.Test.Utilities
namespace Cap.Consistency.EntityFrameworkCore.Test
{
public class SqlServerTestStore : IDisposable
{


+ 1
- 1
test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs View File

@@ -1,7 +1,7 @@
using System.IO;
using Microsoft.Extensions.Configuration;

namespace Cap.Consistency.EntityFrameworkCore.Test.Utilities
namespace Cap.Consistency.EntityFrameworkCore.Test
{
public class TestEnvironment
{


Loading…
Cancel
Save