gilesrpa
gilesrpa

Reputation: 1061

JustMock Arrange Not Working

Ok,

Just got my licence for JustMock and it looks great. I am having an issue with Arranging my first MVC controller test thou.

My test method looks as follows:

    [TestMethod]
    public void Option_Detail_Test_JustMock()
    {

        // Arrange
        var id = 7;

        var services = Telerik.JustMock.Mock.Create<IServiceResolver>();
        var landService = Telerik.JustMock.Mock.Create<ILandService>();

        var requestGet = DataHelper.Object1();
        var requestLand = DataHelper.Object2(requestGet);

        Telerik.JustMock.Mock.Arrange(() => landService.Get(Arg.AnyInt)).Returns(requestGet);
        Telerik.JustMock.Mock.Arrange(() => _mapper.Map<LandOptionItemViewModel>(Arg.AnyObject)).Returns(requestLand);


        var controller =  new LandController(services);


        // Act
        ActionResult result = controller.Option(id);

        // Assert
        Assert.IsNotNull(result);

    }

The DataHelper class just builds me some data structures, an example:

public static class DataHelper
{

    public static FirstDataContract Object1()
    {

        return new FirstDataContract() {
            Agreements = null,
            Areas = (new FirstAreaDataContract[]
            {
                new FirstAreaDataContract
                {
                    Id = 1,
                    LandRightsTypeCode = "ABC",
                    LandTransactionTypeCode = "123",
                    NetAmount = 10
                },
                new FirstAreaDataContract
                {
                    Id = 2,
                    LandRightsTypeCode = "XYZ",
                    LandTransactionTypeCode = "456",
                    NetAmount = 50
                }
            }).ToList();
     }

This all appears to work fine. the Mock.Create's are called, the DataHelper populates the two request variables and both Mock.Arrange statements do not error.

When I call the controller method Option, code snippet:

public ActionResult Option(int id)
{
    var parcel = _landService.Get(id);
    ...
    ...
}

I was expecting JustMock to set the parcel object to the mocked object created above. Is this what I should expect?

What I get is an instantiated object with no data.

Upvotes: 0

Views: 927

Answers (0)

Related Questions