public static async Task Assert(this ConnectedProjectionTestSpecification <LegacyContext> specification) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } var options = new DbContextOptionsBuilder <LegacyContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; using (var context = new LegacyContext(options)) { context.Database.EnsureCreated(); foreach (var message in specification.Messages) { await new ConnectedProjector <LegacyContext>(specification.Resolver) .ProjectAsync(context, message); await context.SaveChangesAsync(); } var result = await specification.Verification(context, CancellationToken.None); if (result.Failed) { throw new AssertionFailedException(result.Message); } } }
public static async Task Assert(this ConnectedProjectionTestSpecification <IAsyncDocumentSession> specification) { if (specification == null) { throw new ArgumentNullException("specification"); } using (var store = new EmbeddableDocumentStore { RunInMemory = true, DataDirectory = Path.GetTempPath() }) { store.Configuration.Storage.Voron.AllowOn32Bits = true; store.Initialize(); using (var session = store.OpenAsyncSession()) { await new ConnectedProjector <IAsyncDocumentSession>(specification.Resolver). ProjectAsync(session, specification.Messages); await session.SaveChangesAsync(); var result = await specification.Verification(session, CancellationToken.None); if (result.Failed) { throw new AssertionException(result.Message); } } } }
private static XunitException CreateFailedScenarioExceptionFor(this ConnectedProjectionTestSpecification <BackofficeContext> specification, VerificationResult result) { var title = string.Empty; var exceptionMessage = new StringBuilder() .AppendLine(title) .AppendTitleBlock("Given", specification.Messages, Formatters.NamedJsonMessage) .Append(result.Message); return(new XunitException(exceptionMessage.ToString())); }
public void MessagesReturnsExpectedResult() { var messages = new [] { new object(), new object() }; var sut = new ConnectedProjectionTestSpecification <object>( Resolve.WhenEqualToHandlerMessageType(new ConnectedProjectionHandler <object> [0]), messages, (session, token) => Task.FromResult(VerificationResult.Pass())); var result = sut.Messages; Assert.That(result, Is.SameAs(messages)); }
public void ResolverReturnsExpectedResult() { var resolver = Resolve.WhenEqualToHandlerMessageType(new ConnectedProjectionHandler <object> [0]); var sut = new ConnectedProjectionTestSpecification <object>( resolver, new object[0], (session, token) => Task.FromResult(VerificationResult.Pass())); var result = sut.Resolver; Assert.That(result, Is.SameAs(resolver)); }
public void VerificationReturnsExpectedResult() { Func <object, CancellationToken, Task <VerificationResult> > verification = (session, token) => Task.FromResult(VerificationResult.Pass()); var sut = new ConnectedProjectionTestSpecification <object>( Resolve.WhenEqualToHandlerMessageType(new ConnectedProjectionHandler <object> [0]), new object[0], verification); var result = sut.Verification; Assert.That(result, Is.SameAs(verification)); }
public static async Task Assert(this ConnectedProjectionTestSpecification <MemoryCache> specification) { if (specification == null) { throw new ArgumentNullException("specification"); } using (var cache = new MemoryCache(new Random().Next().ToString())) { await new ConnectedProjector <MemoryCache>(specification.Resolver). ProjectAsync(cache, specification.Messages); var result = await specification.Verification(cache, CancellationToken.None); if (result.Failed) { throw new AssertionException(result.Message); } } }
public static async Task Assert <TContext>( this ConnectedProjectionTestSpecification <TContext> specification, Func <TContext> contextFactory, ILogger logger) where TContext : DbContext { var projector = new ConnectedProjector <TContext>(specification.Resolver); using (var ctx = contextFactory()) { ctx.Database.EnsureCreated(); logger.LogTrace($"Given: {Environment.NewLine}{specification.Messages.ToLogStringLimited(max: int.MaxValue)}"); var position = 0L; foreach (var message in specification.Messages.Select(e => new Envelope( e, new ConcurrentDictionary <string, object>( new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(Envelope.PositionMetadataKey, position++) }) ).ToGenericEnvelope())) { await projector.ProjectAsync(ctx, message); await ctx.SaveChangesAsync(); } var result = await specification.Verification(ctx, CancellationToken.None); if (result.Failed) #if NUNIT { throw new NUnit.Framework.AssertionException($"The verfication failed because: {result.Message}"); } #elif XUNIT { throw new Xunit.Sdk.XunitException($"The verfication failed because: {result.Message}"); } #endif logger.LogTrace(result.Message); } }
protected async Task Assert(ConnectedProjectionTestSpecification <TContext> specification) { await specification.Assert(CreateContext, _logger); }