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.
 
 
 

62 lines
2.0 KiB

  1. using System;
  2. using Cap.Consistency.Infrastructure;
  3. using Cap.Consistency.Test;
  4. using Microsoft.AspNetCore.Testing;
  5. using Microsoft.EntityFrameworkCore;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Xunit;
  8. namespace Cap.Consistency.EntityFrameworkCore.Test
  9. {
  10. public class MessageStoreWithGenericsTest : MessageManagerTestBase<MessageWithGenerics, string>, IClassFixture<ScratchDatabaseFixture>
  11. {
  12. private readonly ScratchDatabaseFixture _fixture;
  13. public MessageStoreWithGenericsTest(ScratchDatabaseFixture fixture) {
  14. _fixture = fixture;
  15. }
  16. protected override void AddMessageStore(IServiceCollection services, object context = null) {
  17. services.AddSingleton<IConsistencyMessageStore<MessageWithGenerics>>(new MessageStoreWithGenerics((ContextWithGenerics)context));
  18. }
  19. protected override object CreateTestContext() {
  20. return CreateContext();
  21. }
  22. public ContextWithGenerics CreateContext() {
  23. var db = DbUtil.Create<ContextWithGenerics>(_fixture.ConnectionString);
  24. db.Database.EnsureCreated();
  25. return db;
  26. }
  27. protected override MessageWithGenerics CreateTestMessage(string payload = "") {
  28. return new MessageWithGenerics() {
  29. Payload = payload,
  30. SendTime = DateTime.Now,
  31. Status = MessageStatus.WaitForSend,
  32. UpdateTime = DateTime.Now
  33. };
  34. }
  35. protected override bool ShouldSkipDbTests() {
  36. return TestPlatformHelper.IsMono || !TestPlatformHelper.IsWindows;
  37. }
  38. }
  39. public class MessageWithGenerics : ConsistencyMessage
  40. {
  41. }
  42. public class MessageStoreWithGenerics : ConsistencyMessageStore<MessageWithGenerics>
  43. {
  44. public MessageStoreWithGenerics(DbContext context) : base(context) {
  45. }
  46. }
  47. public class ContextWithGenerics : ConsistencyDbContext<MessageWithGenerics, string>
  48. {
  49. public ContextWithGenerics(DbContextOptions options) : base(options) {
  50. }
  51. }
  52. }