File tree 8 files changed +52
-13
lines changed
Sample/EventStoreDB/Simple/ECommerce.Api.Tests
8 files changed +52
-13
lines changed Original file line number Diff line number Diff line change @@ -7,20 +7,21 @@ public class EventsLog
7
7
public List < object > PublishedEvents { get ; } = new ( ) ;
8
8
}
9
9
10
- public class EventListener < TEvent > : IEventHandler < TEvent >
11
- where TEvent : notnull
10
+ public class EventListener : IEventBus
12
11
{
12
+ private readonly IEventBus eventBus ;
13
13
private readonly EventsLog eventsLog ;
14
14
15
- public EventListener ( EventsLog eventsLog )
15
+ public EventListener ( EventsLog eventsLog , IEventBus eventBus )
16
16
{
17
+ this . eventBus = eventBus ;
17
18
this . eventsLog = eventsLog ;
18
19
}
19
20
20
- public Task Handle ( TEvent @event , CancellationToken cancellationToken )
21
+ public async Task Publish ( IEventEnvelope eventEnvelope , CancellationToken ct )
21
22
{
22
- eventsLog . PublishedEvents . Add ( @event ) ;
23
-
24
- return Task . CompletedTask ;
23
+ eventsLog . PublishedEvents . Add ( eventEnvelope ) ;
24
+ await eventBus . Publish ( eventEnvelope , ct ) ;
25
25
}
26
26
}
27
+
Original file line number Diff line number Diff line change @@ -22,11 +22,13 @@ protected override IHost CreateHost(IHostBuilder builder)
22
22
builder . ConfigureServices ( services =>
23
23
{
24
24
services . AddSingleton ( eventsLog )
25
- . AddSingleton ( typeof ( IEventHandler < > ) , typeof ( EventListener < > ) )
26
25
. AddSingleton < IExternalEventProducer > ( externalEventProducer )
27
26
. AddSingleton < IEventBus > ( sp =>
28
- new EventBusDecoratorWithExternalProducer ( sp . GetRequiredService < EventBus > ( ) ,
29
- sp . GetRequiredService < IExternalEventProducer > ( ) ) )
27
+ new EventListener ( eventsLog ,
28
+ new EventBusDecoratorWithExternalProducer ( sp . GetRequiredService < EventBus > ( ) ,
29
+ sp . GetRequiredService < IExternalEventProducer > ( ) )
30
+ )
31
+ )
30
32
. AddSingleton < IExternalCommandBus > ( externalCommandBus )
31
33
. AddSingleton < IExternalEventConsumer , DummyExternalEventConsumer > ( ) ;
32
34
} ) ;
Original file line number Diff line number Diff line change 3
3
using ECommerce . ShoppingCarts . GettingCartById ;
4
4
using FluentAssertions ;
5
5
using Ogooreck . API ;
6
+ using Warehouse . Api . Tests ;
6
7
using static Ogooreck . API . ApiSpecification ;
7
8
using Xunit ;
8
9
9
10
namespace Carts . Api . Tests . ShoppingCarts . AddingProduct ;
10
11
11
12
public class AddProductFixture : ApiSpecification < Program > , IAsyncLifetime
12
13
{
14
+ public AddProductFixture ( ) : base ( new ShoppingCartsApplicationFactory ( ) ) { }
15
+
13
16
public Guid ShoppingCartId { get ; private set ; }
14
17
15
18
public readonly Guid ClientId = Guid . NewGuid ( ) ;
Original file line number Diff line number Diff line change 3
3
using ECommerce . ShoppingCarts . GettingCartById ;
4
4
using FluentAssertions ;
5
5
using Ogooreck . API ;
6
+ using Warehouse . Api . Tests ;
6
7
using Xunit ;
7
8
using static Ogooreck . API . ApiSpecification ;
8
9
9
10
namespace Carts . Api . Tests . ShoppingCarts . Canceling ;
10
11
11
12
public class CancelShoppingCartFixture : ApiSpecification < Program > , IAsyncLifetime
12
13
{
14
+ public CancelShoppingCartFixture ( ) : base ( new ShoppingCartsApplicationFactory ( ) ) { }
15
+
13
16
public Guid ShoppingCartId { get ; private set ; }
14
17
15
18
public readonly Guid ClientId = Guid . NewGuid ( ) ;
Original file line number Diff line number Diff line change 4
4
using FluentAssertions ;
5
5
using Xunit ;
6
6
using Ogooreck . API ;
7
+ using Warehouse . Api . Tests ;
7
8
using static Ogooreck . API . ApiSpecification ;
8
9
9
10
namespace Carts . Api . Tests . ShoppingCarts . Confirming ;
10
11
11
12
public class ConfirmShoppingCartFixture : ApiSpecification < Program > , IAsyncLifetime
12
13
{
14
+ public ConfirmShoppingCartFixture ( ) : base ( new ShoppingCartsApplicationFactory ( ) ) { }
15
+
13
16
public Guid ShoppingCartId { get ; private set ; }
14
17
15
18
public readonly Guid ClientId = Guid . NewGuid ( ) ;
Original file line number Diff line number Diff line change 5
5
using ECommerce . ShoppingCarts . ProductItems ;
6
6
using FluentAssertions ;
7
7
using Ogooreck . API ;
8
+ using Warehouse . Api . Tests ;
8
9
using Xunit ;
9
10
using static Ogooreck . API . ApiSpecification ;
10
11
11
12
namespace Carts . Api . Tests . ShoppingCarts . Opening ;
12
13
13
- public class OpenShoppingCartTests : IClassFixture < TestWebApplicationFactory < Program > >
14
+ public class OpenShoppingCartTests : IClassFixture < ShoppingCartsApplicationFactory >
14
15
{
15
16
private readonly ApiSpecification < Program > API ;
16
17
@@ -41,8 +42,8 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
41
42
} ) )
42
43
) ;
43
44
44
- public OpenShoppingCartTests ( TestWebApplicationFactory < Program > fixture ) =>
45
- API = ApiSpecification < Program > . Setup ( fixture ) ;
45
+ public OpenShoppingCartTests ( ShoppingCartsApplicationFactory applicationFactory ) =>
46
+ API = ApiSpecification < Program > . Setup ( applicationFactory ) ;
46
47
47
48
public readonly Guid ClientId = Guid . NewGuid ( ) ;
48
49
}
Original file line number Diff line number Diff line change 4
4
using FluentAssertions ;
5
5
using Xunit ;
6
6
using Ogooreck . API ;
7
+ using Warehouse . Api . Tests ;
7
8
using static Ogooreck . API . ApiSpecification ;
8
9
9
10
namespace Carts . Api . Tests . ShoppingCarts . RemovingProduct ;
10
11
11
12
public class RemoveProductFixture : ApiSpecification < Program > , IAsyncLifetime
12
13
{
14
+ public RemoveProductFixture ( ) : base ( new ShoppingCartsApplicationFactory ( ) ) { }
13
15
public Guid ShoppingCartId { get ; private set ; }
14
16
15
17
public readonly Guid ClientId = Guid . NewGuid ( ) ;
Original file line number Diff line number Diff line change
1
+ using Core . Testing ;
2
+ using ECommerce . Storage ;
3
+ using Microsoft . EntityFrameworkCore ;
4
+ using Microsoft . Extensions . DependencyInjection ;
5
+ using Microsoft . Extensions . Hosting ;
6
+
7
+ namespace Warehouse . Api . Tests ;
8
+
9
+ public class ShoppingCartsApplicationFactory : TestWebApplicationFactory < Program >
10
+ {
11
+ protected override IHost CreateHost ( IHostBuilder builder )
12
+ {
13
+ var host = base . CreateHost ( builder ) ;
14
+
15
+ using var scope = host . Services . CreateScope ( ) ;
16
+ using var context = scope . ServiceProvider . GetRequiredService < ECommerceDbContext > ( ) ;
17
+ var database = context . Database ;
18
+ database . ExecuteSqlRaw ( "TRUNCATE TABLE \" ShoppingCartDetailsProductItem\" " ) ;
19
+ database . ExecuteSqlRaw ( "TRUNCATE TABLE \" ShoppingCartShortInfo\" " ) ;
20
+ database . ExecuteSqlRaw ( "TRUNCATE TABLE \" ShoppingCartDetails\" CASCADE" ) ;
21
+
22
+ return host ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments