-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from soat-fiap/gherkin_bdd
test: add gherkin unit tests #173
- Loading branch information
Showing
14 changed files
with
103 additions
and
107 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
src/FIAP.TechChallenge.ByteMeBurger.Api/Auth/AccessTokenAuthEventsHandler.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/FIAP.TechChallenge.ByteMeBurger.Api/Auth/JwtExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/FIAP.TechChallenge.ByteMeBurger.Api/Auth/JwtOptions.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/CustomersController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/OrdersController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/ProductsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...P.TechChallenge.ByteMeBurger.Application.Test/UseCases/Orders/Gherkin/CreateOrder.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: Create new order | ||
|
||
Scenario: Create a new order successfully | ||
Given Selected product exists | ||
And Tracking code is created | ||
When UseCase is called | ||
Then it should create the order | ||
And it should publish integration event |
73 changes: 73 additions & 0 deletions
73
...P.TechChallenge.ByteMeBurger.Application.Test/UseCases/Orders/Gherkin/CreateOrderSteps.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Bmb.Domain.Core.Events; | ||
using Bmb.Domain.Core.Interfaces; | ||
using FIAP.TechChallenge.ByteMeBurger.Application.UseCases.Orders; | ||
using Xunit.Gherkin.Quick; | ||
using OrderCreated = Bmb.Domain.Core.Events.Integration.OrderCreated; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Application.Test.UseCases.Orders.Gherkin; | ||
|
||
[FeatureFile("./UseCases/Orders/Gherkin/CreateOrder.feature")] | ||
public class CreateOrderSteps : Feature | ||
{ | ||
// Given Selected product exists | ||
// And Tracking code is created | ||
// When UseCase is called | ||
// Then it should create the order | ||
private readonly CreateOrderUseCase _useCase; | ||
private readonly Mock<IProductRepository> _mockProductRepository; | ||
private readonly Mock<IOrderTrackingCodeService> _mockOrderTrackingCodeService; | ||
private readonly Mock<IDispatcher> _mockDispatcher; | ||
private Order _order; | ||
private Product _product; | ||
|
||
public CreateOrderSteps() | ||
{ | ||
_mockDispatcher = new Mock<IDispatcher>(); | ||
_mockProductRepository = new Mock<IProductRepository>(); | ||
_mockOrderTrackingCodeService = new Mock<IOrderTrackingCodeService>(); | ||
|
||
_useCase = new CreateOrderUseCase(_mockProductRepository.Object, _mockOrderTrackingCodeService.Object, | ||
_mockDispatcher.Object); | ||
} | ||
|
||
[Given("Selected product exists")] | ||
public void SetupExistingProduct() | ||
{ | ||
_product = new Product(Guid.NewGuid(), "product", "description", ProductCategory.Drink, 10, []); | ||
_mockProductRepository.Setup(p => p.FindByIdAsync(_product.Id)) | ||
.ReturnsAsync(_product) | ||
.Verifiable(); | ||
} | ||
|
||
[And("Tracking code is created")] | ||
public void SetupTrackingCode() | ||
{ | ||
_mockOrderTrackingCodeService.Setup(s => s.GetNextAsync()) | ||
.ReturnsAsync(new OrderTrackingCode("code")) | ||
.Verifiable(); | ||
} | ||
|
||
[When("UseCase is called")] | ||
public async Task WhenUseCaseIsCalled() | ||
{ | ||
_order = await _useCase.Execute(null, new List<SelectedProduct> | ||
{ | ||
new(_product.Id, 1) | ||
}); | ||
} | ||
|
||
[Then("it should create the order")] | ||
public void ThenItShouldCreateTheOrder() | ||
{ | ||
_order.Should().NotBeNull(); | ||
_order.TrackingCode.Should().Be(new OrderTrackingCode("code")); | ||
_order.OrderItems[0].ProductId.Should().Be(_product.Id); | ||
_mockProductRepository.VerifyAll(); | ||
} | ||
|
||
[And("it should publish integration event")] | ||
public void ThenItShouldPublishTheEvent() | ||
{ | ||
_mockDispatcher.Verify(d => d.PublishIntegrationAsync(It.IsAny<OrderCreated>(), default), Times.Once); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters