Git Product home page Git Product logo

Comments (2)

charlessolar avatar charlessolar commented on May 26, 2024

For foreign testing I envision a TestDomainUnitOfWork object which provides access to building repositories and entities, but stubs out message receiving and event saving. Instead providing easy methods to retrieve

  • the repositories used
  • the entities read
  • the entities changed
  • the events raised / applied

If you want to test a message handler such as

public class Handler :
        IHandleMessages<SayHello>
{
    public async Task Handle(SayHello command, IMessageHandlerContext ctx)
    {
        var world = await ctx.For<World>().TryGet("World");
        if (world == null)
            world = await ctx.For<World>().New("World");

        world.SayHello(command.Message);
    }
}

You would be able to write something like

[Fact]
public async Task should_say_hello() 
{
    var fixture = new Fixture().Customize(new AutoFakeIteasyCustomization());
    
    var uow = new TestDomainUnitOfWork();
    var context = new TestableMessageHandlerContext();

    // sets up eventstore to return an event for hydration
    uow.Read<World>("World").HasEvent<SaidHello>(x => x.Message = "Foo" ); 

    var handler = fixture.Create<Handler>();
    
    // calls command handler with specific command
    await handler.Handle(new SayHello {
        Message = "Bar"
    });

    // events raised in entities are retrievable and comparable
    Assert.True(uow.Saved<World>("World").WroteEvent<SaidHello>(x => x.Message = "Bar"));
}

from aggregates.net.

charlessolar avatar charlessolar commented on May 26, 2024

Addressing the testing library part of this issue - I completed a good stab of a real functional testing helper. Example here

[Theory, AutoFakeItEasyData]
        public async Task should_say_hello(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Test<Domain.World>().Plan("World").HasEvent<SaidHello>(x =>
            {
                x.Message = "foo";
            });

            await handler.Handle(new SayHello
            {
                Message = "test"
            }, context).ConfigureAwait(false);

            context.UoW.Test<Domain.World>().Check("World").Raised<SaidHello>(x =>
            {
                x.Message = "test";
            });
        }

from aggregates.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.