0

I have a class:

public class WeekCompareModel 
{
   public WeekData Week1 {get; set;}
   public WeekData Week1 {get; set;}  
}

This object is created like this:

var model = new WeekCompareModel
{
   Week1 = Repo.FirstOrDefault(x => x.Typ == (int)type && x.Week == week1),
   Week2 = Repo.FirstOrDefault(x => x.Typ == (int)type && x.Week == week2),
};

In my code this is instantiated in a manager class that implements a base class:

public class SystemStatisticsManager : CrudManagerBase<Systemstatistik>, ISystemStatisticsManager
{
    public SystemStatisticsManager()
    {
        Repo = CoreRepository.Systemstatistiks;
    }
...
}

My crudmanagerbase class:

public class CrudManagerBase<T> : ICrudManagerBase<T>
    where T : class
{
    protected readonly ICachedCoreRepository CoreRepository;
    protected IQueryable<T> Repo;
 ...
 }

What I would like to do in my unittest is to override the call to

 new WeekCompareModel { ... }

and replaced it with a test instance of that model.

Any idea if this is possible with FakeItEasy or any other Mock library?

h3li0s
  • 613
  • 9
  • 25

1 Answers1

0

As noted in @Nikosi's comment, FakeItEasy will not be able to do this without delegating creation to another method.

But you asked about other libraries as well. I've used Typemock Isolator in the past, and it has the capability. The feature is called Faking Future Instances, and can be used like

var handle = Isolate.Fake.NextInstance<Dependency>();

// Do something with the system under test

The downside is that Isolator is a commercial product and, as I type, costs about $399 US/year.

Oh. I just noticed that JustMock also has Future Mocking as well. I can't tell from the documentation but assume it also only provides the feature in its paid version.

Blair Conrad
  • 233,004
  • 25
  • 132
  • 111