I am checking that the ModelState.IsValid in my action method that create the Employee
[HttpPost]
public virtual ActionResult Create(EmployeeForm employeeForm)
{
if (this.ModelState.IsValid)
{
try
{
IEmployee employee = this._uiFactoryInstanc...
When I use SetupAllProperties on a Mock, it works as expected:
/// <summary>
/// demos SetupAllProprties on an interface. This seems to work fine.
/// </summary>
[Test]
public void Demo_SetupAllProperties_forAnInterface()
{
var mock = new Mock<IAddress>();
mock.SetupAllProperties();
var stub = mock.Object;
stub.City = ...
I have a method I'd like to mock:
public interface IServiceBus
{
void Subscribe<T>(ISubscribeTo<T> subscriber) where T : class;
}
For the sake of this example, T can be something called SomeType.
Now, I'd like to mock this, like so:
var mockServiceBus = new Mock<IServiceBus>();
mockServiceBus.Setup(x => x.Subscribe(It.IsAny<ISubs...
I've got the default route set-up:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Shortie", // Route name
"{controller}/{id}", // URL with parameters
new { controller = "Ettan", action = "Index", id = "id" } // P...
I have a typical Silverlight application with a WCF service and I am using slsvcutil.exe to generate the standard client proxy to communicate with the web service. I am trying to write unit tests and I'm attempting to use the Silverlight Unit Testing framework and Moq to mock the proxy and remove the service dependency for testing.
I am...
I'm getting the exception
The type initializer for 'Moq.Mock`1'
threw an exception.
using Moq 4.0 I've checked around on a couple of forums and they allude to using the Moq-NoCastle version. I've tried both this and version in the Moq folder. Both with the same result.
I've got a solution with 2 projects, one for my interface...
I've been using Moq framework in c# for mocking in unit tests however there is one thing I dont complete understand yet. I have this line of code
var feedParserMock = new Mock<ApplicationServices.IFeedParser>();
feedParserMock.Setup(y => y.ParseFeed(csv)).Returns(items).Verifiable();
The second line does it mean it will only return th...
Hi Everyone,
I am working with a faked HttpContext (code provided in the end) and probably I am missing something because I can't access TempData collection (forth line of SetFakeControllerContext method). Every time I try I get this error message:
'controller.TempData' threw an exception of type 'System.AccessViolationException'
The ...
I'm using VS Unit Testing Framework and Moq.
When a Moq verification fails, I'll get a Moq.MockException. In the Test Results window, instead of showing the helpful message inside the exception, it just says "Test method XXX threw exception: ..."
Is there a way to tell the VS Unit Test framework always display the message of exceptions...
I am trying to understand how to use Moq, however I am having some confusion about what Moq should be used for. My understanding is that mock framework are used for generating objects which would be difficult to create under normal circumstances. The examples I have seen of Moq however seem to not only create Moq object, but also provide...
I have a class that inherits from an abstract base class. I am trying to verify that a specified protected method in the base class is called twice and I'd like to verify that the parameters passed are specific values (different for each call).
I was hoping that I'd be able to use Protected with either Expect or Verify, but seemingly I'...
So I'm trying to unit-test a controller method. I'm using MSTest in VS 2010, and Moq 3.1
Test method:
[TestMethod]
public void TestAccountSignup()
{
var request = new Mock<HttpRequestBase>();
var context = new Mock<HttpContextBase>();
AccountController controller = new AccountController();
...
I have code that uses MoQ to create a partial stub. I'd prefer to interact with the interface instead of the concrete implementation so that I won't have to modify the unit test if I have a different implementation of the interface.
So for example, I have a factory method such as:
private Mock<ISomeInterface> ISomeInterfaceStubFactory...
Let's say we are testing a class C which has 2 methods M1 and M2 where M1 calls M2 when executed.
Testing M2 is ok, but how can we test M1? The difficulty is that we need to mock M2 if I'm not misunderstanding things.
If so, how can we mock another method while testing a method defined in the same class?
[Edit]
Class C has no base cla...
I have a class that constructs a new object to add to the internal state of an object I am mocking... something like
public class foo
{
public bar raz;
public foo(bar raz)
{
this.raz = raz;
}
public void InsertItem()
{
raz.Insert(new FooBar());
}
...
I have a mock that i have setup like this. I need to return the same value that was passed in to .CreatePersonName
mock.Setup(m => m.CreatePersonName(It.IsAny<PersonName>()))
.Returns(// what do i put here?);
...
Hello there, I have just started playing with unit testing / mocks using Moq, and ran into a problem..
I have a Service layer named "CustomerService" which have following code:
public interface ICustomerService
{
Customer GetCustomerById(int id);
}
public class CustomerService : ICustomerService
{
private IRepository<Customer>...
I have a class that does some retrieving of contents, and it has a method that requires some inputs (filters) before retrieving it. One of the "input" calls another method, which basically returning an int, how do I mock it using MOQ? Here's an example:
namespace MyNamespace
{
public class ConfigMetaDataColumns : MyModel
{
...
I have set a test using Moq 3.0. I need to test a method that will change some value in that database. I am using ASP.NET MVC so I want to test my controller.
I setup this
// Generate an implementer of IProductsRepository at runtime using Moq
var mockTareasRepos = new Mock<IRepository>();
mockTareasRepos.Setup(x => x.ExecutedTask).R...
I just downloaded the latest release of the source code to the Microsoft Enterprise Library. When I tried to build the solution in Visual Studio 2010, I get the following error:
The type or namespace name 'Moq' could
not be found (are you missing a using
directive or an assembly reference?)
What is Moq and where can I find th...