chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi !!

I am using WCSF with CSLA.NET as business object layer.

Here is the scenario:

- CSLA provides me with ReadOnlyList
- WCSF controller accesses CSLA business object i.e. ReadonlyList
- WCSF presenter access method/property on a controller to get ReadOnlyList to set property on view.

How do I test and verify my view?

For e.g.

Sample CSLA Business Object

public class A : : ReadOnlyBase<A>
{
// Some Code to get item from database + other methods
}

public class AList : ReadOnlyListBase<AList, A>
{
// some code to get list from database + other methods
}

public class AController : IAController
{
public AList GetAList()
{
return AList.Get();
}
}

public class IAView
{
AList ListOfA { set; }
}

public class APresenter : Presenter<IAView>
{
private IAController _controller;

public APresenter([CreateNew] IAController controller)
{
_controller = controller;
}

public override void OnViewInitialized()
{
View.ListOfA = _controller.GetAList();
}
}

Now as far as Testing scenario is concerned:

Scenario 1:

View.ListOfA is null

Scenario 2:
View.ListOfA is not Null
View.ListOfA count > 0

In order to do this I have to mock controller + csla object
I have to return mock readonly collection

This is where I am haing issues.

Help appreciated.
asked by tshah (1.2k points)

1 Answer

0 votes
Hi
I hope I understands you correctly so please fix if I'm wrong :shock:

For Scenario 1 View.ListOfA is null:
We need to path mocked IAController object to the APresenter class
and set IAController.GetAList method to return null
Example:
[TestMethod]
public void TestListOfAIsNull()
{
    IAController controller = (IAController)RecorderManager.CreateMockedObject(typeof(IAController));

    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        recorder.ExpectAndReturn(controller.GetAList(), null);
    }

    APresenter aPresenter = new APresenter(controller);
    //call expectations here ...            
}


For Scenario 2 View.ListOfA is not null and count > 0:
Similar to the test before but now set GetAList method to return a list
Example
[TestMethod]
public void TestListOfAIsNotNull()
{
    AList retList = new AList();
    //retList.Add() ...

    IAController controller = (IAController)RecorderManager.CreateMockedObject(typeof(IAController));

    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        recorder.ExpectAndReturn(controller.GetAList(), retList);
    }

    APresenter aPresenter = new APresenter(controller);
   //call expectation here ...
}
answered by ohad (35.4k points)
...