Skip to content

Commit a8b1fa0

Browse files
committed
feat: add utility classes for Wishlist, User, Image, and Cart in unit tests
1 parent d9ff83b commit a8b1fa0

File tree

5 files changed

+478
-0
lines changed

5 files changed

+478
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Ecommerce.Application.UseCases.Products.Common;
2+
using Ecommerce.Application.UseCases.Users.Queries.GetCartItems;
3+
using Ecommerce.Domain.ProductAggregate.ValueObjects;
4+
5+
namespace Ecommerce.UnitTests.Ecommerce.Application.UnitTests.UseCases;
6+
7+
public partial class Utils
8+
{
9+
public record Cart
10+
{
11+
public const int PageNumber = 1;
12+
public const int PageSize = 10;
13+
14+
public static GetCartQuery CreateGetCartQuery()
15+
{
16+
return new GetCartQuery(PageNumber, PageSize);
17+
}
18+
19+
public static CartResult CreateCartResult(int i = 1)
20+
{
21+
var cartItemResults = CartItem.CreateCartItemResults(i);
22+
var totalPrice = cartItemResults.Sum(x => x.Product.PriceValue * x.Quantity);
23+
return new CartResult
24+
{
25+
Items = CartItem.CreateCartItemResults(i),
26+
TotalItems = i,
27+
TotalPrice = totalPrice,
28+
};
29+
}
30+
31+
public record CartItem
32+
{
33+
public const int Quantity = 10;
34+
public static readonly ProductId ProductId = ProductId.CreateUnique();
35+
36+
public static Domain.UserAggregate.Entities.CartItem Create()
37+
{
38+
return Domain.UserAggregate.Entities.CartItem.Create(
39+
Utils.Cart.CartItem.ProductId,
40+
Utils.Cart.CartItem.Quantity
41+
);
42+
}
43+
44+
public static List<Domain.UserAggregate.Entities.CartItem> CreateCartItems(int i = 1)
45+
{
46+
return Enumerable.Range(1, i).Select(_ => Create()).ToList();
47+
}
48+
49+
public static List<CartItemResult> CreateCartItemResults(int i = 1)
50+
{
51+
return Enumerable
52+
.Range(1, i)
53+
.Select(_ => new CartItemResult
54+
{
55+
Id = Utils.Cart.CartItem.ProductId.Value.ToString(),
56+
Quantity = Utils.Cart.CartItem.Quantity,
57+
Product = Utils.Product.CreateProductResult(Utils.Product.CreateProduct()),
58+
})
59+
.ToList();
60+
}
61+
}
62+
}
63+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Text;
2+
3+
namespace Ecommerce.UnitTests.Ecommerce.Application.UnitTests.UseCases;
4+
5+
public partial class Utils
6+
{
7+
public record Image
8+
{
9+
public const string ImageData = "ImageData";
10+
public static readonly Stream ImageStream = new MemoryStream(Encoding.UTF8.GetBytes(ImageData));
11+
public static long ImageSize => ImageStream.Length;
12+
13+
public static readonly string FileName = nameof(FileName);
14+
public static readonly string LeftImageFileName = nameof(LeftImageFileName);
15+
public static readonly string RightImageFileName = nameof(RightImageFileName);
16+
public static readonly string TopImageFileName = nameof(TopImageFileName);
17+
public static readonly string BackImageFileName = nameof(BackImageFileName);
18+
public static readonly string FrontImageFileName = nameof(FrontImageFileName);
19+
public static readonly string BottomImageFileName = nameof(BottomImageFileName);
20+
21+
public static string ImageDataFromIndex(int i) => $"{ImageData} {i}";
22+
23+
public static Stream ImageStreamFromIndex(int i) =>
24+
new MemoryStream(Encoding.UTF8.GetBytes(ImageDataFromIndex(i)));
25+
26+
public static long ImageSizeFromIndex(int i) => ImageStreamFromIndex(i).Length;
27+
28+
public static string FileNameFromIndex(int i) => $"{FileName} {i}";
29+
30+
public static string LeftImageFileNameFromIndex(int i) => $"{LeftImageFileName} {i}";
31+
32+
public static string RightImageFileNameFromIndex(int i) => $"{RightImageFileName} {i}";
33+
34+
public static string TopImageFileNameFromIndex(int i) => $"{TopImageFileName} {i}";
35+
36+
public static string BackImageFileNameFromIndex(int i) => $"{BackImageFileName} {i}";
37+
38+
public static string FrontImageFileNameFromIndex(int i) => $"{FrontImageFileName} {i}";
39+
40+
public static string BottomImageFileNameFromIndex(int i) => $"{BottomImageFileName} {i}";
41+
}
42+
}

0 commit comments

Comments
 (0)