When I run the Should_CopyTemplate_Test() test case below, the reference to CurrentTenant in the method it calls is returning NullReferenceException, as if the ICurrentTenant is not being injected.
I have this test set up:
{
private ISltnRepository _sltnRepository;
private ICurrentTenant _currentTenant;
public SltnManager_Tests()
{
_sltnRepository = GetRequiredService<ISltnRepository>();
_currentTenant = GetRequiredService<ICurrentTenant>();
}
[Fact]
public async Task Should_CopyTemplate_Test()
{
// Arrange
var sltnManager = new SltnManager(_sltnRepository);
// Act
Guid sltnId = Guid.Parse("00000000-14ba-4f0f-8417-c2f312768aea");
var sltn = await sltnManager.CopyTemplate(sltnId);
//Assert
sltn.Name.ShouldBe("");
}
}
Testing this method:
public async Task<Sltn> CopyTemplate(Guid templateId)
{
// Get the template solution from the host tenant
Sltn template;
using (CurrentTenant.Change(null))
{
template = await _sltnRepository.GetAsync(templateId);
}
// set a branches list from the template
List<Branch> branches = new List<Branch>();
foreach(var templateBranch in template.Branches)
{
branches.Add(new Branch(GuidGenerator.Create(), templateBranch.Name, templateBranch.Description, templateBranch.AppUserId, templateBranch.ParentBranchId));
}
//create a new solution for the tenant from the template
var sltn = new Sltn(GuidGenerator.Create(), template.Name, template.Description, template.DisplayOrder, branches);
await _sltnRepository.InsertAsync(sltn);
return sltn;
}
However CurrentTenant.Change is returning NullReferenceException on CurrentTenant.
Hi.
Thanks, that fixed the issue.
A supplementary question, does the SQlite EF Core Context used by the test framework support the IncludeDetails=true.
In my code above foreach(var templateBranch in template.Branches), Branches returns null.
Branches are added in a seeding class, which worked for SQL Server.
Ok.
I made the change and it worked.
Just to clarify.
Thanks - Adam
Ok, Thanks very much for your help.
I have the following test method in a test class that derives from AppDomainTestBase
The Column class is managed through the EntityInstance AggregateRoot.
The EntityInstance class has the following AddColumn method:
The AppEfCoreQueryableExtensions class includes:
And the EfCoreEntityInstanceRepository class contains:
So why doesn't ...
return the entity.Columns collection ?
Is it because of Unit of Work ?
By the way I was blocked from submitting this issue with the code embedded as text.
Is there a way to provide my Project privately ?
I've sent the project by email.
By the way, the Test class that contains the Test method is "EntityInstanceManager_Tests" in the Datansa.App.Domain.Tests project under the "Solution" folder.
Hi.
Yes that worked. So the issue was, in the Test class there was no ambient UOW, as there would be in an ApplicationService class.
Thanks for your help.
Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.
If you're creating a bug/problem report, please include following:
I have this method in a MenuContributor class in my Blazor project: <br>
private async Task<Guid> GetFirstProjectAsync(Guid sltnId)
{
Console.WriteLine($"SLTNID = {sltnId} ");
var projectFilter = new GetProjectsInput
{
SltnId = new Guid("00000000-14ba-4f0f-8417-c2f312768aea")
};
projectFilter.MaxResultCount = PageSize;
projectFilter.SkipCount = (CurrentPage - 1) * PageSize;
projectFilter.Sorting = CurrentSorting;
var result = await _projectsAppService.GetListAsync(projectFilter); <--- THIS IS WHERE THE EXCEPTION HAPPENS
if (result.Items.FirstOrDefault() != null)
{
return result.Items.FirstOrDefault().Id;
}
else
{
Guid defaultGuid = default;
return defaultGuid;
}
}
>> mono_wasm_start_single_stepping 2 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed. System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed. at Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope(Object tag) at Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope() at Autofac.Extensions.DependencyInjection.AutofacServiceScopeFactory.CreateScope() at Volo.Abp.Validation.ObjectValidator.GetErrors(Object validatingObject, String name, Boolean allowNull) at Volo.Abp.Validation.MethodInvocationValidator.AddMethodParameterValidationErrors(IAbpValidationResult context, ParameterInfo parameterInfo, Object parameterValue) at Volo.Abp.Validation.MethodInvocationValidator.AddMethodParameterValidationErrors(MethodInvocationValidationContext context) at Volo.Abp.Validation.MethodInvocationValidator.Validate(MethodInvocationValidationContext context) at Volo.Abp.Validation.ValidationInterceptor.Validate(IAbpMethodInvocation invocation) at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.<InterceptAsync>d__3`1[[Volo.Abp.Validation.ValidationInterceptor, Volo.Abp.Validation, Version=4.3.2.0, Culture=neutral, PublicKeyToken=null],[Volo.Abp.Application.Dtos.PagedResultDto`1[[Datansa.App.Solution.ProjectDto, Datansa.App.Application.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Volo.Abp.Ddd.Application.Contracts, Version=4.3.2.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Datansa.App.Blazor.Navigation.SolutionMenuContributor.GetFirstProjectAsync(Guid sltnId) in C:\Users\agilm\Documents\Repos\Datansa.App\src\Datansa.App.Blazor\Navigation\SolutionMenuContributor.cs:line 109 at Datansa.App.Blazor.Navigation.SolutionMenuContributor.ConfigureMainMenuAsync(MenuConfigurationContext context) in C:\Users\agilm\Documents\Repos\Datansa.App\src\Datansa.App.Blazor\Navigation\SolutionMenuContributor.cs:line 63 at Datansa.App.Blazor.Navigation.SolutionMenuContributor.ConfigureMenuAsync(MenuConfigurationContext context) in C:\Users\agilm\Documents\Repos\Datansa.App\src\Datansa.App.Blazor\Navigation\SolutionMenuContributor.cs:line 49 at Volo.Abp.UI.Navigation.MenuManager.GetAsync(String name) at Volo.Abp.AspNetCore.Components.Web.LeptonTheme.Components.ApplicationLayout.Navigation.MainMenuProvider.GetMenuAsync() at Volo.Abp.AspNetCore.Components.Web.LeptonTheme.Components.ApplicationLayout.MainHeader.MainHeader.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
However, I replicated the logic in a test method in my Application.Tests test project and the logic worked fine without exception.
Is it something to do with GUID?
This the class its trying to return:
public class ProjectDto : FullAuditedEntityDto<Guid> { public string Name { get; set; } public string Description { get; set; } public int DisplayOrder { get; set; } public List<ProjectConformDto> ProjectConforms { get; set; } }
Happy to provide the project if required.