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.
 
 
 

63 line
2.0 KiB

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