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.
 
 
 

61 lines
2.0 KiB

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