Commit 013c6169 authored by yangxiaodong's avatar yangxiaodong

Add unit tests of CAP builder.

parent d4074414
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Moq" Version="4.7.10" /> <PackageReference Include="Moq" Version="4.7.63" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
......
using System;
using System.Threading;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Job;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace DotNetCore.CAP.Test
{
public class CapBuilderTest
{
[Fact]
public void CanOverrideMessageStore()
{
var services = new ServiceCollection();
services.AddConsistency().AddMessageStore<MyMessageStore>();
var thingy = services.BuildServiceProvider()
.GetRequiredService<ICapMessageStore>() as MyMessageStore;
Assert.NotNull(thingy);
}
[Fact]
public void CanOverrideJobs()
{
var services = new ServiceCollection();
services.AddConsistency().AddJobs<MyJobTest>();
var thingy = services.BuildServiceProvider()
.GetRequiredService<IJob>() as MyJobTest;
Assert.NotNull(thingy);
}
[Fact]
public void CanOverrideProducerService()
{
var services = new ServiceCollection();
services.AddConsistency().AddProducerService<MyProducerService>();
var thingy = services.BuildServiceProvider()
.GetRequiredService<ICapProducerService>() as MyProducerService;
Assert.NotNull(thingy);
}
private class MyProducerService : ICapProducerService
{
public Task SendAsync(string topic, string content)
{
throw new NotImplementedException();
}
}
private class MyJobTest : IJob
{
public Task ExecuteAsync()
{
throw new NotImplementedException();
}
}
private class MyMessageStore : ICapMessageStore
{
public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<ConsistencyMessage> GetFirstEnqueuedMessageAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
}
\ No newline at end of file
//using System;
//using System.Threading;
//using System.Threading.Tasks;
//using DotNetCore.CAP.Infrastructure;
//using DotNetCore.CAP.Store;
//using Microsoft.Extensions.DependencyInjection;
//using Xunit;
//namespace DotNetCore.CAP.Test
//{
// public class ConsistencyBuilderTest
// {
// [Fact]
// public void CanOverrideMessageStore() {
// var services = new ServiceCollection();
// services.AddConsistency().AddMessageStore<MyUberThingy>();
// var thingy = services.BuildServiceProvider().GetRequiredService<IConsistencyMessageStore>() as MyUberThingy;
// Assert.NotNull(thingy);
// }
// private class MyUberThingy : IConsistencyMessageStore
// {
// public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// public void Dispose() {
// throw new NotImplementedException();
// }
// public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// public Task<string> GetMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken) {
// throw new NotImplementedException();
// }
// }
// }
//}
\ No newline at end of file
//using System;
//using System.Threading;
//using System.Threading.Tasks;
//using DotNetCore.CAP.Infrastructure;
//using DotNetCore.CAP.Store;
//using Microsoft.AspNetCore.Http;
//using Microsoft.Extensions.DependencyInjection;
//using Microsoft.Extensions.Logging;
//using Moq;
//using Xunit;
//namespace DotNetCore.CAP.Test
//{
// public class ConsistencyMessageManagerTest
// {
// [Fact]
// public void EnsureDefaultServicesDefaultsWithStoreWorks() {
// var services = new ServiceCollection()
// .AddTransient<IConsistencyMessageStore, NoopMessageStore>();
// services.AddConsistency();
// services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// services.AddLogging();
// var manager = services.BuildServiceProvider()
// .GetRequiredService<IConsistencyMessageStore >();
// Assert.NotNull(manager);
// }
// [Fact]
// public void AddMessageManagerWithCustomerMannagerReturnsSameInstance() {
// var services = new ServiceCollection()
// .AddTransient<IConsistencyMessageStore, NoopMessageStore>()
// .AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// services.AddLogging();
// //services.AddConsistency()
// // .AddConsistencyMessageManager<CustomMessageManager>();
// var provider = services.BuildServiceProvider();
// Assert.Same(provider.GetRequiredService<IConsistencyMessageStore >(),
// provider.GetRequiredService<CustomMessageManager>());
// }
// public class CustomMessageManager : IConsistencyMessageStore
// {
// public CustomMessageManager()
// : base(new Mock<IConsistencyMessageStore>().Object, null, null) {
// }
// }
// [Fact]
// public async Task CreateCallsStore() {
// var store = new Mock<IConsistencyMessageStore>();
// var message = new ConsistencyMessage { SendTime = DateTime.Now };
// store.Setup(x => x.CreateAsync(message, CancellationToken.None)).ReturnsAsync(OperateResult.Success).Verifiable();
// var messageManager = TestConsistencyMessageManager(store.Object);
// var result = await messageManager.CreateAsync(message);
// Assert.True(result.Succeeded);
// store.VerifyAll();
// }
// public IConsistencyMessageStore TestConsistencyMessageManager(IConsistencyMessageStore store = null) {
// store = store ?? new Mock<IConsistencyMessageStore>().Object;
// var mockLogger = new Mock<ILogger<IConsistencyMessageStore >>().Object;
// var manager = new IConsistencyMessageStore (store, null, mockLogger);
// return manager;
// }
// }
//}
\ No newline at end of file
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
{ {
public class ConsistencyOptionsTest public class ConsistencyOptionsTest
{ {
} }
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Moq" Version="4.7.10" /> <PackageReference Include="Moq" Version="4.7.63" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
</ItemGroup> </ItemGroup>
...@@ -32,4 +32,8 @@ ...@@ -32,4 +32,8 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Job\" />
</ItemGroup>
</Project> </Project>
//using System; using System;
//using System.Threading; using System.Threading;
//using System.Threading.Tasks; using System.Threading.Tasks;
//using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Infrastructure;
//using DotNetCore.CAP.Store;
namespace DotNetCore.CAP.Test
//namespace DotNetCore.CAP.Test {
//{ public class NoopMessageStore : ICapMessageStore
// public class NoopMessageStore : IConsistencyMessageStore {
// { public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken)
// public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { {
// throw new NotImplementedException(); throw new NotImplementedException();
// } }
// public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken) { public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken)
// throw new NotImplementedException(); {
// } throw new NotImplementedException();
}
// public void Dispose() {
// throw new NotImplementedException(); public void Dispose()
// } {
throw new NotImplementedException();
// public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { }
// throw new NotImplementedException();
// } public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken)
{
// public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { throw new NotImplementedException();
// throw new NotImplementedException(); }
// }
public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken)
// public Task<string> GetMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { {
// throw new NotImplementedException(); throw new NotImplementedException();
// } }
// public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { public Task<ConsistencyMessage> GetFirstEnqueuedMessageAsync(CancellationToken cancellationToken)
// throw new NotImplementedException(); {
// } throw new NotImplementedException();
// } }
//}
\ No newline at end of file public Task<string> GetMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment