Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:40:27+00:00 2026-06-18T00:40:27+00:00

I have two interfaces called ITweetReq and ITweetResp . An outside service sends Requests

  • 0

I have two interfaces called ITweetReq and ITweetResp.

An outside service sends Requests to send tweets when they come in, which is implemented by the interface ITweetReq and our system in return sends the reply back which is implemented in ITweetResp interface.

Both the incoming and outgoing messages are logged in a file. I have to unit test the log file to make sure it is logging the correct number of message received and replied.

I am wondering if I should mock both the interfaces then do a test on the log file, but not sure how to go about it. Any help or suggestion will be appreciated.

I am using NUnit and Moq Framework.

   var TweetReq = new Mock<ITweetReq>();
   var TweetRes = new Mock<ITweetRes>();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:40:29+00:00Added an answer on June 18, 2026 at 12:40 am

    You seem a little confused as to what mocking/unit testing is.
    Mocks are typically created for anything ‘outside’ of the class being tested.
    Unit tests are run on your code (typically a method, or part of it).

    You should write unit tests for the class which does the logging, by calling the methods which receive/reply to tweets with the mocked objects, and testing for the expected result.

    It might be better if you mocked your logging class too, as testing files directly can become complicated and is not recommended.

    For example, you might have these methods on your class.

    public class TweetHandler
    {
        public void Main()
        {
            ILogger logger = GetLogger();
    
            while (true)
            {
                ITweetReq request = GetNextRequest();
    
                ITweetRes response = HandleRequest(request, logger);
    
                SendResponse(response, logger);
            }
        }
    
        public ITweetRes HandleRequest(ITweetReq request, ILogger logger)
        {
            int id = request.Id;
            string text = request.Text;
    
            logger.Log("Received tweet " + id + " with text: " + text);
    
            return new TweetResponse(id, text);
        }
    
        public void SendResponse(ITweetRes response, ILogger logger)
        {
            logger.Log("Sending response to tweet: " + response.Id);
            Response(reponse);
        }
    }
    

    You can then write unit tests like this:

    [TestMethod]
    public void HandleRequest_ShouldLogIdAndText()
    {
        // Arrange
        var handler = new TweetHandler();
        var mockRequest = new Mock<ITweetReq>();
        var mockLogger = new Mock<ILogger>();
    
        mockRequest.Setup(x => x.Id).Returns(10);
        mockRequest.Setup(x => x.Text).Returns("some text");
    
        // Act
        handler.HandleRequest(mockRequest, mockLogger);
    
        // Assert
        mockLogger.Verify(x => x.Log("Received tweet 10 with text: some text"));
    }
    
    [TestMethod]
    public void SendResponse_ShouldLogId()
    {
        // Arrange
        var handler = new TweetHandler();
        var mockResponse = new Mock<ITweetRes>();
        var mockLogger = new Mock<ILogger>();
    
        mockResponse.Setup(x => x.Id).Returns(20);
    
        // Act
        handler.SendReponse(mockResponse, mockLogger);
    
        // Assert
        mockLogger.Verify(x => x.Log("Sending response to tweet: 20"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a concrete singleton service which implements Ninject.IInitializable and 2 interfaces. Problem is
I need advice on interfaces. I have a class called Unit which can attack
I have two questions 1) my interface i have interface called IRegister and within
I have two interfaces IHeaderRow , and IDetailRow I then have an object that
I have two interfaces A and B and B is extending A. I have
I have two entities Visita and Cliente that implements respectively two interfaces IVisita and
Lets say I have two interfaces interface A and interface B: public interface A
If I have two interfaces , both quite different in their purposes , but
I have two network interfaces on my Solaris machine and the output of ifconfig
I have two Java interfaces and one implementing class. (I have used Eclipse to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.