fais
fais

Reputation: 175

Unable to convert MSTest to NUnit Test using rhino mocks

I am following this post to implement MVP Pattern. http://www.bradoncode.com/blog/2012/04/mvp-design-pattern-survival-kit.html

At the end of the article the testing is performed, which is performed in Microsoft Visual studio Test environment with Mock for Mocking the dependencies. In my project, I am using NUnit Test environment and RhinoMock for mocking depenecies.

In the article these are the test those are SetUp:

mockView.SetupSet(v => v.Products = It.Is<List<ProductItem>>(i => i.Count == 3))
        .Verifiable();
mockView.SetupSet(v => v.Total = It.Is<decimal>(t => t == 8.97m))
        .Verifiable();
mockView.SetupSet(v => v.SubTotal = It.Is<decimal>(t => t == 8.97m))
        .Verifiable();
mockView.SetupSet(v => v.Discount = It.Is<decimal>(t => t == 0m))
        .Verifiable();

I like to convert these lines to setup expectation and this is what I have tried:

_view = MockRepository.GenerateMock<IView>();
_controller = new Presenter(_view);            
_view.Expect(v => v.List = ???); //  List is my property defined in IView

NOTE:I am using NUnit and Rhino mocks for mocking.

Any help is really appreciated.

Upvotes: 1

Views: 102

Answers (1)

Old Fox
Old Fox

Reputation: 8725

The syntax of "fake object".Except --> Verify Exception is the old way to verify behavior.

Each line in your code snippet puts an expectation on a single property. The "newest" and the simplest way to do the equivalent verification is:(Put the following lines in the Assert section)

_view.AssertWasCalled(x => x.Products = Arg<IList<ProductItem>>
                            .Matches(list => list.Count == 3));
_view.AssertWasCalled(x => x.Total = 8.97m);
_view.AssertWasCalled(x => x.SubTotal = 8.97m);
_view.AssertWasCalled(x => x.Discount = 0m);

Upvotes: 1

Related Questions