0

I have a class Alias. I have used it with Autofixture and everything have been working OK. The tests started to fail however when I've added an interface property to my class.

So that's my class:

public class Alias : NotifyPropertyChanged
{
    private Alias()
    {
        Nicks = new List<string>();
        History = new History(this);
    }
    
    public IDownloader Downloader {get;set;}
}

I am using it in test like that:

Fixture fixture =  new Fixture();

var alias = fixture.Create<Alias>();

And got Exception:

loeh.AutoFixture.ObjectCreationException : AutoFixture was unable to create an instance from Core.Helpers.IDownloader...

I've tried to register the interface by fixture.Register<IVKDownloader>(() => new Downloader()); but I still get this error.

If I change this property to use type instead of the interface public Downloader Downloader {get;set;} everything is working normally. How could I fix this?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Seekeer
  • 1,344
  • 2
  • 18
  • 31
  • possible duplicate of [How to let Autofixture create an instance of a type that contains properties with an interface type?](http://stackoverflow.com/questions/12949417/how-to-let-autofixture-create-an-instance-of-a-type-that-contains-properties-wit) – hometoast Nov 03 '14 at 18:55
  • 2
    Why do you expect `fixture.Register` to impact how `IDownloader` is being created? – Mark Seemann Nov 03 '14 at 19:39
  • 3
    Is that a typo of `IVKDownloader` instead of `IDownloder`? If not that might be why it isn't working – John Nov 03 '14 at 20:39
  • 1
    @Seekeer ok I'll add it as an answer then, glad its working! :) – John Nov 03 '14 at 21:27

1 Answers1

6

fixture.Register<IVKDownloader>(() => new Downloader()); Looks like that is a typo for IDownloader

fixture.Register<IDownloader>(() => new Downloader());

John
  • 6,503
  • 3
  • 37
  • 58