I have a Flex 4 client application that is under development in parallel with the server back-end. I am use Mate's MockRemoteObject to provide a mock data service, but as the real data service comes on line, we'll want to run against that sometimes from Eclipse.
Is there a way to easily switch between the two without having to modify s...
I am trying to unit test an action filter I wrote. I want to mock the HttpClientCertificate but when I use MOQ I get exception. HttpClientCertificate doesnt have a public default constructor.
code:
//Stub HttpClientCertificate </br>
var certMock = new Mock<HttpClientCertificate>();
HttpClientCertificate clientCertificate = certMock.Obj...
I've cross posted this on the #moq discussion group at:
http://groups.google.com/group/moqdisc/browse_thread/thread/569b75fd2cc1829d
hey folks,
I have come across a problem with a mocked ref param that I'm sure
must be obvious, but being new to the framework I just can't work it
out.
I have the following repository method:
public int...
I have code under test that basically looks like this (the specific code isn't important to the question. It is just here for explanatory purposes):
public ICollection<Product> GetByCategory(string category, ISession session)
{
return session
.CreateCriteria(typeof(Product))
.Add(Restrictions.Eq("Category", category...
Yet another "simple" question about unit testing model objects that uses data access layer.
When I mock my Table<Customer> to IQuerable<ICustomer>, where new List<FakeCustomer>().AsQuerable() is used in role of in memory data store, the following code passes unit test perfectly:
var filteredCustomers = from c in dal.Customers
...
I have been looking at examples of mocking using Moq and Rhino Mocks and all the examples seem to mock interfaces. Why is this? I have heard they can mock static classes, but what about non-static classes?
...
I'm new with MSTest (Visual Studio 2010).
Is there any integrated mocking framework that comes with VS2010?
Or is there any other good mocking framework that's easy to pick up that I could use?
...
Hi, I'm wondering if there's any mocking framework that allows testing methods contaning method calls to dependent class instances not injected to the tested method or its class:
void MethodToTest()
{
....
DependentClass dc = new DependentClass();
dc.Foo();
....
}
In the code above I would like to mock the call to Foo(...
I consider folks at MS way more smarter than I am. I was trying to build/test a repository which almost follows this approach except that I want to loosely couple the ObjectContext dependency inside the repository. I found out that in order to do decouple this I need to jump a lot of hoops as shown in this article.Even this approach is d...
Hi,
I'm trying to write a simple integration test, but having some trouble with Domain Objects. I've read on unit testing but can't figure it out.
This is my simple test:
User user = User.get(1)
controller.params.userid = "1"
controller.session.user = user
controller.save();
The error message is:
groovy.lang.Mis...
I want to mock this interface using Moq
IInterfaceToBeMocked {
IEnumerable<Dude> SearchDudeByFilter(Expression<Func<Dude,bool>> filter);
}
I was thinking of doing something like
_mock.Setup(method => method.SearchDudeByFilter( x=> x.DudeId.Equals(10) && X.Ride.Equals("Harley"))). Returns(_dudes);// _dudes is an in-memory list of dud...
I have the following method:
private string _google = @"http://www.google.com";
public ConnectionStatus CheckCommunicationLink()
{
//Test if we can get to Google (A happy website that should always be there).
Uri googleURI = new Uri(_google);
if (!IsUrlReachable(googleURI, mGoogleTestString))
{
//The internet is...
I'd like to be able to test a class initialises correctly using Moq:
class ClassToTest
{
public ClassToTest()
{
Method1(@"C:\myfile.dat")
}
public virtual void Method1(string filename)
{
// mock this method
File.Create(filename);
}
}
I thought I'd be able to use the CallBase property to...
Usually I have client code similiar to something like this:
// SomeOtherServiceClient would be injected in actual code.
ISomeOtherService client = new SomeOtherServiceClient();
... so that I can mock the service for testing. But now I have a WCF service that has the context mode set to PerSession and implements IDisposable.
[Service...
I have the following test to verify that my repository is calling it's respective session (I've rewritten it to highlight the actual problem):
[Test]
public void Why_Does_This_Fail()
{
var objectUnderTest = new SomeGenericsProblem();
var fakeSession = MockRepository.GenerateMock<ISession>();
fakeSession....
I understand how to mock interfaces or virtual method calls. But frameworks like TypeMock can mock everything in the framework. Which .NET mechanisms are used to provide such functions?
...
How can I mole the DataContext that I'm using in a class to write messages to a table. I'd like to assert that the table LINQ is writing to has the expected count of messages. Here's what i have so far.
var context = new MJustTestingDataContext();
MyMessagewriter writer = new MyMessageWriter(context);
var messageList = new List<MIncmoi...
I am using MvcContrib and the TestControllerBuilder to write tests for my controller.
I am writing the tests for my Error Handling Controller that looks like this:
public JsonResult HttpError()
{
Exception ex = null;
try
{
ex = (Exception)HttpContext.Application[Request.UserHostAddress.ToStr...
So I have a class that looks like this:
public class MyClassToTest()
{
MyStaticClass.DoSomethingThatIsBadForUnitTesting();
}
and a static class that looks like this:
public static class MyStaticClass()
{
public static void DoSomethingThatIsBadForUnitTesting()
{
// Hit a database
// call services
//...
I want to make sure I am testing Models/Objects in isolation and not as one huge system.
If I have an Order object and it has Foreign Keys to Customers, Payments, OrderItems, etc. and I want to test Order functionality, I need to create fixtures for all of that related data, or create it in code. I think what I really need to be doing i...