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 7168549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:48:10+00:00 2026-05-28T14:48:10+00:00

I have a device that needs to be mocked. Depending on the last set

  • 0

I have a device that needs to be mocked. Depending on the last set value a statusflag on the device changes. I need to mock this behaviour.

Here is some pseudocode that does not work:

private delegate void setvalue(Value val);
...
Value lower = new Value(1);
Value higher = new Value(7);
ISweetInterface mock = setupSweetInterface();
Boolean flagreturn = false;
mock.Expect(x => x.Lower).Return(lower);
mock.Expect(x => x.SetValue(lower))
    .Do(new setvalue(delegate(Value val) { flagreturn = true; }));
mock.Expect(x => x.SetValue(higher))
    .Do(new setvalue(delegate(Value val) { flagreturn = false; }));

mock.Expect(x => x.CheckFlag()).Return(flagreturn);

Mockuser tested = new Mockuser(mock)
Assert.IsTrue(tested.setLowerAndCheckFlag());
Assert.IsFalse(tested.setHigherAndCheckFlag());

Depending on the last set value the flag on the device has to change. I think my delegate actually can not see the flagreturn. The Code i wrote compiles but CheckFlag() always returns false.

How can i properly express this coupled behaviour.

  • 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-05-28T14:48:11+00:00Added an answer on May 28, 2026 at 2:48 pm

    I got it to work with the assistance of another object that keeps track for me. One of the cornerstones is to invoke the new object with DO rather than just trying to return one of its properties.

    Here is some pseudocode to illustrate:

        private class mockdevice
        {
            public List<Value> listOfTrueReturn = new List<Value>();
            private Boolean flagvalue = false;
            public bool flag()
            {
                    return flagvalue;
            }
            public void setvalue(Value val)
            {
                if (listOfTrueReturn.Contains(val))
                {
                    flagvalue = true;
                }
                else
                {
                    flagvalue = false;
                }
            }
        }
    
    
        private delegate void setvalue(Value val);
        private delegate Boolean getflag();
    
        [Test]
        public void shouldAnswerStackoverflowQuestion()
        {
            float d = 5f;
            Value lower = new Value(-d, 0f, unit);
            Value higher = new Value(d, 0f, unit);
            mockdevice md = new mockdevice();
            md.listOfTrueReturn.Add(higher);
    
            IFindFlagDataObject mock = setupmock();
            mock.Expect(x => x.Lower).Return(lower);
            mock.Expect(x => x.Higher).Return(higher);
            mock.Expect(x => x.CheckFlag()).Do(new getflag(md.flag)).Repeat.Times(2);
            mock.Expect(x => x.SetValue(Arg<Value>.Is.Anything)).Do(new setvalue(md.setvalue)).Repeat.Times(2);
    
            FindFlagStrategy tested = new FindFlagStrategy(mock);
            tested.FindFlagValue();
    
            mock.VerifyAllExpectations();
            Mockuser tested = new Mockuser(mock)
            Assert.IsTrue(tested.setLowerAndCheckFlag());
            Assert.IsFalse(tested.setHigherAndCheckFlag());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that needs to constantly ping a device However this ping
We have an embedded device that needs to interact with an enterprise software system.
I have a PCI device that needs to read and write from userspace. I'm
I have a device driver that uses the following algorithm to convert a value
I have a decent sized set of data that needs to be stored in
I have make an application. In this application client need that when user download
I have a gui that needs to be updated from a hardware device attached
I have an ASP.NET application designed for a Windows CE device that needs to
I have a device that supports 4-color graphics (much like CGA in the old
We have a device that uses Exchange web services to download mail and calendar

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.