Exemple #1
0
        public static Task ExpectNone(this ProjectionScenario <IAsyncDocumentSession> scenario)
        {
            return(scenario
                   .Verify(async session =>
            {
                using (var streamer = await session.Advanced.StreamAsync <RavenJObject>(Etag.Empty))
                {
                    if (await streamer.MoveNextAsync())
                    {
                        var storedDocumentIdentifiers = new List <string>();
                        do
                        {
                            storedDocumentIdentifiers.Add(streamer.Current.Key);
                        } while (await streamer.MoveNextAsync());

                        return VerificationResult.Fail(
                            string.Format("Expected no documents, but found {0} document(s) ({1}).",
                                          storedDocumentIdentifiers.Count,
                                          string.Join(",", storedDocumentIdentifiers)));
                    }
                    return VerificationResult.Pass();
                }
            })
                   .Assert());
        }
Exemple #2
0
 public void SetUp()
 {
     _resolver = Resolve.
                 WhenEqualToHandlerMessageType(new ProjectionHandler <object> [0]);
     _messages = new[] { new object(), new object() };
     _sut      = new ProjectionScenario <object>(_resolver).Given(_messages);
 }
        public Task EventProjectionScenario(Action <ProjectionScenario> configuration)
        {
            var scenario = new ProjectionScenario(_store);

            configuration(scenario);

            return(scenario.Execute());
        }
Exemple #4
0
        public static Task Expect(this ProjectionScenario <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());
        }
Exemple #5
0
 public static Task ExpectNone(this ProjectionScenario <MemoryCache> scenario)
 {
     return(scenario.
            Verify(cache =>
     {
         if (cache.GetCount() != 0)
         {
             return Task.FromResult(
                 VerificationResult.Fail(
                     string.Format("Expected no cache items, but found {0} cache item(s) ({1}).",
                                   cache.GetCount(),
                                   string.Join(",", cache.Select(pair => pair.Key)))));
         }
         return Task.FromResult(VerificationResult.Pass());
     }).
            Assert());
 }
Exemple #6
0
        public static Task Expect(this ProjectionScenario <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());
        }