using System; using System.Threading.Tasks; using DotNetCore.CAP.Abstractions; using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; using Microsoft.Extensions.DependencyInjection; using Moq; using Xunit; namespace DotNetCore.CAP.Test { public class CallbackMessageSenderTest { private IServiceProvider _provider; private Mock _mockCallbackPublisher; private Mock _mockContentSerializer; private Mock _mockMessagePack; public CallbackMessageSenderTest() { _mockCallbackPublisher = new Mock(); _mockContentSerializer = new Mock(); _mockMessagePack = new Mock(); var services = new ServiceCollection(); services.AddTransient(); services.AddLogging(); services.AddSingleton(_mockCallbackPublisher.Object); services.AddSingleton(_mockContentSerializer.Object); services.AddSingleton(_mockMessagePack.Object); _provider = services.BuildServiceProvider(); } [Fact] public async void SendAsync_CanSend() { // Arrange _mockCallbackPublisher .Setup(x => x.PublishCallbackAsync(It.IsAny())) .Returns(Task.CompletedTask).Verifiable(); _mockContentSerializer .Setup(x => x.Serialize(It.IsAny())) .Returns("").Verifiable(); _mockMessagePack .Setup(x => x.Pack(It.IsAny())) .Returns("").Verifiable(); var fixture = Create(); // Act await fixture.SendAsync(null, null, Mock.Of()); // Assert _mockCallbackPublisher.VerifyAll(); _mockContentSerializer.Verify(); _mockMessagePack.Verify(); } private CallbackMessageSender Create() => _provider.GetService(); } } namespace Samples { public interface IFoo { int Age { get; set; } string Name { get; set; } } public class FooTest { [Fact] public void CanSetProperty() { var mockFoo = new Mock(); mockFoo.Setup(x => x.Name).Returns("NameProerties"); Assert.Equal("NameProerties", mockFoo.Object.Name); } } }