your mock IModelManager looks like it is never assigned to ModelManager.Instance, so your mock will never be hit. You either need to change your ModelManager so you can provide the singleton instance or change SomeClass so that it's dependency on an IModelManager can be provided.
2009/11/11 paparata <[email protected]> > > I am encountering an issue using Rhino Mocks which I hope you can > advise me on please. I have tried to demonstarte in the attached > solution in VS2005 C# > > The method that I wish to test is someClass.MethodToTest(). This > method calls ModelManager.Instance.GetModels().GetEntity() so I have > tried to create a Dynamic mock object to mock the response from this > method. I have been unsuccessful and ask for your advise please. An > exception is raised when I call Expect.Call > > Thank you > > Source code is as follows > > using System; > using NUnit.Framework; > using Rhino.Mocks; > > namespace RhinoMocksTester > { > public class AnEntity > { > private int m_id; > > public int Id > { > get { return m_id;} > } > > public AnEntity(int id) > { > m_id = id; > } > } > > public interface IModel > { > AnEntity GetEntity(); > } > > public interface IModelManager > { > IModel GetModels(); > } > > public class Model : IModel > { > public AnEntity GetEntity() > { > return new AnEntity(5); > } > } > > public class ModelManager : IModelManager > { > private static Model m_Models; > private static ModelManager m_modelManager = new ModelManager > (); > > private ModelManager() > { > } > > public static ModelManager Instance > { > get > { > return m_modelManager; > } > } > > public IModel GetModels() > { > if (m_Models == null) > m_Models = new Model(); > > return m_Models; > } > } > > public class SomeClass : IDisposable > { > private AnEntity m_anEntity; > > public int Id > { > get { return m_anEntity.Id; } > } > > public void MethodToTest() > { > m_anEntity = ModelManager.Instance.GetModels().GetEntity > (); > } > > public void Dispose() > { > > } > } > > [TestFixture] > public class Tests > { > [Test] > public void LookupEntityTest() > { > MockRepository mocks = new MockRepository(); > // Create a dynamic mock object to process interaction > with the ModelManager interface > IModelManager mm = mocks.DynamicMock<IModelManager>(); > // Create an entity to return when > ModelManager.Instance.GetModel().GetEntity() is called > AnEntity anEntity = new AnEntity(6); > > Expect.Call(mm.GetModels().GetEntity()).Return > (anEntity).IgnoreArguments(); > > mocks.ReplayAll(); > > // Execute the test method > SomeClass someClass = new SomeClass(); > someClass.MethodToTest(); > Assert.AreEqual(6,someClass.Id); > } > } > } > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en -~----------~----~----~----~------~----~------~--~---
