Refactoring and Adding Tests (#58)
* Moving Identity seeding to its own class and method. * Adding tests for AddItem * Added catalog api controller and functional tests Added and cleaned up some comments * Adding integration tests for OrderRepository * Getting integration test for order working with inmemory db
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using ApplicationCore.Entities.OrderAggregate;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnitTests.Builders;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace IntegrationTests.Repositories.OrderRepositoryTests
|
||||
{
|
||||
public class GetById
|
||||
{
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly OrderRepository _orderRepository;
|
||||
private OrderBuilder OrderBuilder { get; } = new OrderBuilder();
|
||||
private readonly ITestOutputHelper _output;
|
||||
public GetById(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_orderRepository = new OrderRepository(_catalogContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsExistingOrder()
|
||||
{
|
||||
var existingOrder = OrderBuilder.WithDefaultValues();
|
||||
_catalogContext.Orders.Add(existingOrder);
|
||||
_catalogContext.SaveChanges();
|
||||
int orderId = existingOrder.Id;
|
||||
_output.WriteLine($"OrderId: {orderId}");
|
||||
|
||||
var orderFromRepo = _orderRepository.GetById(orderId);
|
||||
Assert.Equal(OrderBuilder.TestBuyerId, orderFromRepo.BuyerId);
|
||||
|
||||
// Note: Using InMemoryDatabase OrderItems is available. Will be null if using SQL DB.
|
||||
var firstItem = orderFromRepo.OrderItems.FirstOrDefault();
|
||||
Assert.Equal(OrderBuilder.TestUnits, firstItem.Units);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user