Verifying a specific parameter with Moq

public void SubmitMessagesToQueue_OneMessage_SubmitSuccessfully() { var messageServiceClientMock = new Mock<IMessageServiceClient>(); var queueableMessage = CreateSingleQueueableMessage(); var message = queueableMessage[0]; var xml = QueueableMessageAsXml(queueableMessage); messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(xml)).Verifiable(); //messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(It.IsAny<XmlElement>())).Verifiable(); var serviceProxyFactoryStub = new Mock<IMessageServiceClientFactory>(); serviceProxyFactoryStub.Setup(proxyFactory => proxyFactory.CreateProxy()).Returns(essageServiceClientMock.Object); var loggerStub = new Mock<ILogger>(); var client = new MessageClient(serviceProxyFactoryStub.Object, loggerStub.Object); client.SubmitMessagesToQueue(new List<IMessageRequestDTO> {message}); //messageServiceClientMock.Verify(proxy => proxy.SubmitMessage(xml), Times.Once()); messageServiceClientMock.Verify(); } … Read more

NUnit vs. Visual Studio 2008’s test projects for unit testing [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more

How do I use Assert.Throws to assert the type of the exception?

How do I use Assert.Throws to assert the type of the exception and the actual message wording? Something like this: Assert.Throws<Exception>( ()=>user.MakeUserActive()).WithMessage(“Actual exception message”) The method I am testing throws multiple messages of the same type, with different messages, and I need a way to test that the correct message is thrown depending on the … Read more

Different return values the first and second time with Moq

I have a test like this: [TestCase(“~/page/myaction”)] public void Page_With_Custom_Action(string path) { // Arrange var pathData = new Mock<IPathData>(); var pageModel = new Mock<IPageModel>(); var repository = new Mock<IPageRepository>(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); container.Setup(x => x.GetInstance<IPageRepository>()).Returns(repository.Object); repository.Setup(x => x.GetPageByUrl<IPageModel>(path)).Returns(() => pageModel.Object); pathData.Setup(x => x.Action).Returns(“myaction”); pathData.Setup(x => x.Controller).Returns(“page”); var resolver … Read more

NUnit vs. MbUnit vs. MSTest vs. xUnit.net [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more