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.
 
 
 

54 lines
1.9 KiB

  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Xunit;
  8. using Microsoft.Extensions.Logging;
  9. using Moq;
  10. namespace Cap.Consistency.Test
  11. {
  12. public class ConsistencyMessageManagerTest
  13. {
  14. [Fact]
  15. public void EnsureDefaultServicesDefaultsWithStoreWorks() {
  16. var services = new ServiceCollection()
  17. .AddTransient<IConsistencyMessageStore<TestConsistencyMessage>, NoopMessageStore>();
  18. services.AddConsistency<TestConsistencyMessage>();
  19. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  20. services.AddLogging();
  21. var manager = services.BuildServiceProvider()
  22. .GetRequiredService<ConsistencyMessageManager<TestConsistencyMessage>>();
  23. Assert.NotNull(manager);
  24. }
  25. [Fact]
  26. public void AddMessageManagerWithCustomerMannagerReturnsSameInstance() {
  27. var services = new ServiceCollection()
  28. .AddTransient<IConsistencyMessageStore<TestConsistencyMessage>, NoopMessageStore>()
  29. .AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  30. services.AddLogging();
  31. services.AddConsistency<TestConsistencyMessage>()
  32. .AddConsistencyMessageManager<CustomMessageManager>();
  33. var provider = services.BuildServiceProvider();
  34. Assert.Same(provider.GetRequiredService<ConsistencyMessageManager<TestConsistencyMessage>>(),
  35. provider.GetRequiredService<CustomMessageManager>());
  36. }
  37. public class CustomMessageManager : ConsistencyMessageManager<TestConsistencyMessage>
  38. {
  39. public CustomMessageManager()
  40. : base(new Mock<IConsistencyMessageStore<TestConsistencyMessage>>().Object, null, null) {
  41. }
  42. }
  43. }
  44. }