Re: [nsubstitute] Received.InOrder Feedback

75 views
Skip to first unread message

David Tchepak

unread,
Apr 22, 2013, 10:03:43 AM4/22/13
to nsubs...@googlegroups.com
Glad it's working for you Matt, and thanks for letting us know.

I'm keen to promote it to the main namespace (from experimental) -- the main thing holding me back is I want to make sure failed assertions are reported in a clear enough way (when calls are not received in the correct order). Have the assertion messages looked ok to you?


On Mon, Apr 22, 2013 at 11:58 PM, Matt Slavicek <matt.s...@gmail.com> wrote:
The Received.InOrder function is very nice.

Using it, this test:

        [TestMethodTestCategory("BVT")]
        public void TheFileIsEncryptedBeforeItIsSent()
        {
            const int encryptFunctionCallOrder = 1;
            const string encryptFunction = "encrypt";
            const int sentFunctionCallOrder = 2;
            const string sentFunction = "sent";
 
            var expectedFunctionCalls = new SortedList<intstring>
            {
                { encryptFunctionCallOrder, encryptFunction },
                { sentFunctionCallOrder, sentFunction },
            };
 
            var actualFunctionCalls = new SortedList<intstring>();
            MockFileEncrypter
                .When(x => x
                .Encrypt(Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>()))
                .Do(x => actualFunctionCalls.Add(encryptFunctionCallOrder, encryptFunction));
            MockFileTransferProxy
                .When(x => x
                .SendUpload(Arg.Any<string>()))
                .Do(x => actualFunctionCalls.Add(sentFunctionCallOrder, sentFunction));
 
            ExerciseSut();
 
            actualFunctionCalls
                .ShouldBeEquivalentTo(expectedFunctionCalls);
        }

Got collapsed down to:
        [TestMethodTestCategory("BVT")]
        public void TheFileIsEncryptedBeforeItIsSent()
        {
            ExerciseSut();
 
            Received.InOrder(() =>
            {
                MockFileEncrypter.Encrypt(Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>());
                MockFileTransferProxy.SendUpload(Arg.Any<string>());
            });
        }


It is much easier to pick out what the test is verifying. 


--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute...@googlegroups.com.
To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at http://groups.google.com/group/nsubstitute?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages