Moq Dependency?

Dec 7, 2009 at 1:54 AM

Would it be true to say that WcfMock has a dependency on the MOQ test framework?

I use rhino, and I have yet to be able to get WcfMock to work with Rhino mock.

Dec 7, 2009 at 2:14 AM

Actually, I just learned that this framework works just fine with Rhino mock.  I was setting up my stubs incorrectly.

Imagine that you have a service operation that looks like this...

public void CreateTags(CreateTagsData tagData, string systemObjectId, string recordId) {
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Accepted;

Now you can write unit tests like this, using Rhino mock

public void Test_HttpStatusCode_IsSetToAccepted() {
    ITagDataProvider dataProvider = MockRepository.GenerateStub<ITagDataProvider>();
    TagService svc = new TagService(dataProvider);
// I guess that MOQ sets up these instatnces for us, however in Rhino Mock, I have to manage this myself... no worries
    IWebOperationContext current = MockRepository.GenerateStub<IWebOperationContext>();
    IOutgoingWebResponseContext outgoingResponse = MockRepository.GenerateStub<IOutgoingWebResponseContext>();
    current.Stub(it => it.OutgoingResponse).Return(outgoingResponse);

    using (new MockedWebOperationContext(current)) {
        svc.CreateTags(null, string.Empty, string.Empty);

    Assert.AreEqual(HttpStatusCode.Accepted, current.OutgoingResponse.StatusCode);

Thanks for the code.  It should be a big help.