charlessolar / Aggregates.NET

.NET event sourced domain driven design model via NServiceBus and GetEventStore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IApplicationUnitOfWork not present in TestableContext

galenp opened this issue · comments

commented

Hi Charles

I have the following test designed to test a projection into RavenDb:


 public class VisitDetailsProjectionTests
    {
        [Theory(Skip = "BUG in testable context"), AutoFakeItEasyData]
        public async Task OnInitialisedFromDraft(TestableContext context,
            VisitDetailsProjection handler,
            string initiatorEmail,
            string visitorAdminEmail,
            string siteRepEmail,
            string status,
            string orderRef,
            string projectRef)
        {
            Guid visitId = context.Id("VISIT_ID");
            Guid requestId = context.Id("REQUEST_ID");
            var id = $"VisitDetails/{visitId}";

            var @event = context.Create<CreatedFromRequest>(x =>
            {
                x.VisitId = visitId;
                x.RequestId = requestId;
                x.InitiatorEmail = initiatorEmail;
                x.VisitorAdminEmail = visitorAdminEmail;
                x.SiteRepEmail = siteRepEmail;
                x.Status = status;
                x.OrderRef = orderRef;
                x.ProjectRef = projectRef;
            });

            await handler.Handle(@event, context).ConfigureAwait(false);

            context.App.Check<VisitDetails>(id).Added(x =>
            {
                x.Key.Should().Be(visitId, "id should match");
                x.VisitRequestId.Should().Be(requestId, "request id should match");
                x.InitiatedByEmail.Should().Be(initiatorEmail, "initiator email should match");
                x.SiteRepEmail.Should().Be(siteRepEmail, "site rep email should match");
                x.VisitorAdminEmail.Should().Be(visitorAdminEmail, "visitor admin email should match");
                x.Status.Should().Be(status, "status should match");
                x.OrderRef.Should().Be(orderRef, "order ref should match");
                x.ProjectRef.Should().Be(projectRef, "project ref should match");
                return true;
            });
        }
    }

This is blowing up in one of the ExtensionMethods because the .App() (IApplicationUnitOfWork) is empty in the TestableContext.
The .UoW() is present for what it's worth.

public static Task AddModel<T>(this IMessageHandlerContext context, Id id, IStampedEvent message, Func<T> handler) where T : class, IReadModel
       {
           try
           {
               var details = handler();
               details.LastModified = message.Stamp;
               return context.App().Add(id, details);
           }
           catch (Exception ex)
           {
               Error<T>("AddModel", $"error inserting record: {ex.Message}");
               return Task.CompletedTask;
           }
       }
  • Is there something additional that needs to be done in the testing project to define the AppUoW?
  • The .App is new for me compared to when i used this library previously. I couldn't find any test examples that used it.
commented

In TestableContext.cs


            _ctx.Extensions.Set("CommandDestination", "");
            _ctx.Extensions.Set<UnitOfWork.IDomainUnitOfWork>(UoW);
            **_ctx.Extensions.Set<UnitOfWork.IUnitOfWork>(App);**
            _ctx.Extensions.Set<IProcessor>(Processor);
            _ctx.Extensions.Set<IServiceProvider>(ServiceProvider);

Should that be IApplicationUnitOfWork instead of IUnitOfWork maybe?

Yes - IApplicationUnitOfWork integrates with the testing package better - use that interface