public static Task Expect(this ConnectedProjectionScenario <MemoryCache> scenario, params CacheItem[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(scenario.ExpectNone()); } return(scenario. Verify(cache => { if (cache.GetCount() != items.Length) { if (cache.GetCount() == 0) { return Task.FromResult( VerificationResult.Fail( string.Format("Expected {0} cache item(s), but found 0 cache items.", items.Length))); } return Task.FromResult( VerificationResult.Fail( string.Format("Expected {0} cache item(s), but found {1} cache item(s) ({2}).", items.Length, cache.GetCount(), string.Join(",", cache.Select(pair => pair.Key))))); } if (!cache.Select(pair => cache.GetCacheItem(pair.Key)).SequenceEqual(items, new CacheItemEqualityComparer())) { var builder = new StringBuilder(); builder.AppendLine("Expected the following cache items:"); foreach (var expectedItem in items) { builder.AppendLine(expectedItem.Key + ": " + JToken.FromObject(expectedItem.Value).ToString()); } builder.AppendLine(); builder.AppendLine("But found the following cache items:"); foreach (var actualItem in cache) { builder.AppendLine(actualItem.Key + ": " + JToken.FromObject(actualItem.Value).ToString()); } return Task.FromResult(VerificationResult.Fail(builder.ToString())); } return Task.FromResult(VerificationResult.Pass()); }). Assert()); }
public static Task Expect(this ConnectedProjectionScenario <IAsyncDocumentSession> scenario, params object[] documents) { if (documents == null) { throw new ArgumentNullException("documents"); } if (documents.Length == 0) { return(scenario.ExpectNone()); } return(scenario .Verify(async session => { using (var streamer = await session.Advanced.StreamAsync <object>(Etag.Empty)) { var storedDocuments = new List <object>(); var storedDocumentIdentifiers = new List <string>(); while (await streamer.MoveNextAsync()) { storedDocumentIdentifiers.Add(streamer.Current.Key); storedDocuments.Add(streamer.Current.Document); } if (documents.Length != storedDocumentIdentifiers.Count) { if (storedDocumentIdentifiers.Count == 0) { return VerificationResult.Fail( string.Format("Expected {0} document(s), but found 0 documents.", documents.Length)); } return VerificationResult.Fail( string.Format("Expected {0} document(s), but found {1} document(s) ({2}).", documents.Length, storedDocumentIdentifiers.Count, string.Join(",", storedDocumentIdentifiers))); } var expectedDocuments = documents.Select(JToken.FromObject).ToArray(); var actualDocuments = storedDocuments.Select(JToken.FromObject).ToArray(); if (!expectedDocuments.SequenceEqual(actualDocuments, new JTokenEqualityComparer())) { var builder = new StringBuilder(); builder.AppendLine("Expected the following documents:"); foreach (var expectedDocument in expectedDocuments) { builder.AppendLine(expectedDocument.ToString()); } builder.AppendLine(); builder.AppendLine("But found the following documents:"); foreach (var actualDocument in actualDocuments) { builder.AppendLine(actualDocument.ToString()); } return VerificationResult.Fail(builder.ToString()); } return VerificationResult.Pass(); } }) .Assert()); }