Browse Source

add test case

master
yangxiaodong 8 years ago
parent
commit
9848558c9d
5 changed files with 149 additions and 0 deletions
  1. +48
    -0
      test/Cap.Consistency.Test/ConsistencyBuilderTest.cs
  2. +17
    -0
      test/Cap.Consistency.Test/ConsistencyMessageManagerTest.cs
  3. +35
    -0
      test/Cap.Consistency.Test/NoopMessageStore.cs
  4. +27
    -0
      test/Cap.Consistency.Test/OperateResultTest.cs
  5. +22
    -0
      test/Shared/TestConsistencyMessage.cs

+ 48
- 0
test/Cap.Consistency.Test/ConsistencyBuilderTest.cs View File

@@ -0,0 +1,48 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using System.Threading;

namespace Cap.Consistency.Test
{
public class ConsistencyBuilderTest
{
[Fact]
public void CanOverrideMessageStore() {
var services = new ServiceCollection();
services.AddConsistency<TestConsistencyMessage>().AddMessageStore<MyUberThingy>();
var thingy = services.BuildServiceProvider().GetRequiredService<IConsistencyMessageStore<TestConsistencyMessage>>() as MyUberThingy;
Assert.NotNull(thingy);
}

private class MyUberThingy : IConsistencyMessageStore<TestConsistencyMessage>
{
public Task<OperateResult> CreateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<OperateResult> DeleteAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public void Dispose() {
throw new NotImplementedException();
}

public Task<TestConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<string> GetMessageIdAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<OperateResult> UpdateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}
}
}
}

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

@@ -0,0 +1,17 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Cap.Consistency.Test
{
public class ConsistencyMessageManagerTest
{
[Fact]
public void EnsureDefaultServicesDefaultsWithStoreWorks() {
var services = new ServiceCollection().AddTransient<IConsistencyMessageStore<TestConsistencyMessage>, NoopMessageStore>();
}
}
}

+ 35
- 0
test/Cap.Consistency.Test/NoopMessageStore.cs View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Cap.Consistency.Test
{
public class NoopMessageStore : IConsistencyMessageStore<TestConsistencyMessage>
{
public Task<OperateResult> CreateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<OperateResult> DeleteAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public void Dispose() {
throw new NotImplementedException();
}

public Task<TestConsistencyMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<string> GetMessageIdAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}

public Task<OperateResult> UpdateAsync(TestConsistencyMessage message, CancellationToken cancellationToken) {
throw new NotImplementedException();
}
}
}

+ 27
- 0
test/Cap.Consistency.Test/OperateResultTest.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Cap.Consistency.Test
{
public class OperateResultTest
{
[Fact]
public void VerifyDefaultConstructor() {
var result = new OperateResult();

Assert.False(result.Succeeded);
Assert.Equal(0, result.Errors.Count());
}

[Fact]
public void NullFaildUsesEmptyErrors() {
var result = OperateResult.Failed();

Assert.False(result.Succeeded);
Assert.Equal(0, result.Errors.Count());
}
}
}

+ 22
- 0
test/Shared/TestConsistencyMessage.cs View File

@@ -0,0 +1,22 @@
using System;

namespace Cap.Consistency.Test
{
public class TestConsistencyMessage : TestConsistencyMessage<string>
{
public TestConsistencyMessage() {
Id = Guid.NewGuid().ToString();
}
}


public class TestConsistencyMessage<TKey> where TKey : IEquatable<TKey>
{
public TestConsistencyMessage() { }

public virtual TKey Id { get; set; }

public virtual DateTime Time { get; set; }
}

}

Loading…
Cancel
Save