#22 using (mocks.Ordered) behaviour

closed-duplicate
nobody
None
5
2007-10-12
2007-06-20
Anonymous
No

Apologies if this is a feature not a bug!!!

If I run the following, where mockConnectionSettings.LoadSettings() is called and mockUserSettings.GetSettings() is not called, I get a failing test.

Expect.Once.On(mockConnectionSettings)
.Method("LoadSettings")
.WithNoArguments()
.Will(Throw.Exception
(new ConnectionSettingsNotStoredException()));
Expect.Once.On(mockUserSettings)
.Method("GetSettings")
.WithNoArguments()
.Will(Throw.Exception
(new ConnectionSettingsNotDefinedException()));.
mocks.VerifyAllExpectationsHaveBeenMet();

If I run the same code in a
"using (mocks.Ordered)" block, my test passes.

Is this a bug, or is there an excellent reason I don't know??? I can supply further info on request.

Regards

Rob
rob@settsoftware.co.uk

Discussion

  • Drew Noakes
    Drew Noakes
    2007-07-18

    Logged In: YES
    user_id=591973
    Originator: NO

    I'm seeing the same behaviour. The test incorrectly passes when specifing the order of expectations. A few of us looked over this and believe it's a bug in NMock. We're using version 1.0.2313.18049 (the current release candidate).

    As I can't find a link to attach a file, here's the code inline:

    <code>

    [TestFixture]
    public class RuleEngineServiceTest
    {
    private Mockery _mocks;

    [SetUp]
    protected void SetUp()
    {
    _mocks = new Mockery();
    }

    [TearDown]
    protected void TearDown()
    {
    _mocks.VerifyAllExpectationsHaveBeenMet();
    }

    [Test]
    public void ShouldLookInCacheForRuleSet()
    {
    string file = "foo.xml";
    IRuleSetCache cache = _mocks.NewMock<IRuleSetCache>();
    IRuleSetManager mgr = new RuleSetManager(cache);

    using (_mocks.Ordered)
    {
    Expect
    .Once
    .On(cache)
    .Method("Contains")
    .With(file)
    .Will(Return.Value(false));
    Expect
    .Once
    .On(cache)
    .Method("AddRuleSet");
    }
    IRuleSet ruleSet = mgr.CreateRuleSet(file);
    }
    }

    public class RuleSetManager : IRuleSetManager
    {
    private readonly IRuleSetCache _cache;

    public RuleSetManager(IRuleSetCache cache)
    {
    _cache = cache;
    }

    #region IRuleSetManager Members

    public IRuleSet CreateRuleSet(string file)
    {
    IRuleSet ruleSet = null;
    if (_cache.Contains(file))
    {
    ruleSet = _cache.GetRuleSet(file);
    }

    return ruleSet;
    }

    #endregion
    }

    public interface IRuleSetManager
    {
    IRuleSet CreateRuleSet(string file);
    }

    public interface IRuleSetCache
    {
    bool Contains(string key);
    IRuleSet GetRuleSet(string key);
    void AddRuleSet(string key, IRuleSet ruleSet);
    }

    public interface IRuleSet
    {
    }

    </code>

     
  • Logged In: YES
    user_id=591527
    Originator: NO

    I'm not sure why this bug hasn't been closed yet. This is fixed in cvs.

     
  • Steve Mitcham
    Steve Mitcham
    2007-10-12

    • status: open --> closed-duplicate
     
  • Steve Mitcham
    Steve Mitcham
    2007-10-12

    Logged In: YES
    user_id=1572889
    Originator: NO

    This is a duplicate of 1605557 which is fixed in CVS. We are starting a push to get a new 'official' release out the door soon.