Comments (2)
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.
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)
- Migrate to Actions
- Any plan to write a comprehensive documentation HOT 1
- Adding EventStore to my endpoint fails HOT 7
- ProjectionsManager is failing because there's no SSL certificate available. HOT 6
- Isn't there a way to NOT use EventStore? HOT 3
- Error when calling Apply method in the Domain app HOT 6
- How to catch BusinessException in custom built behavior? HOT 14
- Writing to EventStore is taking so much time, sometimes it doesn't work, and events don't reach directly to Application endpoint. HOT 8
- Taking snapshot to speed reading from EventStore HOT 3
- Inheritance in models HOT 1
- Replay all events if application endpoint version upgraded HOT 2
- Sagas Doesn't Work HOT 16
- Setting Correlation Id Can Make NSB Throw HOT 1
- Migrate logging to Microsoft.Extensions.Logging.Abstractions HOT 1
- Add development mode option
- Force Microsoft DI and Logging Infrastructure HOT 2
- Use correct mime type for message content type
- ScopeValidation of DI when in Production Mode HOT 10
- IApplicationUnitOfWork not present in TestableContext HOT 3
- Testing - Child Entity - Multipe Events HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aggregates.net.