I want to test my service, and i still have this error after hours of trying to find how should i make this right
public async Task DeleteAsync(string entityId, IEntityRef child)
{
Requires.NotNull(entityId, nameof(entityId));
Requires.NotNull(child, nameof(child));
await using IAtomicScope atomicScope = _atomicScopeFactory.Create();
PartnerBase parentPartner = await _partnerStore.GetAsync(entityId, atomicScope);
IEntityRef parent = new EntityRef
{
Id = entityId,
EntityType = parentPartner.EntityType
};
await _validator.ValidateOnDeleteLinkAsync(parent, child);
IContextDetail currentContext = await _contextService.GetCurrentContextAsync();
PersonModel person = await _verifier.GetAccessibleAsync(child, atomicScope);
await _verifier.VerifyManagerialPermissionsAsync(currentContext, parent, atomicScope);
IEntityMembership membership = new EntityMembership
{
Parent = parent.ToMembershipEntityRef(),
Entity = child.ToMembershipEntityRef()
};
await _membershipService.DeleteAsync(membership, atomicScope);
await NotifyMembershipChanged(parent, null, person.UserOpenId, atomicScope);
await atomicScope.CommitAsync();
}
and my test
public async void DeleteAsync_ParentNotPersonCorrectCall_MembershipDeleteCalled(EntityType entityType)
{
IEntityRef parent = _fixture.Build<EntityRef>()
.With(q => q.EntityType, entityType)
.Create();
IEntityRef child = _fixture.Create<EntityRef>();
PersonModel person = _fixture.Create<PersonModel>();
IEntity entity = _fixture.Create<Department>();
_verifier.Setup(v => v.GetAccessibleAsync(child, _atomicScope.Object))
.ReturnsAsync(person);
_entityReaderService.SetupGetFirstByReferenceIdAsync(parent.GetReferenceId(), entity, _atomicScope.Object);
await _service.DeleteAsync(parent.Id, child);
IEntityMembership membership = new EntityMembership
{
Parent = parent.ToMembershipEntityRef(),
Entity = child.ToMembershipEntityRef()
};
_membershipService.Verify(m => m.DeleteAsync(It.Is<IEntityMembership>(q => q.IsEquivalentTo(membership)), _atomicScope.Object), Times.Once);
}
It throws an error saying
Object reference not set to an instance of an object.
PS: It's my first question, please be kind and don't let it be the last one.. Thanks!