I'm using this kind of wiring for my MVC and I want to test the controller. So far, I've found two ways : either my mock view dispatch events or my controller expose public methods.
Dispatching events seems the way to go (as pointed out in an answer), but if my view is a simple mock object, how do I dispatch those events?
...
I'm writing a custom Profile provider, but I still intend to use the default AspNetSqlMembershipProvider as my Membership provider. My GetAllProfiles() method in my Profile provider looks like this:
1 public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, o...
I was experimenting jMock as my mocking framework for my project. I came into a situation where I need to mock both a class and an interface. I used the ClassImposteriser.INSTANCE to initiate the impostor of the context.
Supposing a class Validator and an interface Person to mock. When I was going to mock the Interface Person, I ran to ...
Is there a way to get my mocks to impersonate a type? I am trying to do something like this:
var myMock = new Mock<IMyType>();
myMock.Setup(x => x.GetType()).Returns(typeof(MyTypeImpl));
however, GetType is not overrideable.
Any suggestions?
...
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 ...
I have an AccountController whose constructor takes an object derived from my custom IOpenIdAuthentication interface. By default, this is an OpenIdAuthenticationService object that wraps an OpenIdRelyingParty. The interface looks like this:
public interface IOpenIdAuthentication {
IAuthenticationResponse Response { get; }
IAuthe...
//IsExist always false,is it a bug?
[TestMethod]
public void IsExist()
{
private Mock<IRepository> repository = new Mock<IRepository>();
Foo f = new Foo();
repository.Expect(s => s.IsExist(foo)).Returns(true);
var controller = new MyController(repository.Object);
var res...
Suppose I am defining a Haskell function f (either pure or an action) and somewhere within f I call function g. For example:
f = ...
g someParms
...
How do I replace function g with a mock version for unit testing?
If I were working in Java, g would be a method on class SomeServiceImpl that implements interface SomeService. ...
I'm using Moq library. I'm mocking up an instance that does all regular CRUD functionality. I would like to set it up in a way to allow only one Delete(x) call over some object and all consecutive calls to Delete(x) of the same object should return an Exception.
My Delete() method returns void.
How do I do that?
Some code
mock = new ...
The test class below verifies that a simple HttpService gets content from a given URL. Both the implementations shown make the test pass, though one is clearly wrong because it constructs the URL with an incorrect argument.
To avoid this and correctly specify the behaviour I want, I'd like to verify that in the use block of the test ca...
I have a method on an interface:
string DoSomething(string whatever);
I want to mock this with MOQ, so that it returns whatever was passed in - something like:
_mock.Setup( theObject => theObject.DoSomething( It.IsAny<string>( ) ) )
.Returns( [the parameter that was passed] ) ;
Any ideas?
...
What is the purpose of mocking?
I have been following some ASP.NET MVC tutorials that use NUnit for testing and Moq for mocking. I am a little unclear about the mocking part of it though.
...
For unit testing purposes I'm trying to write a mock object of a class with no constructors.
Is this even possible in Java, of is the class simply not extensible?
...
Hi
I've been experimenting with Rhino Mocks for unit testing my .Net Compact Framework application, and have hit a problem. I can get a basic unit test using Rhino Mocks built, but every time I run the test that has the Rhino Mocks code in it, the test fails because it can't find the Rhino Mocks assembly.
System.TypeLoadException: Coul...
I am trying to write some functional tests in my rails app, and in the application_controller.rb I have this:
before_filter :current_account
def current_account
@current_account ||= Account.find_by_subdomain!(request.subdomians.first)
end
When running tests, request.subdomains doesn't contain the valid subdomains I'm looking for and...
I am just starting here with mocking about, and I am trying something which I think should be quite simple.
I have a class that reads Google calendar data. First, it creates a CalendarService object, then it calls Query on that object, receives a EventFeed and iterates on the Item collection of AtomEntryCollection.
I want it all to be m...
I want to handle a ManagementException exception for a specific ErrorCode only and am having trouble writing the unit test for it. Ordinarily, I would write the test so that it is something like the following:
Searcher search = MockRepository.GenerateMock<Searcher>();
// wrapper for ManagementObjectSearcher
...
search.Expect(s => s.G...
Hi,
i am using TypeMock Isolator to fake the tables on my DataContext like this:
Isolate.Swap.CallsOn(ctx.GetTable<TTable>()).WithCallsTo(content);
I now can fill the "database" with arbitrary data on each test. In order to get meaningful data for the test scenario into the DataContext i usually have to create 3-5 objects.
Now, the p...
I am currently trying to go back through and write unit tests for some code that wraps an existing class. The function I am looking for has code that looks like the following...
private OldObject oldObject
...
public Boolean method(){
Boolean returnValue = false
if(oldObject.method(100)){
returnValue = true
}
if(oldObject....
Any idea in Moq for a class with readonly modifier :
Class myClass
{
private int id;
public int Id{ get {return id;}}
public myClass(int id)
{ this.id = id }
}
I was trying to mock this object:
var myMock= new Mock<myClass>();
myMock.SetupGet(m => m.ID).Return(555);
It returned me error:
System.ArgumentException: I...