|
using System;
using Raven.Client.Document;
using Raven.Client.Tests.Document;
using Xunit;
using System.Collections.Generic;
using Rhino.Mocks;
using Raven.Client.Shard.ShardStrategy.ShardAccess;
using System.Linq;
namespace Raven.Client.Tests.Shard
{
public class When_Using_Parallel_Access_Strategy : BaseTest
{
[Fact]
public void Can_get_complete_result_list()
{
var shard1 = MockRepository.GenerateStub<IDocumentSession>();
var documentQuery1 = MockRepository.GenerateStub<IDocumentQuery<Company>>();
shard1.Stub(x => x.Query<Company>().GetEnumerator())
.Return(new List<Company> { new Company { Name = "Company1" } }.GetEnumerator());
var shard2 = MockRepository.GenerateStub<IDocumentSession>();
shard2.Stub(x => x.Query<Company>().GetEnumerator())
.Return(new List<Company> { new Company { Name = "Company2" } }.GetEnumerator());
var results = new ParallelShardAccessStrategy().Apply(new[] { shard1, shard2 }, x => x.Query<Company>().ToArray());
Assert.Equal(2, results.Count);
}
[Fact]
public void Null_result_is_not_an_exception()
{
var shard1 = MockRepository.GenerateStub<IDocumentSession>();
var results = new ParallelShardAccessStrategy().Apply(new[] { shard1 }, x => (IList<Company>)null);
Assert.Equal(0, results.Count);
}
[Fact]
public void Execution_exceptions_are_rethrown()
{
var shard1 = MockRepository.GenerateStub<IDocumentSession>();
shard1.Stub(x => x.Query<Company>()).Throw(new ApplicationException("Oh noes!"));
Assert.Throws(typeof(ApplicationException), () =>
{
new ParallelShardAccessStrategy().Apply(new[] { shard1 }, x => x.Query<Company>().ToArray());
});
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.