SA-143 all tests and issues fixed

This commit is contained in:
Mykhailo Bilodid 2023-11-18 01:46:59 +02:00
parent 4bd13648b6
commit 5973598063
3 changed files with 99 additions and 6 deletions

View File

@ -55,7 +55,8 @@ public abstract class BaseRepository<TEntity> : IBaseRepository<TEntity> where T
public async Task<int> GetTotalCountAsync() public async Task<int> GetTotalCountAsync()
{ {
return (int)(await this._collection.EstimatedDocumentCountAsync()); var filter = Builders<TEntity>.Filter.Eq("IsDeleted", false);
return (int)(await this._collection.CountDocumentsAsync(x => !x.IsDeleted));
} }
public async Task<int> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken) public async Task<int> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken)

View File

@ -109,6 +109,7 @@ public class DbInitializer
var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab");
var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab"); var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab");
var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab"); var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab");
var wishlistId5 = ObjectId.Parse("65575253dbe88a3c118e1ca2");
var wishlists = new Wishlist[] var wishlists = new Wishlist[]
{ {
@ -121,6 +122,14 @@ public class DbInitializer
CreatedDateUtc = DateTime.UtcNow CreatedDateUtc = DateTime.UtcNow
}, },
new Wishlist new Wishlist
{
Id = wishlistId5,
Name = "Gaming PC",
Type = WishlistTypes.Product.ToString(),
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
},
new Wishlist
{ {
Id = wishlistId2, Id = wishlistId2,
Name = "Generic Wishlist Name", Name = "Generic Wishlist Name",
@ -162,6 +171,8 @@ public class DbInitializer
var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab");
var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab"); var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab");
var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab"); var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab");
var wishlistId5 = ObjectId.Parse("65575253dbe88a3c118e1ca2");
var messages = new Message[] var messages = new Message[]
{ {
@ -211,6 +222,51 @@ public class DbInitializer
CreatedDateUtc = DateTime.UtcNow.AddSeconds(50) CreatedDateUtc = DateTime.UtcNow.AddSeconds(50)
}, },
new Message new Message
{
Text = "Message 1",
Role = MessageRoles.User.ToString(),
WishlistId = wishlistId5,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
},
new Message
{
Text = "Message 2",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId5,
CreatedDateUtc = DateTime.UtcNow.AddSeconds(5)
},
new Message
{
Text = "Message 3",
Role = MessageRoles.User.ToString(),
WishlistId = wishlistId5,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow.AddSeconds(20)
},
new Message
{
Text = "Message 4",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId5,
CreatedDateUtc = DateTime.UtcNow.AddSeconds(25)
},
new Message
{
Text = "Message 5",
Role = MessageRoles.User.ToString(),
WishlistId = wishlistId5,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow.AddSeconds(45)
},
new Message
{
Text = "Message 6",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId5,
CreatedDateUtc = DateTime.UtcNow.AddSeconds(50)
},
new Message
{ {
Text = "Prompt", Text = "Prompt",
Role = MessageRoles.User.ToString(), Role = MessageRoles.User.ToString(),
@ -249,6 +305,7 @@ public class DbInitializer
var wishlistId1 = ObjectId.Parse("ab79cde6f69abcd3efab65cd"); var wishlistId1 = ObjectId.Parse("ab79cde6f69abcd3efab65cd");
var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab");
var wishlistId3 = ObjectId.Parse("65575253dbe88a3c118e1ca2");
var products = new Product[] var products = new Product[]
{ {
@ -285,6 +342,40 @@ public class DbInitializer
WishlistId = wishlistId1, WishlistId = wishlistId1,
CreatedById = user1.Id, CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow CreatedDateUtc = DateTime.UtcNow
},
new Product
{
Name = "AMD Ryzen 5 5600G 6-Core 12-Thread Unlocked Desktop Processor with Radeon Graphics",
Description = "Features best-in-class graphics performance in a desktop processor for smooth 1080p gaming, no graphics card required",
Rating = 4.8,
Price = 120,
Url = "https://a.co/d/5ceuIrq",
ImagesUrls = new string[]
{
"https://m.media-amazon.com/images/I/51f2hkWjTlL._AC_SL1200_.jpg",
"https://m.media-amazon.com/images/I/51iji7Gel-L._AC_SL1200_.jpg"
},
WasOpened = false,
WishlistId = wishlistId3,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
},
new Product
{
Name = "Samsung 970 EVO Plus SSD 2TB NVMe M.2 Internal Solid State Hard Drive, V-NAND Technology, Storage and Memory Expansion for Gaming, Graphics w/ Heat Control, Max Speed, MZ-V7S2T0B/AM ",
Description = "7 Year Limited Warranty: The 970 EVO Plus provides up to 1200 TBW (Terabytes Written) with 5-years of protection for exceptional endurance powered by the latest V-NAND technology and Samsung's reputation for quality ",
Rating = 4.8,
Price = 153,
Url = "https://a.co/d/gxnuqs1",
ImagesUrls = new string[]
{
"https://m.media-amazon.com/images/I/51Brl+iYtvL._AC_SL1001_.jpg",
"https://m.media-amazon.com/images/I/51GOfLlVwoL._AC_SL1001_.jpg"
},
WasOpened = false,
WishlistId = wishlistId3,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
}, },
}; };

View File

@ -26,6 +26,7 @@ public class WishlistsTests : TestsBase
private const string TestingValidWishlistId = "ab79cde6f69abcd3efab65cd"; private const string TestingValidWishlistId = "ab79cde6f69abcd3efab65cd";
private const string TestingValidWishlistId2 = "65575253dbe88a3c118e1ca2";
public WishlistsTests(TestingFactory<Program> factory) public WishlistsTests(TestingFactory<Program> factory)
: base(factory) : base(factory)
@ -178,7 +179,7 @@ public class WishlistsTests : TestsBase
}", }",
variables = new variables = new
{ {
wishlistId = TestingValidWishlistId wishlistId = TestingValidWishlistId2
} }
}; };
@ -246,7 +247,7 @@ public class WishlistsTests : TestsBase
}", }",
variables = new variables = new
{ {
wishlistId = TestingValidWishlistId, wishlistId = TestingValidWishlistId2,
pageNumber = 1, pageNumber = 1,
pageSize = 2 pageSize = 2
} }
@ -823,7 +824,7 @@ public class WishlistsTests : TestsBase
}", }",
variables = new variables = new
{ {
wishlistId = TestingValidWishlistId, wishlistId = TestingValidWishlistId2,
pageNumber = 100, pageNumber = 100,
pageSize = 2 pageSize = 2
} }
@ -878,7 +879,7 @@ public class WishlistsTests : TestsBase
query = "query productsPageFromPersonalWishlist($wishlistId: String!, $pageNumber: Int!, $pageSize: Int!) { productsPageFromPersonalWishlist (wishlistId: $wishlistId, pageNumber: $pageNumber, pageSize: $pageSize) { hasNextPage, hasPreviousPage, items { id, url, name, description, rating, imagesUrls, wasOpened, wishlistId }, pageNumber, pageSize, totalItems, totalPages } }", query = "query productsPageFromPersonalWishlist($wishlistId: String!, $pageNumber: Int!, $pageSize: Int!) { productsPageFromPersonalWishlist (wishlistId: $wishlistId, pageNumber: $pageNumber, pageSize: $pageSize) { hasNextPage, hasPreviousPage, items { id, url, name, description, rating, imagesUrls, wasOpened, wishlistId }, pageNumber, pageSize, totalItems, totalPages } }",
variables = new variables = new
{ {
wishlistId = TestingValidWishlistId, wishlistId = TestingValidWishlistId2,
pageNumber = 1, pageNumber = 1,
pageSize = 100 pageSize = 100
} }
@ -890,7 +891,7 @@ public class WishlistsTests : TestsBase
Assert.NotNull(pagedList); Assert.NotNull(pagedList);
Assert.Equal("Samsung 970 EVO Plus SSD 2TB NVMe M.2 Internal Solid State Hard Drive, V-NAND Technology, Storage and Memory Expansion for Gaming, Graphics w/ Heat Control, Max Speed, MZ-V7S2T0B/AM ", pagedList.Items.ToList()[1].Name); Assert.Equal("Samsung 970 EVO Plus SSD 2TB NVMe M.2 Internal Solid State Hard Drive, V-NAND Technology, Storage and Memory Expansion for Gaming, Graphics w/ Heat Control, Max Speed, MZ-V7S2T0B/AM ", pagedList.Items.ToList()[1].Name);
Assert.Equal(TestingValidWishlistId, pagedList.Items.ToList()[1].WishlistId); Assert.Equal(TestingValidWishlistId2, pagedList.Items.ToList()[1].WishlistId);
} }
[Fact] [Fact]