I have a many to many relation between my two entities so the EF generated to me the junction tabel correctly and my code logic works fine but when i arrive to implement my unit tests i got a problem saying that :
System.InvalidOperationException : The property ‘ClientTypeEntityDocumentsToProvideEntity (Dictionary<string, object>).Id’ could not be found. Ensure that the property exists and has been included in the model.
so i don’t figure out how to fix this issue .
these are my two entities :
public class ClientTypeEntity : AEntity
{
/// <remarks>Fr :Nom type client.</remarks>
public string TypeName { get; set; }
/// <remarks>Fr : liste des dossier.</remarks>
public ICollection<FolderEntity> Folders { get; set; }
/// <remarks>Fr : liste des pièces á fournir.</remarks>
public ICollection<DocumentsToProvideEntity> ClientTypeDocuments { get; set; }
}
public class DocumentsToProvideEntity : AEntity
{
/// <remarks>Fr : Nom document.</remarks>
public string DocumentName { get; set; }
/// <remarks>Fr : Nom document.</remarks>
public string DocumentDescription { get; set; }
/// <remarks>Fr : Type client.</remarks>
public ICollection<ClientTypeEntity> ClientTypes { get; set; }
and this is my Repository test method :
[Test]
public async Task GetAll_WhenHaveEntities_ShouldReturnAsync()
{
// Arrange
var dataTestService = new DataTestService();
var modelInput = ClientTypeMock.GetClientType();
var expectedModel = ClientTypeMock.GetAllClientType();
var clientTypeRepository = new ClientTypesRepository(dataTestService.UnitOfWork, dataTestService.MapperCore, dataTestService.GetLogger<ClientTypesRepository>());
await clientTypeRepository.CreateAsync(modelInput);
// Act
var result = await clientTypeRepository.GetAllClientTypesAsync();
// Assert
result.Should().BeEquivalentTo(expectedModel);
}
And finally this is my Mock class :
public static class ClientTypeMock
{
public static ClientType GetClientType()
{
return new ClientType()
{
Id = 1,
TypeName = "personne morale",
Folders = new List<Folder>(),
ClientTypeDocuments = new Collection<DocumentsToProvide>()
{
new ()
{
DocumentName = "Attestation d’agriculteur",
DocumentDescription = "Attestation d’agriculteur",
},
},
};
}
public static IEnumerable<ClientType> GetAllClientType()
{
return new List<ClientType>()
{
new ClientType()
{
Id = 1,
TypeName = "personne morale",
Folders = new List<Folder>(),
ClientTypeDocuments = new List<DocumentsToProvide>(),
},
};
}
}
So can someone help me i’m realyy stucked ?