Hi,
I'm looking at the unit test: AuditLogAppService_Test. Should_Get_Audit_Logs()
Here, we setup the Arrange part by Adding some values to the AuditLogs table and then calling the service in the act step.
I followed the same step to test my own app service. However, I got the DbContext disposed exception. I followed through other discussions here and was able to get the tests to work by starting a unit of work.
How is it working in the AuditLogAppService_Test?
4 Answer(s)
-
0
Can you show your test case?
-
0
public class TenantCustmozation_Tests : AppTestBase { private readonly TenantCustomizationAppService _app; public TenantCustmozation_Tests() { _app = Resolve<TenantCustomizationAppService>(); } [Fact] public async Task App_returns_tenantCustomization_if_present() { LoginAsDefaultTenantAdmin(); var uowManager = Resolve<IUnitOfWorkManager>(); using (uowManager.Begin()) { UsingDbContext( ctx => { ctx.Customizations.Add(new PatientPortal.POS.TenantCustomization { LoginBodyText = "Hello", TenantId = AbpSession.TenantId.Value }); }); var result = await _app.GetCustomizations(); result.ShouldNotBeNull(); result.LoginBodyText.ShouldBe("Hello"); } }
This is the working test. When I remove the uowManager.Begin(), the test fails because the DbContext has already been disposed when it reaches the _app.GetCustomizations() call.
-
0
Can you try resolving the interface ITenantCustomizationAppService instead of the class?
-
0
Yeah. that was the case . :( Thank you for that.