You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultPocoTest.cs 2.1 KiB

7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Cap.Consistency.Infrastructure;
  6. using Microsoft.AspNetCore.Builder.Internal;
  7. using Microsoft.AspNetCore.Testing.xunit;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Xunit;
  11. namespace Cap.Consistency.EntityFrameworkCore.Test
  12. {
  13. public class DefaultPocoTest : IClassFixture<ScratchDatabaseFixture>
  14. {
  15. private readonly ApplicationBuilder _builder;
  16. public DefaultPocoTest(ScratchDatabaseFixture fixture) {
  17. var services = new ServiceCollection();
  18. services
  19. .AddDbContext<ConsistencyDbContext>(o => o.UseSqlServer(fixture.ConnectionString))
  20. .AddConsistency<ConsistencyMessage>()
  21. .AddEntityFrameworkStores<ConsistencyDbContext>();
  22. services.AddLogging();
  23. var provider = services.BuildServiceProvider();
  24. _builder = new ApplicationBuilder(provider);
  25. using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
  26. using (var db = scoped.ServiceProvider.GetRequiredService<ConsistencyDbContext>()) {
  27. db.Database.EnsureCreated();
  28. }
  29. }
  30. [ConditionalFact]
  31. [FrameworkSkipCondition(RuntimeFrameworks.Mono)]
  32. [OSSkipCondition(OperatingSystems.Linux)]
  33. [OSSkipCondition(OperatingSystems.MacOSX)]
  34. public async Task EnsureStartupUsageWorks() {
  35. var messageStore = _builder.ApplicationServices.GetRequiredService<IConsistencyMessageStore<ConsistencyMessage>>();
  36. var messageManager = _builder.ApplicationServices.GetRequiredService<ConsistencyMessageManager<ConsistencyMessage>>();
  37. Assert.NotNull(messageStore);
  38. Assert.NotNull(messageManager);
  39. var user = new ConsistencyMessage();
  40. var operateResult = await messageManager.CreateAsync(user);
  41. Assert.True(operateResult.Succeeded);
  42. operateResult = await messageManager.DeleteAsync(user);
  43. Assert.True(operateResult.Succeeded);
  44. }
  45. }
  46. }