Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

58 righe
2.1 KiB

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