Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CallbackMessageSenderTest.cs 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP.Abstractions;
  4. using DotNetCore.CAP.Internal;
  5. using DotNetCore.CAP.Models;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Moq;
  8. using Xunit;
  9. namespace DotNetCore.CAP.Test
  10. {
  11. public class CallbackMessageSenderTest
  12. {
  13. private IServiceProvider _provider;
  14. private Mock<ICallbackPublisher> _mockCallbackPublisher;
  15. private Mock<IContentSerializer> _mockContentSerializer;
  16. private Mock<IMessagePacker> _mockMessagePack;
  17. public CallbackMessageSenderTest()
  18. {
  19. _mockCallbackPublisher = new Mock<ICallbackPublisher>();
  20. _mockContentSerializer = new Mock<IContentSerializer>();
  21. _mockMessagePack = new Mock<IMessagePacker>();
  22. var services = new ServiceCollection();
  23. services.AddTransient<CallbackMessageSender>();
  24. services.AddLogging();
  25. services.AddSingleton(_mockCallbackPublisher.Object);
  26. services.AddSingleton(_mockContentSerializer.Object);
  27. services.AddSingleton(_mockMessagePack.Object);
  28. _provider = services.BuildServiceProvider();
  29. }
  30. [Fact]
  31. public async void SendAsync_CanSend()
  32. {
  33. // Arrange
  34. _mockCallbackPublisher
  35. .Setup(x => x.PublishAsync(It.IsAny<CapPublishedMessage>()))
  36. .Returns(Task.CompletedTask).Verifiable();
  37. _mockContentSerializer
  38. .Setup(x => x.Serialize(It.IsAny<object>()))
  39. .Returns("").Verifiable();
  40. _mockMessagePack
  41. .Setup(x => x.Pack(It.IsAny<CapMessage>()))
  42. .Returns("").Verifiable();
  43. var fixture = Create();
  44. // Act
  45. await fixture.SendAsync(null, null, Mock.Of<object>());
  46. // Assert
  47. _mockCallbackPublisher.VerifyAll();
  48. _mockContentSerializer.Verify();
  49. _mockMessagePack.Verify();
  50. }
  51. private CallbackMessageSender Create()
  52. => _provider.GetService<CallbackMessageSender>();
  53. }
  54. }
  55. namespace Samples
  56. {
  57. public interface IFoo
  58. {
  59. int Age { get; set; }
  60. string Name { get; set; }
  61. }
  62. public class FooTest
  63. {
  64. [Fact]
  65. public void CanSetProperty()
  66. {
  67. var mockFoo = new Mock<IFoo>();
  68. mockFoo.Setup(x => x.Name).Returns("NameProerties");
  69. Assert.Equal("NameProerties", mockFoo.Object.Name);
  70. }
  71. }
  72. }