Shady nagy/net6 (#614)
* udated to .net6 * used the .net6 version RC2 * added editconfig. * App core new Scoped Namespaces style. * BlazorAdmin new Scoped Namespaces style. * Blazor Shared new Scoped Namespaces style. * Infra new Scoped Namespaces style. * public api new Scoped Namespaces style. * web new Scoped Namespaces style. * FunctionalTests new Scoped Namespaces style. * Integrational tests new Scoped Namespaces style. * unit tests new Scoped Namespaces style. * update github action. * update github action. * change the global.
This commit is contained in:
@@ -1,41 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Services;
|
||||
using Microsoft.eShopWeb.Infrastructure.Data;
|
||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.BasketRepositoryTests
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.BasketRepositoryTests;
|
||||
|
||||
public class SetQuantities
|
||||
{
|
||||
public class SetQuantities
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Basket> _basketRepository;
|
||||
private readonly BasketBuilder BasketBuilder = new BasketBuilder();
|
||||
|
||||
public SetQuantities()
|
||||
{
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Basket> _basketRepository;
|
||||
private readonly BasketBuilder BasketBuilder = new BasketBuilder();
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_basketRepository = new EfRepository<Basket>(_catalogContext);
|
||||
}
|
||||
|
||||
public SetQuantities()
|
||||
{
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_basketRepository = new EfRepository<Basket>(_catalogContext);
|
||||
}
|
||||
[Fact]
|
||||
public async Task RemoveEmptyQuantities()
|
||||
{
|
||||
var basket = BasketBuilder.WithOneBasketItem();
|
||||
var basketService = new BasketService(_basketRepository, null);
|
||||
await _basketRepository.AddAsync(basket);
|
||||
_catalogContext.SaveChanges();
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveEmptyQuantities()
|
||||
{
|
||||
var basket = BasketBuilder.WithOneBasketItem();
|
||||
var basketService = new BasketService(_basketRepository, null);
|
||||
await _basketRepository.AddAsync(basket);
|
||||
_catalogContext.SaveChanges();
|
||||
await basketService.SetQuantities(BasketBuilder.BasketId, new Dictionary<string, int>() { { BasketBuilder.BasketId.ToString(), 0 } });
|
||||
|
||||
await basketService.SetQuantities(BasketBuilder.BasketId, new Dictionary<string, int>() { { BasketBuilder.BasketId.ToString(), 0 } });
|
||||
|
||||
Assert.Equal(0, basket.Items.Count);
|
||||
}
|
||||
Assert.Equal(0, basket.Items.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.Infrastructure.Data;
|
||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.OrderRepositoryTests
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.OrderRepositoryTests;
|
||||
|
||||
public class GetById
|
||||
{
|
||||
public class GetById
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Order> _orderRepository;
|
||||
private OrderBuilder OrderBuilder { get; } = new OrderBuilder();
|
||||
private readonly ITestOutputHelper _output;
|
||||
public GetById(ITestOutputHelper output)
|
||||
{
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Order> _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 EfRepository<Order>(_catalogContext);
|
||||
}
|
||||
_output = output;
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_orderRepository = new EfRepository<Order>(_catalogContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetsExistingOrder()
|
||||
{
|
||||
var existingOrder = OrderBuilder.WithDefaultValues();
|
||||
_catalogContext.Orders.Add(existingOrder);
|
||||
_catalogContext.SaveChanges();
|
||||
int orderId = existingOrder.Id;
|
||||
_output.WriteLine($"OrderId: {orderId}");
|
||||
[Fact]
|
||||
public async Task GetsExistingOrder()
|
||||
{
|
||||
var existingOrder = OrderBuilder.WithDefaultValues();
|
||||
_catalogContext.Orders.Add(existingOrder);
|
||||
_catalogContext.SaveChanges();
|
||||
int orderId = existingOrder.Id;
|
||||
_output.WriteLine($"OrderId: {orderId}");
|
||||
|
||||
var orderFromRepo = await _orderRepository.GetByIdAsync(orderId);
|
||||
Assert.Equal(OrderBuilder.TestBuyerId, orderFromRepo.BuyerId);
|
||||
var orderFromRepo = await _orderRepository.GetByIdAsync(orderId);
|
||||
Assert.Equal(OrderBuilder.TestBuyerId, orderFromRepo.BuyerId);
|
||||
|
||||
// Note: Using InMemoryDatabase OrderItems is available. Will be null if using SQL DB.
|
||||
// Use the OrderWithItemsByIdSpec instead of just GetById to get the full aggregate
|
||||
var firstItem = orderFromRepo.OrderItems.FirstOrDefault();
|
||||
Assert.Equal(OrderBuilder.TestUnits, firstItem.Units);
|
||||
}
|
||||
// Note: Using InMemoryDatabase OrderItems is available. Will be null if using SQL DB.
|
||||
// Use the OrderWithItemsByIdSpec instead of just GetById to get the full aggregate
|
||||
var firstItem = orderFromRepo.OrderItems.FirstOrDefault();
|
||||
Assert.Equal(OrderBuilder.TestUnits, firstItem.Units);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,62 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||
using Microsoft.eShopWeb.Infrastructure.Data;
|
||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.OrderRepositoryTests
|
||||
namespace Microsoft.eShopWeb.IntegrationTests.Repositories.OrderRepositoryTests;
|
||||
|
||||
public class GetByIdWithItemsAsync
|
||||
{
|
||||
public class GetByIdWithItemsAsync
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Order> _orderRepository;
|
||||
private OrderBuilder OrderBuilder { get; } = new OrderBuilder();
|
||||
|
||||
public GetByIdWithItemsAsync()
|
||||
{
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly EfRepository<Order> _orderRepository;
|
||||
private OrderBuilder OrderBuilder { get; } = new OrderBuilder();
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_orderRepository = new EfRepository<Order>(_catalogContext);
|
||||
}
|
||||
|
||||
public GetByIdWithItemsAsync()
|
||||
{
|
||||
var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TestCatalog")
|
||||
.Options;
|
||||
_catalogContext = new CatalogContext(dbOptions);
|
||||
_orderRepository = new EfRepository<Order>(_catalogContext);
|
||||
}
|
||||
[Fact]
|
||||
public async Task GetOrderAndItemsByOrderIdWhenMultipleOrdersPresent()
|
||||
{
|
||||
//Arrange
|
||||
var itemOneUnitPrice = 5.50m;
|
||||
var itemOneUnits = 2;
|
||||
var itemTwoUnitPrice = 7.50m;
|
||||
var itemTwoUnits = 5;
|
||||
|
||||
[Fact]
|
||||
public async Task GetOrderAndItemsByOrderIdWhenMultipleOrdersPresent()
|
||||
{
|
||||
//Arrange
|
||||
var itemOneUnitPrice = 5.50m;
|
||||
var itemOneUnits = 2;
|
||||
var itemTwoUnitPrice = 7.50m;
|
||||
var itemTwoUnits = 5;
|
||||
var firstOrder = OrderBuilder.WithDefaultValues();
|
||||
_catalogContext.Orders.Add(firstOrder);
|
||||
int firstOrderId = firstOrder.Id;
|
||||
|
||||
var firstOrder = OrderBuilder.WithDefaultValues();
|
||||
_catalogContext.Orders.Add(firstOrder);
|
||||
int firstOrderId = firstOrder.Id;
|
||||
var secondOrderItems = new List<OrderItem>();
|
||||
secondOrderItems.Add(new OrderItem(OrderBuilder.TestCatalogItemOrdered, itemOneUnitPrice, itemOneUnits));
|
||||
secondOrderItems.Add(new OrderItem(OrderBuilder.TestCatalogItemOrdered, itemTwoUnitPrice, itemTwoUnits));
|
||||
var secondOrder = OrderBuilder.WithItems(secondOrderItems);
|
||||
_catalogContext.Orders.Add(secondOrder);
|
||||
int secondOrderId = secondOrder.Id;
|
||||
|
||||
var secondOrderItems = new List<OrderItem>();
|
||||
secondOrderItems.Add(new OrderItem(OrderBuilder.TestCatalogItemOrdered, itemOneUnitPrice, itemOneUnits));
|
||||
secondOrderItems.Add(new OrderItem(OrderBuilder.TestCatalogItemOrdered, itemTwoUnitPrice, itemTwoUnits));
|
||||
var secondOrder = OrderBuilder.WithItems(secondOrderItems);
|
||||
_catalogContext.Orders.Add(secondOrder);
|
||||
int secondOrderId = secondOrder.Id;
|
||||
_catalogContext.SaveChanges();
|
||||
|
||||
_catalogContext.SaveChanges();
|
||||
//Act
|
||||
var spec = new OrderWithItemsByIdSpec(secondOrderId);
|
||||
var orderFromRepo = await _orderRepository.GetBySpecAsync(spec);
|
||||
|
||||
//Act
|
||||
var spec = new OrderWithItemsByIdSpec(secondOrderId);
|
||||
var orderFromRepo = await _orderRepository.GetBySpecAsync(spec);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(secondOrderId, orderFromRepo.Id);
|
||||
Assert.Equal(secondOrder.OrderItems.Count, orderFromRepo.OrderItems.Count);
|
||||
Assert.Equal(1, orderFromRepo.OrderItems.Count(x => x.UnitPrice == itemOneUnitPrice));
|
||||
Assert.Equal(1, orderFromRepo.OrderItems.Count(x => x.UnitPrice == itemTwoUnitPrice));
|
||||
Assert.Equal(itemOneUnits, orderFromRepo.OrderItems.SingleOrDefault(x => x.UnitPrice == itemOneUnitPrice).Units);
|
||||
Assert.Equal(itemTwoUnits, orderFromRepo.OrderItems.SingleOrDefault(x => x.UnitPrice == itemTwoUnitPrice).Units);
|
||||
}
|
||||
//Assert
|
||||
Assert.Equal(secondOrderId, orderFromRepo.Id);
|
||||
Assert.Equal(secondOrder.OrderItems.Count, orderFromRepo.OrderItems.Count);
|
||||
Assert.Equal(1, orderFromRepo.OrderItems.Count(x => x.UnitPrice == itemOneUnitPrice));
|
||||
Assert.Equal(1, orderFromRepo.OrderItems.Count(x => x.UnitPrice == itemTwoUnitPrice));
|
||||
Assert.Equal(itemOneUnits, orderFromRepo.OrderItems.SingleOrDefault(x => x.UnitPrice == itemOneUnitPrice).Units);
|
||||
Assert.Equal(itemTwoUnits, orderFromRepo.OrderItems.SingleOrDefault(x => x.UnitPrice == itemTwoUnitPrice).Units);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user