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
+2 votes

Project type: Xamarin

Unit Test Framework: Nunit 3.6.1


I have my unit tests in a separate project. I am testing out a simple ViewModel with a single Property that is mocked. Not mocking the call and running in Resharper causes the error that I see in SmartRunner when the call is mocked. Very odd.

Here is my test class

 public readonly DependencyServiceStub _dependencyService = new DependencyServiceStub();

        public void OneTimeSetup()
            //Mock<Server> m = new Mock<Server>();
            //Isolate.NonPublic.StaticField<Server>("Instance").Value = new Server();

            var s = Isolate.Fake.AllInstances<Server>();
            Isolate.NonPublic.Property.WhenGetCalled(s, "NetworkCredential").WillReturn(new NetworkCredential());

        public void the_vm_should_spinup()
            var sut = new XmproLoginViewModel(_dependencyService);

When I bebug the test in SmartRunner the Server class I am mocking is actually getting its ctor called. But not when debugging the test with Resharpers Test Runner. The full property and  chain that I am mocking for is:


public static Server Instance // => _server ?? (_server = new Server());
                if (_server == null)
                    _server = new Server();
                return _server;

if (Server.Instance.NetworkCredential != null)

I tried mocking the return of .Instance specifically, but TM complained there was not a Property called "Instance", but .NetworkCredentials was fine.

Thanks for any ideas.


asked by adamhill (620 points)

Please log in or register to answer this question.