mercredi 27 juillet 2016

What is the NSubstitute equivalent of RHino Mocks Is.Anything

I have a load of tests written by another developer in Rhino Mocks. We now use NSubstitute though so I am re-writting the tests in NSubstitute. I have re-written eveything except the Is.Anything. What is the NSubstitute way of writting the Is.Anything in the below example? I have shown the Rhino Mocks first and the NSubstitute examle second.

Rhino Mocks:

using Rhino.Mocks;

namespace ClassUnderTest.Tests
{
    class TestExample_NSubstitute_Tests
    {
        private const int ClassUnderTestLicenseFeatureID = 5106;
        private IMessenger messageProvider;
        private IEventAggregator eventAggregator;

        private ClassUnderTest BuildValidClassUnderTestObject()
        {
            ClassUnderTest newClassUnderTest = new ClassUnderTest(
                    eventAggregator,
                    messageProvider);
            return newClassUnderTest;
        }

        [TestMethod]
        public void ClassUnderTestBroadcastInstrumentState_NoArgs_BaseClassMethodCall()
        {
            //ARRANGE
            ClassUnderTest classUnderTest = BuildValidClassUnderTestObject();

            //ACT
            classUnderTest.BroadcastState();

            //ASSERT
            messageProvider.AssertWasCalled(a => a.ClassToDoWork(
                Arg<OrchestrationInstrumentRuntimeServiceModel>.Is.Anything, 
                Arg<long>.Is.Anything));
            Assert.IsNotNull(classUnderTest);
        }
    }
}

NSubstitute Example:

using NSubstitute;

namespace ClassUnderTest.Tests
{
    class TestExample_NSubstitute_Tests
    {
        private const int ClassUnderTestLicenseFeatureID = 5106;
        private IMessenger messageProvider;
        private IEventAggregator eventAggregator;

        private ClassUnderTest BuildValidClassUnderTestObject()
        {
            ClassUnderTest newClassUnderTest = new ClassUnderTest(
                    eventAggregator,
                    messageProvider);
            return newClassUnderTest;
        }

        [TestMethod]
        public void ClassUnderTestBroadcastInstrumentState_NoArgs_BaseClassMethodCall()
        {
            //ARRANGE
            ClassUnderTest classUnderTest = BuildValidClassUnderTestObject();

            //ACT
            classUnderTest.BroadcastState();

            //ASSERT
            messageProvider.Received().ClassToDoWork(
                Arg<OrchestrationInstrumentRuntimeServiceModel>.Is.Anything,//How do I re-write Is.Anything in NSubstitute?
                Arg<long>.Is.Anything);//How do I re-write Is.Anything in NSubstitute?
            Assert.IsNotNull(classUnderTest);
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire