rhino-mocks

How to mock IDbSet with Rhino Mocks

帅比萌擦擦* 提交于 2019-12-13 04:08:42
问题 I can't get this working at all. I've got this code in my test: MockRepository repository = new MockRepository(); IDbSet<SystemUser> userSet = repository.StrictMock<IDbSet<SystemUser>>(); Expect.Call(userSet.Any(u => u.Id == "UserName")).Return(true); // More code follows But it bombs out on the StrictMock line with the error: System.TypeLoadException: Method 'Create' on type 'IDbSet`1Proxy1862178487664986a7bd03ad3b5c6f2c' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture

RhinoMocks - Raising event on mocked abstract class fails

我们两清 提交于 2019-12-12 21:22:27
问题 Does anyone know how I can raise an event on a abstract class? The test below fails on the last line. The exception I get is the following: System.InvalidOperationException : Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method). I am able to raise the event on an interface, but not on an abstract class that implements that interface. This is using the latest build of RhinoMocks (3.6.0.0). Thanks, Alex

How can I prevent virtual methods from being mocked?

旧城冷巷雨未停 提交于 2019-12-12 16:25:08
问题 We have a base class providing some default implementation for INotifyPropertyChanged (this class is used by many other classes and cannot be easily changed): public class ObservableBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; // this is virtual so derived classes can override it (rarely used, but it is used) protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) {

Arg<object>.Is.Equal with anonymous objects

此生再无相见时 提交于 2019-12-12 10:44:21
问题 In my MVC3 project, I use an IUrlProvider interface to wrap the UrlHelper class. In one of my controller actions, I have a call like this: string url = _urlProvider.Action("ValidateCode", new { code = "spam-and-eggs" }); I want to stub this method call in my unit test, which is in a separate project. The test setup looks something like this: IUrlProvider urlProvider = MockRepository.GenerateStub<IUrlProvider>(); urlProvider.Stub(u => u.Action( Arg<string>.Is.Equal("ValidateCode"), Arg<object>

How to mock the property which returns the list object - In rhino mock

馋奶兔 提交于 2019-12-12 09:45:59
问题 Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string> GetNames(IView view) { return view.Names; } } var mockView = MockRepository.GenerateMock<IView>(); var presenter = new Presenter(); var names = new List<string> {"Test", "Test1"}; mockView.Expect(v => v.Names).Return(names); Assert.AreEqual(names, presenter.GetNames(mockView)) // Here presenter returns null which is incorrect behaviour in my case; When I use the above code to return the mock list

Mocking DBSet, EF Model First

孤者浪人 提交于 2019-12-12 08:58:47
问题 As said in the title, I follow Model First method. So my Model classes are Automatically generated. If I want mock the DBContext derived MyModelContainer which contain DBSets of entity classes. Read some where that in order to unit test, you need to change it to IDBSet . Whether its possible to do it especially in a class that gets auto generated when I do "Run Custom Tool" is one concern. But as of now I modified it. But the real problem is: when I try to Stub MyModelContainer to return a

Invalid call, the last call has been used or no call has been made

霸气de小男生 提交于 2019-12-12 07:26:11
问题 I am getting this error when I try to set a mock to have PropertyBehavior() : System.InvalidOperationException: System.InvalidOperationException: Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).. I am trying to use only Rhino Mocks 3.5 (Arrange, Act, Assert) Here is my code: private IAddAddressForm form; private AddAddressMediator mediator; [TestInitialize()] public void MyTestInitialize() { form =

Mocking HttpContext to retrieve item form contexts item dictionary

时光毁灭记忆、已成空白 提交于 2019-12-12 03:59:54
问题 We use MVC3, for our unit tests we use RhinoMocks in our unit tests. When the a request starts we check the domain from which it came and match that to a customer. This customer is stored in the HttpContext.Items. Most controllers need this info to do their thing. var mocks = new MockRepository(); using (var controller = new TestController()) { HttpContext context = MockRepository.GenerateStub<HttpContext>(); Customer customer = new Customer { Key = "testKey" }; context.Items["Customer"] =

Correctly Unit Test Service / Repository Interaction

感情迁移 提交于 2019-12-11 18:29:26
问题 I have a method CreateAccount(...) that I want to unit test. Basically it creates an Account Entity and saves it to the DB, then returns the newly created Account. I am mocking the Repository and expecting an Insert(...) call. But the Insert method expects an Account object. This test passes, but it just does not seem correct, because CreateAccount creates an account, and I am creating an account for the Mock'ed expected call (two seperate Account instances). What would be the correct way to

How do you assert a generic method was called with Rhino Mocks?

三世轮回 提交于 2019-12-11 16:12:46
问题 I have the following test to verify that my repository is calling it's respective session (I've rewritten it to highlight the actual problem): [Test] public void Why_Does_This_Fail() { var objectUnderTest = new SomeGenericsProblem(); var fakeSession = MockRepository.GenerateMock<ISession>(); fakeSession.Expect(s => s.Query<SomeClass>()); objectUnderTest.NotWorking<SomeClass>(); fakeSession.AssertWasCalled(t => t.Query<SomeClass>()); } but when I run the test I get this: System