rhino-mocks

Rhino Mocks - Stub .Expect vs .AssertWasCalled

北慕城南 提交于 2019-11-27 00:22:08
问题 OK, I know there has been a lot of confusion over the new AAA syntax in Rhino Mocks, but I have to be honest, from what I have seen so far, I like. It reads better, and saves on some keystrokes. Basically, I am testing a ListController which is going to basically be in charge of some lists of things :) I have created an interface which will eventually become the DAL, and this is of course being stubbed for now. I had the following code: ( manager is the system under test, data is the stubbed

Best Practices of Test Driven Development Using C# and RhinoMocks [closed]

假如想象 提交于 2019-11-26 23:45:14
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In order to help my team write testable code, I came up with this simple list of best practices for making our C# code base more

RhinoMock vs. TypeMock vs. NUnit's Mocking?

一世执手 提交于 2019-11-26 22:53:48
问题 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! 回答1: 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

Is there an in-memory provider for Entity Framework?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 20:47:40
问题 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

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

给你一囗甜甜゛ 提交于 2019-11-26 18:37:01
问题 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

What are the differences between mocks and stubs on Rhino Mocks?

有些话、适合烂在心里 提交于 2019-11-26 16:59:17
I haven't play enough with this and usually use mocks, but I wonder what are the differences between this two and when to use one or the other on Rhino Mocks. Update: I also found the answer to my question in Ayende's words : The difference between stubs and mocks You can get the actual definition of the these terms in this article: Mocks Aren't Stubs . I want to focus on the difference from the point of view of Rhino Mocks. A mock is an object that we can set expectations on, and which will verify that the expected actions have indeed occurred. A stub is an object that you use in order to

Mocking and HttpContextBase.get_User()

社会主义新天地 提交于 2019-11-26 16:32:40
问题 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

Mocking Asp.net-mvc Controller Context

不打扰是莪最后的温柔 提交于 2019-11-26 15:05:13
So the controller context depends on some asp.net internals. What are some ways to cleanly mock these up for unit tests? Seems like its very easy to clog up tests with tons of setup when I only need, for example, Request.HttpMethod to return "GET". I've seen some examples/helpers out on the nets, but some are dated. Figured this would be a good place to keep the latest and greatest. I'm using latest version of rhino mocks Haacked Using MoQ it looks something like this: var request = new Mock<HttpRequestBase>(); request.Expect(r => r.HttpMethod).Returns("GET"); var mockHttpContext = new Mock

How to mock the Request on Controller in ASP.Net MVC?

懵懂的女人 提交于 2019-11-26 14:07:36
I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{ public ActionResult Index() { if (Request.IsAjaxRequest()) { //do some ajaxy stuff } return View("Index"); } } I got some tips on mocking and was hoping to test the code with the following and RhinoMocks var mocks = new MockRepository(); var mockedhttpContext = mocks.DynamicMock<HttpContextBase>(); var mockedHttpRequest = mocks.DynamicMock<HttpRequestBase>(); SetupResult.For(mockedhttpContext.Request).Return(mockedHttpRequest); var controller = new HomeController(); controller.ControllerContext =

How to clear previous expectations on an object?

ぃ、小莉子 提交于 2019-11-26 10:39:27
问题 I would like to set up a return value _stubRepository.Stub(Contains(null)).IgnoreArguments().Return(true); but then in a specific test, override that expectation to return false. Something like: _stubRepository.ClearExpectations(); //<- this does not exist, I\'m just making something up _stubRepository.Stub(Contains(null)).IgnoreArguments().Return(false); Notice, I do not want the expectation to return false on the second call, I want to override the first expectation. This would help