-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateOrderStatusSteps.cs
89 lines (79 loc) · 3.04 KB
/
UpdateOrderStatusSteps.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using AutoFixture;
using Bmb.Domain.Core.Events;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Production.Core.Contracts;
using Bmb.Production.Core.Model;
using Bmb.Production.Core.Model.Dto;
using Moq;
using Xunit.Gherkin.Quick;
using Feature = Xunit.Gherkin.Quick.Feature;
using OrderStatusChanged = Bmb.Domain.Core.Events.Notifications.OrderStatusChanged;
namespace Bmb.Production.Application.Test.Gherkin;
[FeatureFile("./Gherkin/UpdateOrderStatus.feature")]
public class UpdateOrderStatusSteps : Feature
{
private readonly UpdateOrderStatusUseCase _useCase;
private readonly Mock<IKitchenOrderRepository> _mockKitchenOrderRepository;
private readonly Mock<IDispatcher> _mockDispatcher;
private Guid _orderId;
public UpdateOrderStatusSteps()
{
_mockKitchenOrderRepository = new Mock<IKitchenOrderRepository>();
_mockDispatcher = new Mock<IDispatcher>();
_useCase = new UpdateOrderStatusUseCase(_mockKitchenOrderRepository.Object, _mockDispatcher.Object);
}
[Given("an OrderId is received")]
public void GivenAnOrderIdIsReceived()
{
_orderId = Guid.NewGuid();
}
[And("the OrderId exists on the database")]
public void WhenTheOrderIdExistsOnTheDatabase()
{
var order = new Fixture().Build<KitchenOrderDto>()
.With(o => o.OrderId, _orderId)
.Create();
_mockKitchenOrderRepository.Setup(r => r.GetAsync(_orderId, default))
.ReturnsAsync(order)
.Verifiable();
}
[And("the order status can be updated")]
public void GivenOrderStatusCanBeUpdated()
{
_mockKitchenOrderRepository.Setup(r => r.UpdateStatusAsync(_orderId, KitchenOrderStatus.Preparing, default))
.Returns(Task.CompletedTask)
.Verifiable();
}
[When("the UseCase is executed")]
public Task Execute_UseCase()
{
return _useCase.ExecuteAsync(_orderId, KitchenOrderStatus.Preparing, default);
}
[Then("it should update the order status")]
public void Update_OrderStatus()
{
_mockKitchenOrderRepository.Setup(r => r.UpdateStatusAsync(_orderId, KitchenOrderStatus.Preparing, default))
.Returns(Task.CompletedTask)
.Verifiable();
}
[And("the event dispatcher is available")]
public void GivenEventDispatcherIsAvailable()
{
_mockDispatcher.Setup(d => d.PublishAsync(It.IsAny<OrderStatusChanged>(), default))
.Returns(Task.CompletedTask)
.Verifiable();
}
[And("it should publishes a OrderStatusUpdated event")]
public void Publishes_OrderStatusUpdated_Event()
{
_mockDispatcher.Setup(d => d.PublishAsync(new OrderStatusChanged(_orderId, OrderStatus.InPreparation), default))
.Returns(Task.CompletedTask)
.Verifiable();
_mockDispatcher.Verify(d => d.PublishAsync(
It.Is<OrderStatusChanged>(e =>
e.OrderId == _orderId &&
e.Status == OrderStatus.InPreparation),
default),
Times.Once);
}
}