From bfa24ceefe211948f0cce11f6d5fc9a7701a2e61 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Thu, 29 Dec 2016 14:32:21 +0800 Subject: [PATCH] add unit test case --- ...Consistency.EntityFrameworkCore.Test.xproj | 7 ++- .../DefaultPocoTest.cs | 57 +++++++++++++++++++ .../MessageStoreWithGenericsTest.cs | 1 - .../Utilities/SqlServerTestStore.cs | 2 +- .../Utilities/TestEnvironment.cs | 2 +- 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs diff --git a/test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj b/test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj index 5b423d9..19c53e0 100644 --- a/test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj +++ b/test/Cap.Consistency.EntityFrameworkCore.Test/Cap.Consistency.EntityFrameworkCore.Test.xproj @@ -4,7 +4,6 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 7442c942-1ddc-40e4-8f1b-654e721eaa45 @@ -13,9 +12,11 @@ .\bin\ v4.6 - 2.0 + + + - + \ No newline at end of file diff --git a/test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs b/test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs new file mode 100644 index 0000000..0a5f82a --- /dev/null +++ b/test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs @@ -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 + { + private readonly ApplicationBuilder _builder; + + public DefaultPocoTest(ScratchDatabaseFixture fixture) { + var services = new ServiceCollection(); + + services + .AddDbContext(o => o.UseSqlServer(fixture.ConnectionString)) + .AddConsistency() + .AddEntityFrameworkStores(); + + services.AddLogging(); + + var provider = services.BuildServiceProvider(); + _builder = new ApplicationBuilder(provider); + + using (var scoped = provider.GetRequiredService().CreateScope()) + using (var db = scoped.ServiceProvider.GetRequiredService()) { + db.Database.EnsureCreated(); + } + } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono)] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public async Task EnsureStartupUsageWorks() { + var messageStore = _builder.ApplicationServices.GetRequiredService>(); + var messageManager = _builder.ApplicationServices.GetRequiredService>(); + + 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); + } + + } +} diff --git a/test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs b/test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs index 39a3c7f..7b29384 100644 --- a/test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs +++ b/test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs @@ -1,5 +1,4 @@ using System; -using Cap.Consistency.EntityFrameworkCore.Test.Utilities; using Cap.Consistency.Test; using Microsoft.AspNetCore.Testing; using Microsoft.EntityFrameworkCore; diff --git a/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs b/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs index c5b987d..7130b84 100644 --- a/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs +++ b/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/SqlServerTestStore.cs @@ -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 { diff --git a/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs b/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs index 79a00ff..70536d5 100644 --- a/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs +++ b/test/Cap.Consistency.EntityFrameworkCore.Test/Utilities/TestEnvironment.cs @@ -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 {