|
|
@ -25,7 +25,7 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart |
|
|
ProductEntityCache = GetRequiredService<IEntityCache<Product, Guid>>(); |
|
|
ProductEntityCache = GetRequiredService<IEntityCache<Product, Guid>>(); |
|
|
ProductCacheItem = GetRequiredService<IEntityCache<ProductCacheItem, Guid>>(); |
|
|
ProductCacheItem = GetRequiredService<IEntityCache<ProductCacheItem, Guid>>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_Return_Null_IF_Entity_Not_Exist() |
|
|
public async Task Should_Return_Null_IF_Entity_Not_Exist() |
|
|
{ |
|
|
{ |
|
|
@ -41,28 +41,32 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart |
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductEntityCache.GetAsync(notExistId)); |
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductEntityCache.GetAsync(notExistId)); |
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductCacheItem.GetAsync(notExistId)); |
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductCacheItem.GetAsync(notExistId)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_Return_EntityCache() |
|
|
public async Task Should_Return_EntityCache() |
|
|
{ |
|
|
{ |
|
|
var product = await ProductEntityCache.FindAsync(TestDataBuilder.ProductId); |
|
|
var product = await ProductEntityCache.FindAsync(TestDataBuilder.ProductId); |
|
|
product.ShouldNotBeNull(); |
|
|
product.ShouldNotBeNull(); |
|
|
|
|
|
product = await ProductEntityCache.FindAsync(TestDataBuilder.ProductId); |
|
|
|
|
|
product.ShouldNotBeNull(); |
|
|
product.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
product.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
product.Name.ShouldBe("Product1"); |
|
|
product.Name.ShouldBe("Product1"); |
|
|
product.Price.ShouldBe(decimal.One); |
|
|
product.Price.ShouldBe(decimal.One); |
|
|
|
|
|
|
|
|
var productCacheItem = await ProductCacheItem.FindAsync(product.Id); |
|
|
var productCacheItem = await ProductCacheItem.FindAsync(product.Id); |
|
|
productCacheItem.ShouldNotBeNull(); |
|
|
productCacheItem.ShouldNotBeNull(); |
|
|
|
|
|
productCacheItem = await ProductCacheItem.FindAsync(product.Id); |
|
|
|
|
|
productCacheItem.ShouldNotBeNull(); |
|
|
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
productCacheItem.Name.ShouldBe("Product1"); |
|
|
productCacheItem.Name.ShouldBe("Product1"); |
|
|
productCacheItem.Price.ShouldBe(decimal.One); |
|
|
productCacheItem.Price.ShouldBe(decimal.One); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_Return_Null_IF_Deleted() |
|
|
public async Task Should_Return_Null_IF_Deleted() |
|
|
{ |
|
|
{ |
|
|
await ProductRepository.DeleteAsync(TestDataBuilder.ProductId); |
|
|
await ProductRepository.DeleteAsync(TestDataBuilder.ProductId); |
|
|
|
|
|
|
|
|
(await ProductEntityCache.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull(); |
|
|
(await ProductEntityCache.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull(); |
|
|
(await ProductCacheItem.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull(); |
|
|
(await ProductCacheItem.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull(); |
|
|
} |
|
|
} |
|
|
@ -77,13 +81,13 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart |
|
|
product.Name = "Product2"; |
|
|
product.Name = "Product2"; |
|
|
product.Price = decimal.Zero; |
|
|
product.Price = decimal.Zero; |
|
|
await ProductRepository.UpdateAsync(product); |
|
|
await ProductRepository.UpdateAsync(product); |
|
|
|
|
|
|
|
|
product = await ProductEntityCache.FindAsync(product.Id); |
|
|
product = await ProductEntityCache.FindAsync(product.Id); |
|
|
product.ShouldNotBeNull(); |
|
|
product.ShouldNotBeNull(); |
|
|
product.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
product.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
product.Name.ShouldBe("Product2"); |
|
|
product.Name.ShouldBe("Product2"); |
|
|
product.Price.ShouldBe(decimal.Zero); |
|
|
product.Price.ShouldBe(decimal.Zero); |
|
|
|
|
|
|
|
|
var productCacheItem = await ProductCacheItem.FindAsync(product.Id); |
|
|
var productCacheItem = await ProductCacheItem.FindAsync(product.Id); |
|
|
productCacheItem.ShouldNotBeNull(); |
|
|
productCacheItem.ShouldNotBeNull(); |
|
|
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId); |
|
|
@ -95,6 +99,11 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart |
|
|
[Serializable] |
|
|
[Serializable] |
|
|
public class Product : FullAuditedAggregateRoot<Guid> |
|
|
public class Product : FullAuditedAggregateRoot<Guid> |
|
|
{ |
|
|
{ |
|
|
|
|
|
public Product() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public Product(Guid id, string name, decimal price) |
|
|
public Product(Guid id, string name, decimal price) |
|
|
: base(id) |
|
|
: base(id) |
|
|
{ |
|
|
{ |
|
|
@ -102,9 +111,6 @@ public class Product : FullAuditedAggregateRoot<Guid> |
|
|
Price = price; |
|
|
Price = price; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[JsonInclude] |
|
|
|
|
|
public override Guid Id { get; protected set; } |
|
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; } |
|
|
public string Name { get; set; } |
|
|
|
|
|
|
|
|
public decimal Price { get; set; } |
|
|
public decimal Price { get; set; } |
|
|
@ -119,4 +125,4 @@ public class ProductCacheItem |
|
|
public string Name { get; set; } |
|
|
public string Name { get; set; } |
|
|
|
|
|
|
|
|
public decimal Price { get; set; } |
|
|
public decimal Price { get; set; } |
|
|
} |
|
|
} |
|
|
|