Skip to content

Commit 1c227f3

Browse files
author
Anthony Sneed
committed
Add SpecFlow tests.
1 parent 80c4735 commit 1c227f3

33 files changed

+789
-176
lines changed

EventDriven.ReferenceArchitecture.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "reference-architecture", "r
1515
reference-architecture\tye.yaml = reference-architecture\tye.yaml
1616
EndProjectSection
1717
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventDriven.CQRS.Tests", "test\EventDriven.CQRS.Tests\EventDriven.CQRS.Tests.csproj", "{9809006C-2F6B-44A1-8AE2-BC449368D209}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventDriven.ReferenceArchitecture.Tests", "test\EventDriven.ReferenceArchitecture.Tests\EventDriven.ReferenceArchitecture.Tests.csproj", "{9809006C-2F6B-44A1-8AE2-BC449368D209}"
1919
EndProject
2020
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomerService", "reference-architecture\CustomerService\CustomerService.csproj", "{48983715-E6DF-462F-AF3C-769C1122794F}"
2121
EndProject
@@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "standby", "standby", "{A045
4343
reference-architecture\dapr\standby\pubsub-snssqs.yaml = reference-architecture\dapr\standby\pubsub-snssqs.yaml
4444
EndProjectSection
4545
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventDriven.ReferenceArchitecture.Specs", "test\EventDriven.ReferenceArchitecture.Specs\EventDriven.ReferenceArchitecture.Specs.csproj", "{68B613B3-EB4A-41DB-A61E-1E031C5BFA85}"
47+
EndProject
4648
Global
4749
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4850
Debug|Any CPU = Debug|Any CPU
@@ -65,6 +67,10 @@ Global
6567
{FC04D111-903D-49FF-84A6-8806C71E2168}.Debug|Any CPU.Build.0 = Debug|Any CPU
6668
{FC04D111-903D-49FF-84A6-8806C71E2168}.Release|Any CPU.ActiveCfg = Release|Any CPU
6769
{FC04D111-903D-49FF-84A6-8806C71E2168}.Release|Any CPU.Build.0 = Release|Any CPU
70+
{68B613B3-EB4A-41DB-A61E-1E031C5BFA85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71+
{68B613B3-EB4A-41DB-A61E-1E031C5BFA85}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{68B613B3-EB4A-41DB-A61E-1E031C5BFA85}.Release|Any CPU.ActiveCfg = Release|Any CPU
73+
{68B613B3-EB4A-41DB-A61E-1E031C5BFA85}.Release|Any CPU.Build.0 = Release|Any CPU
6874
EndGlobalSection
6975
GlobalSection(SolutionProperties) = preSolution
7076
HideSolutionNode = FALSE
@@ -78,6 +84,7 @@ Global
7884
{00BA9501-787E-465C-97D0-F51295D97802} = {F0E48E00-7D72-4614-9C13-90A7B015B06F}
7985
{F0E48E00-7D72-4614-9C13-90A7B015B06F} = {C4FD0AF1-927A-4860-A634-7CE342807692}
8086
{A045033E-5283-4A6F-87D3-B02194595788} = {F0E48E00-7D72-4614-9C13-90A7B015B06F}
87+
{68B613B3-EB4A-41DB-A61E-1E031C5BFA85} = {269CD137-4093-4100-B33E-808586D335F6}
8188
EndGlobalSection
8289
GlobalSection(ExtensibilityGlobals) = postSolution
8390
SolutionGuid = {427A0D03-63CA-48AE-AA95-D21800101398}

ReadMe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Reference architecture for using **EventDriven** abstractions and libraries for
1313
- [Install Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
1414
- [Initialize Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/)
1515
- [Microsoft Tye](https://github.com/dotnet/tye/blob/main/docs/getting_started.md) (recommended)
16+
- [Specflow](https://specflow.org/) IDE Plugin (recommended)
17+
- [Visual Studio](https://docs.specflow.org/projects/getting-started/en/latest/GettingStarted/Step1.html)
18+
- [JetBrains Rider](https://docs.specflow.org/projects/specflow/en/latest/Rider/rider-installation.html)
1619

1720
## Introduction
1821

@@ -67,6 +70,11 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
6770
- Note the address is also updated for the customer's orders.
6871
- Observe log messages in terminal when integration events are published and handled.
6972
73+
### Tests
74+
- **Unit Tests**: EventDriven.ReferenceArchitecture.Tests
75+
- **User Acceptance Tests**: EventDriven.ReferenceArchitecture.Specs
76+
- ReadMe: [Reference Architecture: User Acceptance Tests](test/EventDriven.ReferenceArchitecture.Specs/ReadMe.md)
77+
7078
### Development Guide
7179
7280
> This section describes how to build the Customer and Order services from scratch using the **EventDriven.DDD.Abstractions** package. For your own project substitute `Customer` and `Order` for your own aggregate entites and related classes.

reference-architecture/Common/Common.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
57
</PropertyGroup>
68

79
<ItemGroup>

reference-architecture/Common/Integration/Events/CustomerAddressUpdated.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Common.Integration.Models;
32
using EventDriven.EventBus.Abstractions;
43

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,53 @@
1-
namespace OrderService
1+
using EventDriven.DependencyInjection.URF.Mongo;
2+
using OrderService.Configuration;
3+
using OrderService.Domain.OrderAggregate;
4+
using OrderService.Domain.OrderAggregate.CommandHandlers;
5+
using OrderService.Integration.EventHandlers;
6+
using OrderService.Repositories;
7+
8+
var builder = WebApplication.CreateBuilder(args);
9+
10+
// Add services to the container.
11+
builder.Services.AddControllers();
12+
builder.Services.AddEndpointsApiExplorer();
13+
builder.Services.AddSwaggerGen();
14+
15+
// Add automapper
16+
builder.Services.AddAutoMapper(typeof(Program));
17+
18+
// Add database settings
19+
builder.Services.AddSingleton<OrderCommandHandler>();
20+
builder.Services.AddSingleton<IOrderRepository, OrderRepository>();
21+
builder.Services.AddMongoDbSettings<OrderDatabaseSettings, Order>(builder.Configuration);
22+
builder.Services.AddSingleton<CustomerAddressUpdatedEventHandler>();
23+
24+
// Add Dapr event bus
25+
builder.Services.AddDaprEventBus(builder.Configuration, true);
26+
builder.Services.AddDaprMongoEventCache(builder.Configuration);
27+
28+
var app = builder.Build();
29+
30+
// Configure the HTTP request pipeline.
31+
if (app.Environment.IsDevelopment())
232
{
3-
public class Program
4-
{
5-
public static void Main(string[] args)
6-
{
7-
CreateHostBuilder(args).Build().Run();
8-
}
9-
10-
public static IHostBuilder CreateHostBuilder(string[] args) =>
11-
Host.CreateDefaultBuilder(args)
12-
.ConfigureWebHostDefaults(webBuilder =>
13-
{
14-
webBuilder.UseStartup<Startup>();
15-
});
16-
}
33+
app.UseSwagger();
34+
app.UseSwaggerUI();
1735
}
36+
37+
app.UseRouting();
38+
app.UseAuthorization();
39+
40+
// Map Dapr Event Bus subscribers
41+
app.UseCloudEvents();
42+
app.UseEndpoints(endpoints =>
43+
{
44+
endpoints.MapControllers();
45+
endpoints.MapSubscribeHandler();
46+
endpoints.MapDaprEventBus(eventBus =>
47+
{
48+
var customerAddressUpdatedEventHandler = app.Services.GetRequiredService<CustomerAddressUpdatedEventHandler>();
49+
eventBus.Subscribe(customerAddressUpdatedEventHandler, null, "v1");
50+
});
51+
});
52+
53+
app.Run();

reference-architecture/OrderService/Startup.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

reference-architecture/json/orders.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
{
88
"productId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
99
"productName": "Espresso",
10-
"productPrice": "2.50"
10+
"productPrice": 2.50
1111
},
1212
{
1313
"productId": "5a8c5f7f-0781-4d5e-9d9b-41ef2da5f3c3",
1414
"productName": "Cappuccino",
15-
"productPrice": "3.50"
15+
"productPrice": 3.50
1616
}
1717
],
1818
"shippingAddress": {
@@ -33,7 +33,7 @@
3333
{
3434
"productId": "42b27777-6eff-4193-828d-5fe554a705d1",
3535
"productName": "Chai",
36-
"productPrice": "1.50"
36+
"productPrice": 1.50
3737
}
3838
],
3939
"shippingAddress": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace EventDriven.ReferenceArchitecture.Specs.Configuration;
2+
3+
public class ReferenceArchitectureSpecsSettings
4+
{
5+
public Guid CustomerId { get; set; }
6+
public Guid Order1Id { get; set; }
7+
public Guid Order2Id { get; set; }
8+
public string? CustomerBaseAddress { get; set; }
9+
public bool StartTyeProcess { get; set; }
10+
public TimeSpan TyeProcessTimeout { get; set; }
11+
public TimeSpan AddressUpdateTimeout { get; set; }
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Using Include="TechTalk.SpecFlow" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="EventDriven.DependencyInjection" Version="1.0.0" />
15+
<PackageReference Include="EventDriven.DependencyInjection.URF.Mongo" Version="1.1.0" />
16+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
18+
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
19+
<PackageReference Include="SpecFlow.xUnit" Version="3.9.52" />
20+
<PackageReference Include="xunit" Version="2.4.1" />
21+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageReference>
25+
<PackageReference Include="FluentAssertions" Version="6.5.1" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<Folder Include="Steps" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<None Update="appsettings.json">
34+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
35+
</None>
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\..\reference-architecture\CustomerService\CustomerService.csproj" />
40+
<ProjectReference Include="..\..\reference-architecture\OrderService\OrderService.csproj" />
41+
</ItemGroup>
42+
43+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Update Customer Address
2+
Event driven architecture for propagating data from one service to another.
3+
4+
@eda
5+
Scenario: Update a customer address
6+
Given a customer has been created with 'customer.json'
7+
And orders have been created with 'orders.json'
8+
When I make a PUT request with 'updated-customer.json' to 'api/customer'
9+
Then the response status code should be '200'
10+
And the address for orders should equal 'updated-address.json'

0 commit comments

Comments
 (0)