0

Good day! I need your help, I have next tests:

    [SetUp]
    public void SetUp()
    {
        controller = Substitute.For<IApplicationController>();
        view = Substitute.For<ICamerasView>();
        presenter = new CamerasPresenter(controller, view);
        argument = InitializeDevicesList();
        presenter.Run(argument);
    }

    private List<string> InitializeDevicesList()
    {
        List<string> devicesList = new List<string>();
        Device device = new Device();

        devicesList.Add(device.Name);

        return devicesList;
    }

    [Test]
    public void RunIfDeviceListIsNotEmpty()
    {
        view.DidNotReceive().SetUIOnNoConnectedDevices();
        view.Received().FillCamerasListView(argument);
        view.Received().Show();

    }

which actually tests next code

    public override void Run(List<string> argument)
    {
        connectedCameras = argument;
        if(connectedCameras.Count == 0)
        {
            SetUIOnNoConnectedDevices();
        }
        else
        {
            FillCamerasListView();
        }
        View.Show();
    }

And my issue is that FillCamerasListView method isn't calling in test. But as it expected it called in Run method in this case. So, I can't imagine what is the problem, so I will be very appreciated for your help. Thanks for your time!

Crispried
  • 99
  • 3
  • 11
  • Does ` FillCamerasListView()` call `view.FillCamerasListView(connectedCameras)`? What is the assertion exception you are getting? – David Tchepak Oct 26 '16 at 06:07
  • Ye, sure. SetUIOnNoConnectedDevices and FillCamerasListView which I call in presenter are just a simple wrappers on view.FillCamerasListView and view.SetUIOnNoConnectedDevices. I'm getting exception on this string view.Received().FillCamerasListView(argument); in test. – Crispried Oct 26 '16 at 07:14
  • Exception error: An exception of type 'NSubstitute.Exceptions.ReceivedCallsException' occurred in NSubstitute.dll but was not handled in user code Additional information: Expected to receive a call matching: FillCamerasListView(List) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): FillCamerasListView(*List*) – Crispried Oct 26 '16 at 07:16
  • It looks like wrapper is modifying the argument passed to FillCamerasListView. Can you post that wrapper? – David Tchepak Oct 26 '16 at 07:38
  • Sure, but there aren't any modifications. http://pastebin.com/N2UZ1gQp – Crispried Oct 26 '16 at 09:22
  • `connectedCameras.GetCameraNames`? I think the problem is the view is called with a different argument. You can try `ReceivedWithAnyArgs` or `Arg.Is` with a condition that inspects the argument for the properties you need. – David Tchepak Oct 26 '16 at 09:28
  • Somewhy it helps, thank you. But it's very strange for me, coz argument which I pass in view is just a property of argument, which I pass in presenter. It's mistery for me. – Crispried Oct 26 '16 at 11:02

1 Answers1

0

This example passes. The problem appears to be something in your example that is changing the argument passed to FillCamerasListView as discussed in the comments.

A few options:

  1. Modify the code to match the test's expectation. i.e. pass the argument given to Run on to FillCamerasListView.
  2. Use view.ReceivedWithAnyArgs().FillCamerasListView(null) to assert a call was made without worry about the specifics of the argument passed.
  3. Use view.Received().FillCamerasListView(Arg.Is<List<string>>(x => Matches(x, argument)), where Matches is your own code which determines whether the argument given is correct based on the argument passed to Run.
David Tchepak
  • 9,826
  • 2
  • 56
  • 68