Hello,
Is there a way to execute a hard delete on a mocked database in a unit test? In an appservice we can excecute IRepository.HardDelete().
We want to execute the hard delete in the unit test (class derived from AppTestBase), we can't resolve the IRepository there.
Following example explains what we are trying to do:
[Fact]
public async Task Should_Delete_Entity_With_LocalizedString()
{
// Create a new test entity
await _testLocalizedResourceAppService.CreateTestEntityA();
// Test for the create entity
UsingDbContext(context =>
{
var resources = context.TestLocalizedResources.Include(x => x.Values).ToList();
resources.Count.ShouldBe(1);
resources.First().Values.Count.ShouldBe(2);
});
// Delete the created entity
var entityAList = await _testLocalizedResourceAppService.GetList();
await _testLocalizedResourceAppService.Delete(entityAList.Items.First().Id);
// The entity is soft deleted, the resources still exists
UsingDbContext(context =>
{
context.TestEntitiesA.Count().ShouldBe(1);
context.TestEntitiesA.First().IsDeleted.ShouldBeTrue();
var resources = context.TestLocalizedResources.Include(x => x.Values).ToList();
resources.Count.ShouldBe(1);
resources.First().Values.Count.ShouldBe(2);
});
// Execute hard delete
// How to execute hard delete here?
// The rows should be deleted from the database
UsingDbContext(context =>
{
context.TestEntitiesA.Count().ShouldBe(0);
context.LocalizedResources.Count().ShouldBe(0);
context.LocalizedResourceValues.Count().ShouldBe(0);
});
}
We already tried variants of following code without success:
var uowOptions = new UnitOfWorkOptions();
uowOptions.FilterOverrides.Add(new DataFilterConfiguration(AbpDataFilters.SoftDelete, false));
await WithUnitOfWorkAsync(() =>
{
return _testLocalizedResourceAppService.Delete(entityAList.Items.First().Id);
}, uowOptions);
Hi,
We have a product entity which has a collection with specifications like this:
[Table("Masterdata.Products")]
public class Product : FullAuditedEntity, IMustHaveTenant
{
public int TenantId { get; set; }
[Required]
public string Code { get; set; }
public ICollection<ProductSpecificationValue> Specifications { get; set; }
}
We want to update the product trough following DTO:
public class ProductCreateOrEditDto : EntityDto<int?>
{
[Required]
public string Code { get; set; }
public ICollection<ProductSpecificationValueCreateOrEditDto> Specifications { get; set; }
}
Following code we want to use to update the product:
public async Task Update(ProductCreateOrEditDto input)
{
var product = await _productRepository.GetAllIncluding(e => e.Specifications).Where(e => e.Id == input.Id).FirstOrDefaultAsync();
ObjectMapper.Map(input, product);
}
We can't update the values in the specification as the objectmapper won't sync the collection. The collection in the product gets deleted and AutoMapper creates new instances for the specification in the input object. Referring to following github topic i would assume that Automapper would sync the collections based on the EF properties. https://github.com/aspnetboilerplate/aspnetboilerplate/pull/4034
Do we need to add some configuration to make this work? Are we missing something else?