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.
 
 
 

168 lines
6.3 KiB

  1. namespace DotNetCore.CAP.EntityFrameworkCore.Test
  2. {
  3. //public class EFMessageStoreTest : DatabaseTestHost
  4. //{
  5. // [Fact]
  6. // public void CanCreateSentMessageUsingEF()
  7. // {
  8. // using (var db = CreateContext())
  9. // {
  10. // var guid = Guid.NewGuid().ToString();
  11. // var message = new CapPublishedMessage
  12. // {
  13. // Id = guid,
  14. // Content = "this is message body",
  15. // StatusName = StatusName.Enqueued
  16. // };
  17. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  18. // db.SaveChanges();
  19. // Assert.True(db.CapSentMessages.Any(u => u.Id == guid));
  20. // Assert.NotNull(db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
  21. // }
  22. // }
  23. // [Fact]
  24. // public void CanUpdateSentMessageUsingEF()
  25. // {
  26. // using (var db = CreateContext())
  27. // {
  28. // var guid = Guid.NewGuid().ToString();
  29. // var message = new CapPublishedMessage
  30. // {
  31. // Id = guid,
  32. // Content = "this is message body",
  33. // StatusName = StatusName.Enqueued
  34. // };
  35. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  36. // db.SaveChanges();
  37. // var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  38. // Assert.NotNull(selectedMessage);
  39. // selectedMessage.StatusName = StatusName.Succeeded;
  40. // selectedMessage.Content = "Test";
  41. // db.SaveChanges();
  42. // selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
  43. // Assert.NotNull(selectedMessage);
  44. // Assert.True(selectedMessage.Content == "Test");
  45. // }
  46. // }
  47. // [Fact]
  48. // public void CanRemoveSentMessageUsingEF()
  49. // {
  50. // using (var db = CreateContext())
  51. // {
  52. // var guid = Guid.NewGuid().ToString();
  53. // var message = new CapPublishedMessage
  54. // {
  55. // Id = guid,
  56. // Content = "this is message body",
  57. // StatusName = StatusName.Enqueued
  58. // };
  59. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  60. // db.SaveChanges();
  61. // var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  62. // Assert.NotNull(selectedMessage);
  63. // db.CapSentMessages.Remove(selectedMessage);
  64. // db.SaveChanges();
  65. // selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  66. // Assert.Null(selectedMessage);
  67. // }
  68. // }
  69. // [Fact]
  70. // public void CanCreateReceivedMessageUsingEF()
  71. // {
  72. // using (var db = CreateContext())
  73. // {
  74. // var guid = Guid.NewGuid().ToString();
  75. // var message = new CapReceivedMessage
  76. // {
  77. // Id = guid,
  78. // Content = "this is message body",
  79. // StatusName = StatusName.Enqueued
  80. // };
  81. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  82. // db.SaveChanges();
  83. // Assert.True(db.CapReceivedMessages.Any(u => u.Id == guid));
  84. // Assert.NotNull(db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
  85. // }
  86. // }
  87. // [Fact]
  88. // public void CanUpdateReceivedMessageUsingEF()
  89. // {
  90. // using (var db = CreateContext())
  91. // {
  92. // var guid = Guid.NewGuid().ToString();
  93. // var message = new CapReceivedMessage
  94. // {
  95. // Id = guid,
  96. // Content = "this is message body",
  97. // StatusName = StatusName.Enqueued
  98. // };
  99. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  100. // db.SaveChanges();
  101. // var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  102. // Assert.NotNull(selectedMessage);
  103. // selectedMessage.StatusName = StatusName.Succeeded;
  104. // selectedMessage.Content = "Test";
  105. // db.SaveChanges();
  106. // selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
  107. // Assert.NotNull(selectedMessage);
  108. // Assert.True(selectedMessage.Content == "Test");
  109. // }
  110. // }
  111. // [Fact]
  112. // public void CanRemoveReceivedMessageUsingEF()
  113. // {
  114. // using (var db = CreateContext())
  115. // {
  116. // var guid = Guid.NewGuid().ToString();
  117. // var message = new CapReceivedMessage
  118. // {
  119. // Id = guid,
  120. // Content = "this is message body",
  121. // StatusName = StatusName.Enqueued
  122. // };
  123. // db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
  124. // db.SaveChanges();
  125. // var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  126. // Assert.NotNull(selectedMessage);
  127. // db.CapReceivedMessages.Remove(selectedMessage);
  128. // db.SaveChanges();
  129. // selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
  130. // Assert.Null(selectedMessage);
  131. // }
  132. // }
  133. // public TestDbContext CreateContext(bool delete = false)
  134. // {
  135. // var db = Provider.GetRequiredService<TestDbContext>();
  136. // if (delete)
  137. // {
  138. // db.Database.EnsureDeleted();
  139. // }
  140. // db.Database.EnsureCreated();
  141. // return db;
  142. // }
  143. //}
  144. }