What is the best way to automate MSMQ integration testing using Visual Studio Test Suite / NUnit?

I would like to create a series of automatic unit tests for the MSMQ application that I am writing. As I see it, the task is how to place event handlers from the testing method. That is, I am sending a message from a testing method and must return the result back to this testing method so that the message is received and processed. I have no idea how to do this, and any direction would be appreciated.

+3
source share
2 answers

Are you looking for a way to write unit tests in which the system under test believes that it accepts events from a queue, but do not want to use a real queue during tests?

Check out Rhino Mocks . It allows you to create a mock version of your queue interface, and then raise events from it during the test. Some pseudo-code for checking the Requester.DoSomething () method might look like this:

// SETUP
MockRepository mocks = new MockRepository();
IQueue mockQueue = mocks.StrictMock<IQueue>();

queue.Received+=null;//create an expectation that someone will subscribe to this event
LastCall.IgnoreArguments();// we don't care who is subscribing
IEventRaiser raiseReceivedEvent = LastCall.GetEventRaiser();//get event raiser for the last event, in this case, Received
Expect.Call(mockQueue.Send).Return(msgId);
mocks.ReplayAll();

// EXEC
Requester req = new Requester(mockQueue);

// We expect this method to send a request to the mock queue object.
req.DoSomething();
// Now we raise an event from the mock queue object.
raiseReceivedEvent.Raise(eventArgs);

// VERIFY
// we would probably also check some state in the Requester object
mocks.VerifyAll();

Check out the Rhino mocks wiki for all the details.

+1
source

unit test . MSMQ, . , , . . , .

, . , . (). , , , . , , .

+1

Source: https://habr.com/ru/post/1707802/


All Articles