Browse Source

add test case

master
yangxiaodong 8 years ago
parent
commit
11102034c6
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      test/Cap.Consistency.Test/ConsistencyMessageManagerTest.cs

+ 22
- 0
test/Cap.Consistency.Test/ConsistencyMessageManagerTest.cs View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Xunit;
using Microsoft.Extensions.Logging;
using Moq;
using System.Threading;

namespace Cap.Consistency.Test
{
@@ -49,5 +50,26 @@ namespace Cap.Consistency.Test
: base(new Mock<IConsistencyMessageStore<TestConsistencyMessage>>().Object, null, null) {
}
}

[Fact]
public async Task CreateCallsStore() {
var store = new Mock<IConsistencyMessageStore<TestConsistencyMessage>>();
var message = new TestConsistencyMessage { Time = 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 ConsistencyMessageManager<TMessage> TestConsistencyMessageManager<TMessage>(IConsistencyMessageStore<TMessage> store = null)
where TMessage : class {
store = store ?? new Mock<IConsistencyMessageStore<TMessage>>().Object;
var mockLogger = new Mock<ILogger<ConsistencyMessageManager<TMessage>>>().Object;
var manager = new ConsistencyMessageManager<TMessage>(store, null, mockLogger);
return manager;
}
}
}

Loading…
Cancel
Save