I'm having a bit of trouble doing some unit-testing using moq.
If I have a function like this:
public string GetName(IMapinfoWrapper wrapper)
{
return wrapper.Evaluate("My com command");
///"My comm command" is the same all the time.
}
Then I have a test that checks the return value of the GetName function:
[Test]
public void ...
I am using shanselmann's MvcMockHelper class to mock up some HttpContext stuff using Moq but the issue I am having is being able to assign something to my mocked session object in my MVC controller and then being able to read that same value in my unit test for verification purposes.
My question is how do you assign a storage collection...
I am just getting involved in Moq and unit testing, so forgive me if this seems obvious (a quick search through SO didn't show me anything like this).
I have an interface with the following proposed member:
void AddFeed(Feed feed);
That I would like to write a unit test for this functionality. The test class has a Moq Repository decl...
How do I verify that method was NOT called in Moq?
Does it have something like AssertWasNotCalled?
UPDATE: Starting from Version 3.0, a new syntaxt can be used:
mock.Verify(foo => foo.Execute("ping"), Times.Never());
...
I have an interface named IAuthorizationRepository with the following interface:
public interface IAuthorizationRepository
{
IQueryable<User> Users { get; }
Int32 SaveChanges();
void Detach(Object entity);
void Attach(IEntityWithKey entity);
void DeleteObject(Object entity);
void AddObject(String entitySetName, Object entity);
...
I think it's a good practise to always return empty lists or arrays instead of null
when a method comes up with no results to avoid null checks in the code.
Because Rhino Mocks returns the default value for an object, which is null for lists and arrays, a lot of times I have to either add the null checks back in or setup the mocks with...
I'm writing a command-line interface to my project. The user enters "create project foo", and it finds the controller responsible for "project" and then invokes the Create method, passing "foo" as the first argument.
It relies heavily on attributes and reflection: the controller looks something like this:
[ControllerFor("project")]
cla...
I've been using the MvcMockHelpers class found at Hanselman's blog for passing in a mocked HttpContext. We extended it somewhat to add some authentication data we needed and for the most part this has been great.
The issue we are having is that the context we are giving to the controller has a null value in the HttpContext.Response.Outp...
I am writing a test that depends on the results of an extension method but I don't want a future failure of that extension method to ever break this test. Mocking that result seemed the obvious choice but Moq doesn't seem to offer a way to override a static method (a requirement for an extension method). There is a similar idea with Moq....
Is it possible to get access to the parameter used to make a call to a mocked expectation when assembling the Returns object?
Here is a stub for the objects involved and, given that, I am trying to mock a Collection:
Class CollectionValue {
public Id { get; set; }
}
Class Collection {
private List<CollectionValue> AllValues { g...
I'm trying to get started with Moq and having trouble finding any good resources to do what I need.
I have a Data Interface class that has a Get method which returns a Dataset via Stored Procedure. This is the way the code was written and I can't change it at the moment so it has to be done this way.
I want to test this class by Mocki...
Hi,
I'm using the Composite Application Library's event aggregator, and would like to create a mock for the IEventAggregator interface, for use in my unit test.
I'm planning on using Moq for this task, and an example test so far looks something like this:
var mockEventAggregator = new Mock<IEventAggregator>();
var mockImportantEvent =...
I'm new to mocks and am deciding on a mock framework. The Moq home quotes
Currently, it's the only mocking
library that goes against the
generalized and somewhat unintuitive
(especially for novices) Record/Reply
approach from all other frameworks.
Can anyone explain simply what the Record/Replay approach is and how Moq diff...
I'm trying to Mock the IUnityContainer using Moq 3.0
I'm getting a BadImageFormatException, but not when debugging. From the looks of it I'm not the only one that's ran into this problem.
here
And its a registered issue for Moq
here
I'm just curious if anyone has found a solution... closest I've found is a nice solution that uses Rh...
I keep seeing this referred to on DotNetKicks etc... Yet cannot find out exactly what it is (In English) or what it does? I am stupid, so if you could explain it simply it would be great and why I would use it (If it is something I use)???
Thanks
...
I cannot find a specific feature-by-feature comparison of Moq and Rhino. All the questions are "which do you like better and why", or "here's how you do a simple mock in rhino and how it's done in moq".
I cannot find a deep comparison anywhere. I'm aware of the syntax differences, I'm not looking for answers about that. I am looking ...
Hi folks,
i've got the following Action Method I'm trying to moq test. Notice the AcceptVerbs? I need to make sure i'm testing that.
here's the method.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Include = "Subject, Content")]Post post,
HttpPostedFileBase imageFileName)
{
...
}
here's the moq code i have...
...
Hi folks,
i have a method that does takes in a object and saves it to the database. But, before i save the object, i do the following...
(psuedo code)
if (IsAuthenticated)
{
foo.UserId = AuthenticatedUser.Id;
}
else
{
foo.AnonEmail = "Jon@World-Domination";
foo.AnonName = "Jon Skeet";
}
try
{
_fooService.Save(foo);
}
catc...
I just switched to Moq and have run into a problem. I'm testing a method that creates a new instance of a business object, sets the properties of the object from user input values and calls a method (SaveCustomerContact ) to save the new object. The business object is passed as a ref argument because it goes through a remoting layer. ...
Dear gurus,
I am taking my first steps with MsTest and Moq and would like to unit test a Linq2SQL repository class. The problem is that I do not want the unit tests to permantly modify my development database.
Which would be the best approach for this scenario?
Let each test operate on my real development database, but make sure eac...