Mocking Advantages Over NUint?
Apr 6, 2010I am new to testing.I have to test some C# classes.Kindly let me know what is mocking and why some mocking framework like Rhino mock is preferred over nUint?
View 1 RepliesI am new to testing.I have to test some C# classes.Kindly let me know what is mocking and why some mocking framework like Rhino mock is preferred over nUint?
View 1 RepliesI'm trying to unit test the logOn method of my .Net 4.0 MVC application. I'm pretty sure I need to mock a bunch of objects because I don't want to hit the actual database and I only want to simulate an HTTPcontext in a limited and specific way (if I have to do it at all). All the examples I've found online use mocking frameworks like Moq, RinoMocks or nMock. MVC is all about Test Driven Development, there must be some way to do simple tests without using third party software.
The specific problem,The basic problem is that the controller I'm testing calls Response.Cookies.Add(...) but since the unit test is not in an HTTPContext, Response is null and I get an exception.
My research so far,I understand there is a layer of abstraction which will help me somehow. For example HttpResponse inherits from HttpResponseBase. I think I'm supposed to make a class that inherits from one of the MVC base classes, overload some of the members and then
call the method I want to test in a way that gives it my object instead of one it would normally use.
The question is how to do that. One would need to set up existing code with the ability to construct future versions of objects. Intuitively however, it would seem that existing code could only be and use functionality that existed at the time it was written.
Fortunately, a dynamic runtime means that the code which is actually run can be determined things that change after it is written like config files and HTTP headers.
One way to do that is for the existing code to use some method typically referred to as a factory that takes a string and returns an instance of an object.I conclude that I should look through the code for this factory and figure out how to manipulate it.
My background,I've recently graduated with a degree in Computer Science. Now at my new job, I've been assigned to write unit tests for a large project. Admittedly, I'm new to MVC, many aspects of C# and large projects in general. I may have made simple mistakes or incorrect assumptions in my analysis of this problem. I will do my best to stay active on this post and make it useful for others in situations similar to mine.
I am looking for some guidance
\
-Rhino.Mocks
-Moq
-NMock
-TypeMock (not free)
I have a cookie which my controller uses.
How should i mock the cookie?
I need to create Unit Tests for an ASP.NET MVC 2.0 web site. The site uses Windows Authentication.I've been reading up on the necessity to mock the HTTP context for code that deals with the HttpContext. I feel like I'm starting to get a handle on the DI pattern as well. (Give the class an attribute of type IRepository and then pass in a Repository object when you instantiate the controller.)
What I don't understand, however, is the proper way to Mock the Windows Principal object available through User.Identity. Is this part of the HttpContext? have a link to an article that demonstrates this (or a recommendation for a book)?
I have opened a large web project on elance for a social network. I got over 30 bids on my project and many of the providers recommended php even though they had .net knowledge. many have said that php with drupal has many advanteges over the .NET framework but did not say what they were. Its hard to believe that a scripting language has advantages over a compiled language.
View 6 RepliesI'll be starting a complete re-write of a system in the coming weeks. I'll be using ASP.NET MVC 2.I'm still trying to determine what I should be using as far as TDD, mocking, and IOC is concerned. I was thinking:
VSTEST for writing my TDD tests (or possibly nUnit) Moq as my mocking framework (for creating doubles and fakes) Moq for IOC development Not sure exactly what the ideal setup should be and I'm continuing to research what's available. I'd like some feedback from the community on the most optimal toolsets for TDD, mocking, and IOC.
I'm looking for as comprehensive as possible of a mock replacement and wrapper for the ASP.NET HttpContext in my applications. A comprehensive mock replacement could potentially increase the testability of my ASP.NET web applications substantially, without necessitating migrating every application to more-testable frameworks such as MVC.
Some of the features I am most interested in seeing in an HttpContext wrapper and mock framework include:
Serialized session storage (e.g., .Session).
Serialized application-scoped storage (e.g., .Application).
Per-request item storage (e.g., .Items).
HttpRequest data, such as referrers, request Uri, server variables, post data, etc.
HttpResponse data, such as status codes and content.
Local file resolution (e.g. Server.MapPath)
VirtualPathUtility for application-relative URL path resolution, which has a dependency on the ASP.NET runtime.The identity and principal (e.g., .User) for validating authentication/authorization rules.The AllErrors collection for testing error resolution in HttpModules and Global.asax.I considered writing my own interface, wrapper, and mock; however, I believe such must already exist. The variety of mock frameworks is a little overwhelming for a first-timer to absorb.
What is the most comprehensive HttpContext wrapper and mock?
I've see n a lot of discussions surrounding HttpSessionState and asp.net MVC.I'm trying to write tests for an asp.net application and to mock the HttpSessionState and if so, how?I'm currently using Rhino Mocks and Nunit
View 1 RepliesThe first time i use the Open ID was in my favorite site stackoverflow , i like it so much, from this time to now, i have a set of questions about it: What are the advantages of the open id ?is it just a login facility(more usable than the usual process of entering user name and password)?(i think it will confuse users who are not know them)
Is the open id more secured or less secured or it doesn't related to the security issue at all? Why not all web sites (i mean the popular) use it?Is the implementation is that difficult? When to use open id in a web site? Is it considered as an alternative to the login control or not? if i want to to use the open id in my web application? What is the start point?What are the steps to begin ? Is it a big issue or i can use it in my web application?
What advantages does Membership provide in the case when you have to write custom implementation? Is there any sense to implement membership interfaces or it would be easier to make your own UsersService with just things you need?
View 1 RepliesI'm slowly getting into MVC, but it's still relatively new to me. From what I've discovered by doing a few tutorials, MVC provides an interface for communication between the database and the website and in general allows for better organization of the code. Are there other significant advantages to using an MVC structure? What would be an example of a time when you wouldn't want to user MVC, even if you are communicating with a database?
View 3 RepliesMicrosoft Ajax can expose webservices which respond with json or xml depending on configuration. I would like to mock these services using soap ui. Using the wsdl I can do this to mock the services in the case where xml is returned, however how can I mock the response when JSON is returned?
View 1 RepliesI have a class which I store in session. Lets say Class A, having an attribute theList. I have a member function that adds an item to theList and returns the count of my list.So I mock my class and set theList to "1,2,3" for my unit test, and test my add function by adding "4".
It returns count "3" instead of "4".
here Im trying to write a test can I mock a HttpRequestBase to return post values like this? please help as its quite urgent, how can I acheive this?
var collection = new NameValueCollection();
collection.Add("Id", "1");
collection.Add("UserName", "");
[code]...
What are the advantages and disadvantages of using caching in an asp.net application?
View 2 RepliesWhen do you need IIS Web Garden feature. What's pro's and con's?
View 2 RepliesExplain to a Program Manager what advantages would bring WCF respect to the XML Web Service used in the company until now, what would you respond?
View 4 RepliesSince I'm having problem with unit testing RenderPartialViewToString() with Moq framework [URL] I'm thinking about getting my controller directly, without using Moq for these particular test, however, how do I mocks (or set) the HttpContext for my test without using any Moq framework?
I need to able to do something similar to this, without Moq of course:
var mockHttpContext = new Mock<ControllerContext>();
mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("n1\test");
mockHttpContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
What are the practical advantages of precompiling a website?
View 3 RepliesThere are three developers who create a web application with ASP.NET using different coding standarts.First developer: Uses class libraries and Web forms without using ASP.NET Web Components or Codebehind pages. (Just like ASP with HTML components, single .asp file etc.)Second developer : Uses ASP.NET Web Components and codebehind pages (all advantages of ASP.NET)Thirth developer: Uses HTML components and just codebehind files with old ASP methods(Request, Respond etc.)Which method of these developers use is more advantageous ?
View 6 RepliesSo I've got this method called LoginUser:
public void LoginUser(out SystemUser userToLogin, string username)
Having just started with Rhino Mocks, I'm having a little trouble mocking a call and return value from this method while testing my Presenter code. What's the correct syntax in this instance?
We have an application that has quite an extensive APP_Code directory (about 150 functions). The functions are split across multiple files and then classes and namespaces.
On numerous pages we have to create numerous instances of the classes to be able to access the functionality, which can get very repetitive and means we're repeating code on every page declaring the instance etc.
As far as I can tell, a way to navigate this issue, is to make the functions Public Shared (as opposed to just Public functions).
I'm not familiar with WPF but I've seen things I like about it for web development. I wonder which advantages has developing a WPFbrowser application over asp.net (webforms/MVC) and viceversa. are there things you can do or use in asp.net you can't do in a WPFbroser application?
View 3 RepliesScenario: building a site where navigation will be in master page in either left or top menu. What are the advantages to using the ASP.NET navigation system based on web.sitemap files? The alternative I'm considering is just building the links in <li> elements as necessary.
View 2 Replies