-
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 #30 from soat-fiap/3-add-new-endpoint-to-register-…
…new-products feat: add endpoint integration to create products
- Loading branch information
Showing
6 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
src/FIAP.TechChallenge.ByteMeBurger.Infrastructure/Repository/ProductRepositoryDapper.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,59 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Data; | ||
using Dapper; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Ports.Outgoing; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.ValueObjects; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Infrastructure.Repository; | ||
|
||
public class ProductRepositoryDapper : IProductRepository | ||
{ | ||
private readonly IDbConnection _dbConnection; | ||
|
||
public ProductRepositoryDapper(IDbConnection dbConnection) | ||
{ | ||
_dbConnection = dbConnection; | ||
} | ||
|
||
public Task<Product?> FindByIdAsync(Guid id) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public async Task<Product> CreateAsync(Product product) | ||
{ | ||
var affectedRows = await _dbConnection.ExecuteAsync( | ||
"insert into Products (Id, Name, Description, Category, Price, Images) values (@Id, @Name, @Description, @Category, @Price, @Images);", | ||
new | ||
{ | ||
product.Id, | ||
product.Name, | ||
product.Description, | ||
product.Category, | ||
product.Price, | ||
Images = string.Join("|", product.Images) | ||
}); | ||
return product; | ||
} | ||
|
||
public Task<bool> DeleteAsync(Guid productId) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<ReadOnlyCollection<Product>> GetAll() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<ReadOnlyCollection<Product>> FindByCategory(ProductCategory category) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<bool> UpdateAsync(Product product) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
....TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/ProductRepositoryDapperTest.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,45 @@ | ||
using System.Data; | ||
using Dapper; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.Entities; | ||
using FIAP.TechChallenge.ByteMeBurger.Domain.ValueObjects; | ||
using FIAP.TechChallenge.ByteMeBurger.Infrastructure.Repository; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using JetBrains.Annotations; | ||
using Moq; | ||
using Moq.Dapper; | ||
|
||
namespace FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test.Repository; | ||
|
||
[TestSubject(typeof(ProductRepositoryDapper))] | ||
public class ProductRepositoryDapperTest | ||
{ | ||
private readonly Mock<IDbConnection> _mockConnection; | ||
private readonly ProductRepositoryDapper _target; | ||
|
||
public ProductRepositoryDapperTest() | ||
{ | ||
_mockConnection = new Mock<IDbConnection>(); | ||
_target = new ProductRepositoryDapper(_mockConnection.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_Success() | ||
{ | ||
// Arrange | ||
var product = new Product("product", "description", ProductCategory.Beverage, 10, ["image1"]); | ||
|
||
_mockConnection.SetupDapperAsync(c => c.ExecuteAsync("", null, null, null, null)) | ||
.ReturnsAsync(1); | ||
|
||
// Act | ||
var result = await _target.CreateAsync(product); | ||
|
||
// Assert | ||
using (new AssertionScope()) | ||
{ | ||
result.Should().NotBeNull(); | ||
result.Should().Be(product); | ||
} | ||
} | ||
} |