samedi 4 juillet 2015

MEF Moq-cking on Unit Testing

This is the class with the Imported MEF attribute

public class MyManager : IMyManager {
    [ImportMany]
    public ICollection<Lazy<IContext, IContextMetadata>> Contexts { get; set; }
    public IContext { get; set; }

    // Implemented from IMyManager interface
    public void DoStuff(string name) {
        this.Context = GetContext(name);
    }

    private IContext GetContext(string name) {
        return Contexts.Where(c => c.Metadata.Name.Equals(name)).Single().Value;
    }
}

I was following this answer to attempt to mock it and test it but I got lost in the actual/expected values, since in my case I need to assert MyManager .Context was changed.

I'm figuring I have to Mock<IContext>() and use it to Assert.Equals, but how do I mock up the whole lazy list?

Aucun commentaire:

Enregistrer un commentaire