Skip to main content

Posts

Showing posts from October, 2011

Using callbacks with Moq to check state

Here is the scenario, I have a method that takes an object, however - nowhere in your CUT (class under test) can you publicly access this object to verify state the state of it. I run into this scenario a lot regarding view models, the view model exposes things that we need to look at and interact with as public properties but anything the user doesn’t interact with or see is private which can make testing a pain. Let’s look at an example of something we can easily test before we get to the problem. [ TestMethod ] public void SaveCommandGetsSetWhenConstructed() { //Arrange var adapterMock = new Mock < INewOrderAdapter >(); adapterMock.Setup(x => x.DeclinedBuyItNowPartNumbers) .Returns( new List < string >() { "12345" }); var vm = new PartDeclinedViewModel (eventAggregator, adapterMock.Object) { SelectedLineItems = new ObservableCollection < DeclineReasons >() { DeclineReasons .CONDITI