jeudi 9 juillet 2015

Machine.Fakes mock always null

I am trying to test a ShoppingCartService using machine.fakes. Within my GetViewCart() method the returns from both ShoppingCart (property) and GetShoppingCart() are both null, as if the mock hasn't been set up properly. I'm trying both just to make sure it wasn't an issue with using a property vs a function. All the documentation I've compared with my code seems correct, what am I missing?

public class WithAShoppingCartService: WithSubject<ShoppingCartService>
{
    Establish that = () =>
    {
        _shoppingCart = new ShoppingCart() {Name = "Test Cart!!"};
        The<ISessionBroker>()
            .WhenToldTo(x => x.GetShoppingCart())
            .Return(_shoppingCart);
        The<ISessionBroker>().ShoppingCart = _shoppingCart;
    };

    Because of = () => 
    {
        _cartDto = Subject.GetViewCart();
    };

    It should_call_mapping_engine = () => The<IMappingEngine>()
        .WasToldTo(x => x.Map<ViewCartDTO>(_shoppingCart));  // This test fails

    static ViewCartDTO _cartDto;
    static ShoppingCart _shoppingCart;
}

Here is the GetViewCart() on the ShoppingCartService:

    public ViewCartDTO GetViewCart()
    {
        var cart = _sessionBroker.ShoppingCart; // This is always NULL
        var otherCart = _sessionBroker.GetShoppingCart();  // So is this
        var dto = _mappingEngine.Map<ViewCartDTO>(cart);
        return dto;
    }

Aucun commentaire:

Enregistrer un commentaire