rhino-mocks

Is there an in-memory provider for Entity Framework?

夙愿已清 提交于 2019-11-27 21:48:29
I am unit testing code written against the ADO .NET Entity Framework. I would like to populate an in-memory database with rows, and make sure that my code retrieves them properly. I can mock the Entity Framework using Rhino Mocks, but that would not be sufficient. I would be telling the query what entities to return to me. This would neither test the where clause nor the .Include() statements. I want to be sure that my where clause matches only the rows I intend, and no others. I want to be sure that I have asked for the entities that I need, and none that I don't. For example: class

RhinoMock vs. TypeMock vs. NUnit's Mocking?

空扰寡人 提交于 2019-11-27 20:08:51
I am just starting to do Test Driven Development, and I am wondering the major differences between RhinoMock, TypeMock, and NUnit's built-in mocking? Any information would be greatly appreciated! TypeMock is a commercial product (meaning you'll have to pay for it) but will allow you to mock concrete objects - unlike RhinoMocks/NUnit/MoQ which can only mock an interface/abstract class. How it achieves this is borderline black magic, but it does some very clever things with the CLR. This can be particularly useful when you use libraries in your project that don't use many interfaces. So you

How to avoid HttpContext.Server.MapPath for Unit Testing Purposes

守給你的承諾、 提交于 2019-11-27 16:22:28
I am working in an ASP.net MVC 5 application. I would like to Unit Test my controller action which looks like this public ActionResult Search() { var vm = SetupSearchViewModel(); return View(vm); } All the hard work is done by the SetupSearchViewModel() method, which itself is an orchestrator calling many different other methods, one of which is this private string ExtractJsonFile(string filename) { var filePath = HttpContext.Server.MapPath(filename); var json = System.IO.File.ReadAllText(filePath); return json; } I plan on doing many Unit Tests on this particular action, but I'm starting with

How to change behaviour of stubs?

偶尔善良 提交于 2019-11-27 15:51:19
问题 Can I change the behaviour of a stub during runtime? Something like: public interface IFoo { string GetBar(); } [TestMethod] public void TestRhino() { var fi = MockRepository.GenerateStub<IFoo>(); fi.Stub(x => x.GetBar()).Return("A"); Assert.AreEqual("A", fi.GetBar()); fi.Stub(x => x.GetBar()).Return("B"); Assert.AreEqual("B", fi.GetBar()); // Currently fails here } My code example still fails in the given line, fi.GetBar() still returns "A" . Or is there another trick to model stubs whose

Mocking and HttpContextBase.get_User()

自古美人都是妖i 提交于 2019-11-27 13:49:57
I want to mock the User property of an HttpContext. I'm using Scott Hanselmans MVCHelper class and RhinoMocks. I have a unit test that contains code, like this: ... MockIdentity fakeId = new MockIdentity("TEST_USER", "Windows", true); MockPrincipal fakeUser = new MockPrincipal(null, fakeId); using (mocks.Record()) { Expect.Call(fakeHttpContext.User).Return(fakeUser); } ... My MockIdentity and MockPrincipal classes are mocks conforming to IIdentity and IPrincipal, respectively. I get an error when running the unit test that reports: System.NotImplementedException : The method or operation is

What is the difference between Version and 'Runtime Version' in .Net?

删除回忆录丶 提交于 2019-11-27 13:24:50
问题 When I open the properties window of one of the referenced dlls in my project in Visual Studio I see a Version and also a runtime version . Actually it is Rhino.Mocks library I am checking. And I see Runtime Version : v2.0.50727 Version : 3.6.0.0 What is the difference? (Does it mean I am not able to use 3.6.0.0 of the Rhino Mocks?) 回答1: Runtime is the version of the CLR (or .NET framework) the DLL needs (usually as a minimum), version is the DLL's version. So long as you have the minimum

Rhino Mocks - Difference between GenerateStub<T> & GenerateMock<T> [closed]

帅比萌擦擦* 提交于 2019-11-27 11:40:34
Can any of the Rhino experts explain me by giving a suitable example of the difference between the above methods on the MockRepository class (Rhino Mocks framework). Where should one use Stub over Mock method or otherwise? Sam Holder you should use a mock when you are going to verify that something happened on the object, like a method was called. You should use a stub when you just want the object to be involved in the test to return a value but it is not the thing you are testing. A stub which does not have a expectation fulfilled can never fail a test. I think the general rule should be

Mocking a DataReader and getting a Rhino.Mocks.Exceptions.ExpectationViolationException: IDisposable.Dispose(); Expected #0, Actual #1

久未见 提交于 2019-11-27 06:50:16
问题 I'm trying to mock a SqlDataReader SqlDataReader reader = mocks.CreateMock<SqlDataReader>(); Expect.Call(reader.Read()).Return(true).Repeat.Times(1); Expect.Call(reader.Read()).Return(false); Expect.Call(reader.HasRows).Return(true); Expect.Call(reader.Dispose); Expect.Call(reader["City"]).Return("Boise"); Expect.Call(reader["State"]).Return("State"); Expect.Call(reader["LAT"]).Return(100); Expect.Call(reader["LON"]).Return(-100); mocks.ReplayAll(); but I keep getting a Rhino.Mocks.Exceptions

What are the real-world pros and cons of each of the major mocking frameworks?

冷暖自知 提交于 2019-11-27 04:15:45
问题 see also "What should I consider when choosing a mocking framework for .Net" I'm trying to decide on a mocking framework to use on a .NET project I've recently embarked on. I'd like to speed my research on the different frameworks. I've recently read this blog post http://codevanced.net/post/Mocking-frameworks-comparison.aspx and wondered if any of the StackOverflow audience has anything to add in the way of real-world advantages and caveats to the frameworks. Could people could list the pros

Mocking Static methods using Rhino.Mocks

强颜欢笑 提交于 2019-11-27 01:39:44
Is it possible to mock a static method using Rhino.Mocks? If Rhino does not support this, is there a pattern or something which would let me accomplish the same? Is it possible to mock a static method using Rhino.Mocks No, it is not possible. TypeMock can do this because it utilizes the CLR profiler to intercept and redirect calls. RhinoMocks, NMock, and Moq cannot do this because these libraries are simpler; they don't use the CLR profiler APIs. They are simpler in that they use proxies to intercept virtual members and interface calls. The downside of this simplicity is that they cannot mock