I have a section of code that runs when I fire up my Asp.Net app, but Unit Tests fail.
The code I'm using is here:
var thisResource = db.ProjectSubmission.Find(id);
if (thisResource == null)
{
return Redirect(Request.UrlReferrer.ToString());
}
// Error during Unit test happens here:
var thisModel = Mapper.Map<ProjectSubmissionViewModel>(thisResource);
In my AutoMapperConfig.cs file (run during app startup) I map it like this:
Mapper.CreateMap<ProjectSubmission, ProjectSubmissionViewModel>()
.ForMember(dest => dest.RequestedReviewsCount,
opt => opt.ResolveUsing<CustomProjectSubmissionResolver>());
public class CustomProjectSubmissionResolver : ValueResolver<ProjectSubmission, int>
{
protected override int ResolveCore(ProjectSubmission source)
{
return source.RequestedReviews.Count;
}
}
My thisResource.RequestedReviews has one record during the Unit test.
I'm sure I'm missing something, but not sure what.
Here is more of the message I get during the test:
Mapping types:
ProjectSubmission -> ProjectSubmissionViewModel
PublicationSystem.Model.ProjectSubmission -> PublicationSystem.ViewModels.ProjectSubmissionViewModel
Destination path:
ProjectSubmissionViewModel
Source value:
PublicationSystem.Model.ProjectSubmission
Aucun commentaire:
Enregistrer un commentaire