Make testing name scheme consistent (#395)
* Updating CahceHelperTests names * Updating OrdersTests names * Removing tests for "Include" functionality as it lives in a NuGet Package now * Updating Integration Test anems
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public DateTime PublishingDate { get; set; }
|
||||
public Person Author { get; set; }
|
||||
|
||||
public int GetNumberOfSales()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using Ardalis.Specification.QueryExtensions.Include;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query.IncludeAggregatorTests
|
||||
{
|
||||
public class Include
|
||||
{
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeSimpleType()
|
||||
{
|
||||
var includeAggregator = new IncludeAggregator<Person>();
|
||||
|
||||
// There may be ORM libraries where including a simple type makes sense.
|
||||
var includeQuery = includeAggregator.Include(p => p.Age);
|
||||
|
||||
Assert.Contains(includeQuery.Paths, path => path == nameof(Person.Age));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeFunction()
|
||||
{
|
||||
var includeAggregator = new IncludeAggregator<Person>();
|
||||
|
||||
// This include does not make much sense, but it should at least do not modify the paths.
|
||||
var includeQuery = includeAggregator.Include(p => p.FavouriteBook.GetNumberOfSales());
|
||||
|
||||
Assert.Contains(includeQuery.Paths, path => path == nameof(Person.FavouriteBook));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeObject()
|
||||
{
|
||||
var includeAggregator = new IncludeAggregator<Person>();
|
||||
var includeQuery = includeAggregator.Include(p => p.FavouriteBook.Author);
|
||||
|
||||
Assert.Contains(includeQuery.Paths, path => path == $"{nameof(Person.FavouriteBook)}.{nameof(Book.Author)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeCollection()
|
||||
{
|
||||
var includeAggregator = new IncludeAggregator<Book>();
|
||||
var includeQuery = includeAggregator.Include(o => o.Author.Friends);
|
||||
|
||||
Assert.Contains(includeQuery.Paths, path => path == $"{nameof(Book.Author)}.{nameof(Person.Friends)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using Ardalis.Specification.QueryExtensions.Include;
|
||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query.IncludeQueryTests
|
||||
{
|
||||
public class Include
|
||||
{
|
||||
private IncludeQueryBuilder _includeQueryBuilder = new IncludeQueryBuilder();
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeSimpleType()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
|
||||
// There may be ORM libraries where including a simple type makes sense.
|
||||
var newIncludeQuery = includeQuery.Include(b => b.Title);
|
||||
|
||||
Assert.Contains(newIncludeQuery.Paths, path => path == nameof(Book.Title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeFunction()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
|
||||
// This include does not make much sense, but it should at least do not modify paths.
|
||||
var newIncludeQuery = includeQuery.Include(b => b.GetNumberOfSales());
|
||||
|
||||
// The resulting paths should not include number of sales.
|
||||
Assert.DoesNotContain(newIncludeQuery.Paths, path => path == nameof(Book.GetNumberOfSales));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeObject()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var newIncludeQuery = includeQuery.Include(b => b.Author);
|
||||
|
||||
Assert.Contains(newIncludeQuery.Paths, path => path == nameof(Book.Author));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeCollection()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
|
||||
var newIncludeQuery = includeQuery.Include(b => b.Author.Friends);
|
||||
var expectedPath = $"{nameof(Book.Author)}.{nameof(Person.Friends)}";
|
||||
|
||||
Assert.Contains(newIncludeQuery.Paths, path => path == expectedPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_IncreaseNumberOfPathsByOne()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var numberOfPathsBeforeInclude = includeQuery.Paths.Count;
|
||||
|
||||
var newIncludeQuery = includeQuery.Include(b => b.Author.Friends);
|
||||
var numberOfPathsAferInclude = newIncludeQuery.Paths.Count;
|
||||
|
||||
var expectedNumerOfPaths = numberOfPathsBeforeInclude + 1;
|
||||
|
||||
Assert.Equal(expectedNumerOfPaths, numberOfPathsAferInclude);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_NotModifyAnotherPath()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var pathsBeforeInclude = includeQuery.Paths;
|
||||
|
||||
var newIncludeQuery = includeQuery.Include(b => b.Author.Friends);
|
||||
var pathsAfterInclude = newIncludeQuery.Paths;
|
||||
|
||||
Assert.Subset(pathsAfterInclude, pathsBeforeInclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using Ardalis.Specification.QueryExtensions.Include;
|
||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query.IncludeQueryTests
|
||||
{
|
||||
public class ThenInclude
|
||||
{
|
||||
private IncludeQueryBuilder _includeQueryBuilder = new IncludeQueryBuilder();
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeSimpleType()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var pathBeforeInclude = includeQuery.Paths.First();
|
||||
|
||||
// There may be ORM libraries where including a simple type makes sense.
|
||||
var newIncludeQuery = includeQuery.ThenInclude(p => p.Age);
|
||||
var pathAfterInclude = newIncludeQuery.Paths.First();
|
||||
var expectedPath = $"{pathBeforeInclude}.{nameof(Person.Age)}";
|
||||
|
||||
Assert.Equal(expectedPath, pathAfterInclude);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeFunction()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var pathBeforeInclude = includeQuery.Paths.First();
|
||||
|
||||
// This include does not make much sense, but it should at least not modify the paths.
|
||||
var newIncludeQuery = includeQuery.ThenInclude(p => p.GetQuote());
|
||||
var pathAfterInclude = newIncludeQuery.Paths.First();
|
||||
|
||||
Assert.Equal(pathBeforeInclude, pathAfterInclude);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeObject()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var pathBeforeInclude = includeQuery.Paths.First();
|
||||
|
||||
var newIncludeQuery = includeQuery.ThenInclude(p => p.FavouriteBook);
|
||||
var pathAfterInclude = newIncludeQuery.Paths.First();
|
||||
var expectedPath = $"{pathBeforeInclude}.{nameof(Person.FavouriteBook)}";
|
||||
|
||||
Assert.Equal(expectedPath, pathAfterInclude);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludeCollection()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithObjectAsPreviousProperty();
|
||||
var pathBeforeInclude = includeQuery.Paths.First();
|
||||
|
||||
var newIncludeQuery = includeQuery.ThenInclude(p => p.Friends);
|
||||
var pathAfterInclude = newIncludeQuery.Paths.First();
|
||||
var expectedPath = $"{pathBeforeInclude}.{nameof(Person.Friends)}";
|
||||
|
||||
Assert.Equal(expectedPath, pathAfterInclude);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnIncludeQueryWithCorrectPath_IfIncludePropertyOverCollection()
|
||||
{
|
||||
var includeQuery = _includeQueryBuilder.WithCollectionAsPreviousProperty();
|
||||
var pathBeforeInclude = includeQuery.Paths.First();
|
||||
|
||||
var newIncludeQuery = includeQuery.ThenInclude(p => p.FavouriteBook);
|
||||
var pathAfterInclude = newIncludeQuery.Paths.First();
|
||||
var expectedPath = $"{pathBeforeInclude}.{nameof(Person.FavouriteBook)}";
|
||||
|
||||
Assert.Equal(expectedPath, pathAfterInclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Ardalis.Specification.QueryExtensions.Include;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query.IncludeVisitorTests
|
||||
{
|
||||
public class Visit
|
||||
{
|
||||
[Fact]
|
||||
public void Should_SetPath_IfPassedExpressionWithSimpleType()
|
||||
{
|
||||
var visitor = new IncludeVisitor();
|
||||
Expression<Func<Book, string>> expression = (book) => book.Author.FirstName;
|
||||
visitor.Visit(expression);
|
||||
|
||||
var expectedPath = $"{nameof(Book.Author)}.{nameof(Person.FirstName)}";
|
||||
Assert.Equal(expectedPath, visitor.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_SetPath_IfPassedExpressionWithObject()
|
||||
{
|
||||
var visitor = new IncludeVisitor();
|
||||
Expression<Func<Book, Book>> expression = (book) => book.Author.FavouriteBook;
|
||||
visitor.Visit(expression);
|
||||
|
||||
var expectedPath = $"{nameof(Book.Author)}.{nameof(Person.FavouriteBook)}";
|
||||
Assert.Equal(expectedPath, visitor.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_SetPath_IfPassedExpressionWithCollection()
|
||||
{
|
||||
var visitor = new IncludeVisitor();
|
||||
Expression<Func<Book, List<Person>>> expression = (book) => book.Author.Friends;
|
||||
visitor.Visit(expression);
|
||||
|
||||
var expectedPath = $"{nameof(Book.Author)}.{nameof(Person.Friends)}";
|
||||
Assert.Equal(expectedPath, visitor.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_SetPath_IfPassedExpressionWithFunction()
|
||||
{
|
||||
var visitor = new IncludeVisitor();
|
||||
Expression<Func<Book, string>> expression = (book) => book.Author.GetQuote();
|
||||
visitor.Visit(expression);
|
||||
|
||||
var expectedPath = nameof(Book.Author);
|
||||
Assert.Equal(expectedPath, visitor.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query
|
||||
{
|
||||
public class Person
|
||||
{
|
||||
public int Age { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
|
||||
public Book FavouriteBook { get; set; }
|
||||
public List<Person> Friends { get; set; }
|
||||
|
||||
public string GetQuote()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTes
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_InvokeBasketRepositoryDeleteAsync_Once()
|
||||
public async Task ShouldInvokeBasketRepositoryDeleteAsyncOnce()
|
||||
{
|
||||
var basket = new Basket(_buyerId);
|
||||
basket.AddItem(1, It.IsAny<decimal>(), It.IsAny<int>());
|
||||
|
||||
@@ -36,6 +36,5 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTes
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
||||
await basketService.SetQuantities(123, null));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using Ardalis.Specification.QueryExtensions.Include;
|
||||
using Microsoft.eShopWeb.UnitTests.ApplicationCore.Helpers.Query;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.Builders
|
||||
{
|
||||
public class IncludeQueryBuilder
|
||||
{
|
||||
public IncludeQuery<Person, List<Person>> WithCollectionAsPreviousProperty()
|
||||
{
|
||||
var pathMap = new Dictionary<IIncludeQuery, string>();
|
||||
var query = new IncludeQuery<Person, List<Person>>(pathMap);
|
||||
pathMap[query] = nameof(Person.Friends);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public IncludeQuery<Book, Person> WithObjectAsPreviousProperty()
|
||||
{
|
||||
var pathMap = new Dictionary<IIncludeQuery, string>();
|
||||
var query = new IncludeQuery<Book, Person>(pathMap);
|
||||
pathMap[query] = nameof(Book.Author);
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@ using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
{
|
||||
public class GetMyOrders_Should
|
||||
public class GetMyOrders
|
||||
{
|
||||
private readonly Mock<IOrderRepository> _mockOrderRepository;
|
||||
|
||||
public GetMyOrders_Should()
|
||||
public GetMyOrders()
|
||||
{
|
||||
var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10);
|
||||
var address = new Address(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>());
|
||||
@@ -25,9 +25,9 @@ namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NotReturnNull_If_OrdersArePresent()
|
||||
public async Task NotReturnNullIfOrdersArePresent()
|
||||
{
|
||||
var request = new GetMyOrders("SomeUserName");
|
||||
var request = new eShopWeb.Web.Features.MyOrders.GetMyOrders("SomeUserName");
|
||||
|
||||
var handler = new GetMyOrdersHandler(_mockOrderRepository.Object);
|
||||
|
||||
@@ -10,11 +10,11 @@ using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
{
|
||||
public class GetOrderDetails_Should
|
||||
public class GetOrderDetails
|
||||
{
|
||||
private readonly Mock<IOrderRepository> _mockOrderRepository;
|
||||
|
||||
public GetOrderDetails_Should()
|
||||
public GetOrderDetails()
|
||||
{
|
||||
var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10);
|
||||
var address = new Address(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>());
|
||||
@@ -25,9 +25,9 @@ namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NotBeNull_If_Order_Exists()
|
||||
public async Task NotBeNullIfOrderExists()
|
||||
{
|
||||
var request = new GetOrderDetails("SomeUserName", 0);
|
||||
var request = new eShopWeb.Web.Features.OrderDetails.GetOrderDetails("SomeUserName", 0);
|
||||
|
||||
var handler = new GetOrderDetailsHandler(_mockOrderRepository.Object);
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BeNull_If_Order_Not_found()
|
||||
public async Task BeNullIfOrderNotFound()
|
||||
{
|
||||
var request = new GetOrderDetails("SomeUserName", 100);
|
||||
var request = new eShopWeb.Web.Features.OrderDetails.GetOrderDetails("SomeUserName", 100);
|
||||
|
||||
var handler = new GetOrderDetailsHandler(_mockOrderRepository.Object);
|
||||
|
||||
@@ -30,4 +30,8 @@
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="ApplicationCore\Helpers\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -3,10 +3,10 @@ using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.Web.Extensions.CacheHelpersTests
|
||||
{
|
||||
public class GenerateBrandsCacheKey_Should
|
||||
public class GenerateBrandsCacheKey
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnBrandsCacheKey()
|
||||
public void ReturnsBrandsCacheKey()
|
||||
{
|
||||
var result = CacheHelpers.GenerateBrandsCacheKey();
|
||||
|
||||
@@ -4,10 +4,10 @@ using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.Web.Extensions.CacheHelpersTests
|
||||
{
|
||||
public class GenerateCatalogItemCacheKey_Should
|
||||
public class GenerateCatalogItemCacheKey
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnCatalogItemCacheKey()
|
||||
public void ReturnsCatalogItemCacheKey()
|
||||
{
|
||||
var pageIndex = 0;
|
||||
int? brandId = null;
|
||||
@@ -3,10 +3,10 @@ using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.UnitTests.Web.Extensions.CacheHelpersTests
|
||||
{
|
||||
public class GenerateTypesCacheKey_Should
|
||||
public class GenerateTypesCacheKey
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnTypesCacheKey()
|
||||
public void ReturnsTypesCacheKey()
|
||||
{
|
||||
var result = CacheHelpers.GenerateTypesCacheKey();
|
||||
|
||||
Reference in New Issue
Block a user