0

OK - So, I have been trying to search for this but I probably have my understanding (and hence wording) of the question wrong so I will do my best to explain and hopefully someone can make sense of what I need to do and point me in the right direction - here goes.

I have a view model, the view model takes and adapter which I mock - no problem there, but the asserts I want to write are going to check that setting certain properties of the view model updated certain properties of an object that is itself a property of the adapter. I understand how to use setup to say anytime a method is called return "X" but this isn't a method, it's a property and I am stumped - seems like it outta be simple.

Here is some code from the view model that gives you an idea of what I am doing.

public bool OnlyUseFedEx
{
  get { return vendorQualitativeMetricsAdapter.VendorQualitativeMetric.OnlyUseFedEx; }
  set { vendorQualitativeMetricsAdapter.VendorQualitativeMetric.OnlyUseFedEx = value; }
}

Here is what I started with the test method

    [TestMethod]
public void VQM_ShippingViewModel_Can_Update_Adapters_vendorManagementProxy()
{
  var vendorManagementProxy = new VendorManagementProxy();
  var vqmAdapter = new Mock<IVendorQualitativeMetricsAdapter>();
  //This is where I would like to say - always return that vendorManagementProxy object I created. 
  vqmAdapter.Setup(a => a.VendorQualitativeMetric ???
  ShippingViewModel shippingViewModel;
}

OK - Thanks...

Phil Sandler
  • 27,544
  • 21
  • 86
  • 147
Kenn
  • 2,709
  • 2
  • 29
  • 60

2 Answers2

3

Can't you just use Returns on the Setup call? Maybe I misunderstood the question though...

vqmAdapter.Setup(a => a.VenderQualitativeMetric).Returns(venderManagementProxy)

this is a good place to start looking for MoQ tips and tricks :-)

RoelF
  • 7,483
  • 5
  • 44
  • 67
0

You can use SetupGet:

vqmAdapter.SetupGet(a => a.VendorQualitativeMetric).Returns(vendorManagementProxy);

Update: I've just learnt that you can also use Setup too - see Setup() vs SetupGet() - according to that answer, which you use "is probably ... personal preference"

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165