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

  • SEARCH
  • Home
  • 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 8767119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:43:42+00:00 2026-06-13T16:43:42+00:00

I have an interface that looks like this… public interface ITempFileNameBuilder { string DirectoryPath

  • 0

I have an interface that looks like this…

public interface ITempFileNameBuilder
{
    string DirectoryPath { get; }

    string FileName { get; }

    void GenerateNewFileName();
}

… and I want to mock the GenerateNewFileName method so that it sets the FileName property to something new. I know this is an odd request because obviously there is no set defined in the interface because it’s declared as private set; in the two implementations. I did that so you must call GenerateNewFileName to set the FileName property to something new.

Is this possible?

Edit

Here is the unit of work I’m trying to test.

public void StartRecording(string claimNo, string ip_no, string ip_name, IWaveIn input, Stream writer)
{
    if (this.IsRecording)
    {
        return;
    }

    if (_input != null)
    {
        _input.Dispose();
    }
    _input = input;

    _input.WaveFormat = _waveFormat;
    _input.DataAvailable += (s, args) =>
    {
        _writer.Write(args.Buffer, 0, args.BytesRecorded);
        byte[] buffer = args.Buffer;
        for (int index = 0; index < args.BytesRecorded; index += 2)
        {
            short sample = (short)((buffer[index + 1] << 8) | buffer[index + 0]);
            float sample32 = sample / 32768f;
            _aggregator.Add(sample32);
        }

        OnDataAvailable(args);
    };
    _input.RecordingStopped += (s, args) =>
    {
        _input.Dispose();
        _writer.Dispose();

        OnRecordingStopped(args);
    };

    if (this.CurrentRecording != null)
    {
        _tempFileNameBuilder.GenerateNewFileName();
    }

    this.Recordings.Add(new RecordingTrack(claimNo, ip_no, ip_name,
        _tempFileNameBuilder.FileName,
        _recordingDeployer,
        _recordingCompressor));
    if (this.MicrophoneLevel == default(float))
    {
        this.MicrophoneLevel = .75f;
    }

    _aggregator.Reset();
    _writer = writer;

    _input.StartRecording();
    this.IsRecording = true;
}

And the goal of this unit test is to ensure that the FileName of the CurrentRecording and LastRecording are in fact different. It’s a regression test based on a bug we found earlier. The bug was happening because the FileName property on the RecordingTrack was not being set but rather was just returning the current FileName from the ITempFileNameBuilder instance and so the idea is to ensure that GenerateNewFileName was called and ensure that the set for the TempFileName on the recording track was called.

However, the set on the TempFileName on the RecordingTrack is private too, it’s done in the constructor, so maybe this isn’t really a unit test and more so an integration test?

  • 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-13T16:43:43+00:00Added an answer on June 13, 2026 at 4:43 pm

    You’re mocking the interface, not the implementation. So you should care about how the caller interacts with this. If you expect them to call GenerateNewFileName() and then access FileName, just expect those two calls and give back the appropriate results (where the “generated” filename can just be anything).

    There’s no “field” to set here – you’re just talking about an API.

    Of course, you could easily create a fake instead of a mock, and use that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that looks like this: public interface IEntity { int Id
i have a sub that looks like this: Sub open_esy(filename, p As String, p1
Imagine I have a service that looks like this: public interface MyAccountService { boolean
I have a service contract interface that looks like this: [ServiceKnownType(typeof(GeometricModelDescriptor))] [ServiceKnownType(typeof(TemplateModelDescriptor))] [ServiceContract] public
I have a C interface that looks like this (simplified): extern bool Operation(void **
I have a generic PostProcessor interface that looks like this: public interface PostProcessor<T> {
Here goes: I have a view that looks like this: public interface IAddressView {
I have an interface implemented in Host class that looks like this: void Method1(Action<Args1>
I have an interface that includes a member that looks like: void ExecuteSqlCommand(string procedureName,
Let's say I have a service interface that looks like this: public interface IFooService

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.