@@ -1,6 +1,8 @@ | |||
using System; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
using Cap.Consistency.Infrastructure; | |||
using Cap.Consistency.Store; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Xunit; | |||
@@ -11,18 +13,18 @@ namespace Cap.Consistency.Test | |||
[Fact] | |||
public void CanOverrideMessageStore() { | |||
var services = new ServiceCollection(); | |||
services.AddConsistency<TestConsistencyMessage>().AddMessageStore<MyUberThingy>(); | |||
var thingy = services.BuildServiceProvider().GetRequiredService<IConsistencyMessageStore<TestConsistencyMessage>>() as MyUberThingy; | |||
services.AddConsistency().AddMessageStore<MyUberThingy>(); | |||
var thingy = services.BuildServiceProvider().GetRequiredService<IConsistencyMessageStore>() as MyUberThingy; | |||
Assert.NotNull(thingy); | |||
} | |||
private class MyUberThingy : IConsistencyMessageStore<TestConsistencyMessage> | |||
private class MyUberThingy : IConsistencyMessageStore | |||
{ | |||
public Task<OperateResult> CreateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> DeleteAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
@@ -30,15 +32,19 @@ namespace Cap.Consistency.Test | |||
throw new NotImplementedException(); | |||
} | |||
public Task<TestConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { | |||
public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<string> GetMessageIdAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> UpdateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<string> GetMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
} | |||
@@ -2,6 +2,7 @@ | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
using Cap.Consistency.Infrastructure; | |||
using Cap.Consistency.Store; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Logging; | |||
@@ -15,13 +16,13 @@ namespace Cap.Consistency.Test | |||
[Fact] | |||
public void EnsureDefaultServicesDefaultsWithStoreWorks() { | |||
var services = new ServiceCollection() | |||
.AddTransient<IConsistencyMessageStore<TestConsistencyMessage>, NoopMessageStore>(); | |||
services.AddConsistency<TestConsistencyMessage>(); | |||
.AddTransient<IConsistencyMessageStore, NoopMessageStore>(); | |||
services.AddConsistency(); | |||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | |||
services.AddLogging(); | |||
var manager = services.BuildServiceProvider() | |||
.GetRequiredService<ConsistencyMessageManager<TestConsistencyMessage>>(); | |||
.GetRequiredService<ConsistencyMessageManager>(); | |||
Assert.NotNull(manager); | |||
} | |||
@@ -29,31 +30,31 @@ namespace Cap.Consistency.Test | |||
[Fact] | |||
public void AddMessageManagerWithCustomerMannagerReturnsSameInstance() { | |||
var services = new ServiceCollection() | |||
.AddTransient<IConsistencyMessageStore<TestConsistencyMessage>, NoopMessageStore>() | |||
.AddTransient<IConsistencyMessageStore, NoopMessageStore>() | |||
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | |||
services.AddLogging(); | |||
services.AddConsistency<TestConsistencyMessage>() | |||
.AddConsistencyMessageManager<CustomMessageManager>(); | |||
//services.AddConsistency() | |||
// .AddConsistencyMessageManager<CustomMessageManager>(); | |||
var provider = services.BuildServiceProvider(); | |||
Assert.Same(provider.GetRequiredService<ConsistencyMessageManager<TestConsistencyMessage>>(), | |||
Assert.Same(provider.GetRequiredService<ConsistencyMessageManager>(), | |||
provider.GetRequiredService<CustomMessageManager>()); | |||
} | |||
public class CustomMessageManager : ConsistencyMessageManager<TestConsistencyMessage> | |||
public class CustomMessageManager : ConsistencyMessageManager | |||
{ | |||
public CustomMessageManager() | |||
: base(new Mock<IConsistencyMessageStore<TestConsistencyMessage>>().Object, null, null) { | |||
: base(new Mock<IConsistencyMessageStore>().Object, null, null) { | |||
} | |||
} | |||
[Fact] | |||
public async Task CreateCallsStore() { | |||
var store = new Mock<IConsistencyMessageStore<TestConsistencyMessage>>(); | |||
var message = new TestConsistencyMessage { SendTime = DateTime.Now }; | |||
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); | |||
@@ -63,11 +64,11 @@ namespace Cap.Consistency.Test | |||
store.VerifyAll(); | |||
} | |||
public ConsistencyMessageManager<TMessage> TestConsistencyMessageManager<TMessage>(IConsistencyMessageStore<TMessage> store = null) | |||
where TMessage : ConsistencyMessage { | |||
store = store ?? new Mock<IConsistencyMessageStore<TMessage>>().Object; | |||
var mockLogger = new Mock<ILogger<ConsistencyMessageManager<TMessage>>>().Object; | |||
var manager = new ConsistencyMessageManager<TMessage>(store, null, mockLogger); | |||
public ConsistencyMessageManager TestConsistencyMessageManager(IConsistencyMessageStore store = null) | |||
{ | |||
store = store ?? new Mock<IConsistencyMessageStore>().Object; | |||
var mockLogger = new Mock<ILogger<ConsistencyMessageManager>>().Object; | |||
var manager = new ConsistencyMessageManager(store, null, mockLogger); | |||
return manager; | |||
} | |||
} |
@@ -1,16 +1,18 @@ | |||
using System; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
using Cap.Consistency.Infrastructure; | |||
using Cap.Consistency.Store; | |||
namespace Cap.Consistency.Test | |||
{ | |||
public class NoopMessageStore : IConsistencyMessageStore<TestConsistencyMessage> | |||
public class NoopMessageStore : IConsistencyMessageStore | |||
{ | |||
public Task<OperateResult> CreateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<OperateResult> CreateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> DeleteAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<OperateResult> DeleteAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
@@ -18,15 +20,19 @@ namespace Cap.Consistency.Test | |||
throw new NotImplementedException(); | |||
} | |||
public Task<TestConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { | |||
public Task<ConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<string> GetMessageIdAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<string> GeConsistencyMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> UpdateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) { | |||
public Task<string> GetMessageIdAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
public Task<OperateResult> UpdateAsync(ConsistencyMessage message, CancellationToken cancellationToken) { | |||
throw new NotImplementedException(); | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using System.Linq; | |||
using Cap.Consistency.Store; | |||
using Xunit; | |||
namespace Cap.Consistency.Test | |||