How to verify multiple properties on an object passed as parameter?

Posted by Sandbox on Stack Overflow See other posts from Stack Overflow or by Sandbox
Published on 2010-06-07T17:39:20Z Indexed on 2010/06/07 17:42 UTC
Read the original article Hit count: 149

Filed under:
|

I want to verify multiple properties on an object passed as parameter.

Mock<IInternalDataStore> mockOrder = new Mock<IInternalDataStore>();

I can think of doing it this way. Is this correct? Does a better way exist?

mockDataStore.Setup(o => o.PlaceQuickOrder(It.Is<IOrder>(order => order.Id == 1)));
mockDataStore.Setup(o => o.PlaceQuickOrder(It.Is<IOrder>(order => order.type == OrderType.Qucik)));
mockDataStore.Setup(o => o.PlaceQuickOrder(It.Is<IOrder>(order => order.UnitName == "NYunit")));

mockDataStore.VerifyAll();

Another way of acheiving this would be to create a fake order object, expectedOrderObj with expected properties and do something like this:

mockDataStore.Setup(o => o.PlaceQuickOrder(It.Is<IOrder>(order => order == expectedOrderObj )));

But, I don't want to override ==.

Do we have a solution for this in moq?

My classes look something like this:

 public interface IInternalDataStore
    {
        void PlaceQuickOrder(IOrder order);

        void PlaceUltraFastOrder(IOrder order);        

    }

    public interface IOrder
    {
        public int Id { get; }

        public OrderType type { get; set; }

        public string UnitName { get; set; }
    }

    public enum OrderType
    {
        Qucik = 1,
        UltraFast = 2
    }

© Stack Overflow or respective owner

Related posts about mocking

Related posts about moq