Is it possible to Mock a Linq Expression via Moq using a Generic class such as ~1Repository. ~IRepository being something that is injected via an IoC such as StructureMap or Windsor?
CODE TO TEST:
var person = _repository.Find<Person>()
.Where(p => p.Id == person.Id).SingleOrDefault();
TEST:
var rep...
Hi, I wrote a small program that uses Mechanize to traverse a site.
I want to write tests for it, but don't want it to actually go log onto the site every time I run the tests. I would like to mock the internet, so that when it goes to some site, it simply returns the stored results.
Here is a small example, pretend my code's purpose ...
I'm trying to mock a method call that takes a call-by-name argument:
import org.scalatest.WordSpec
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
trait Collaborator {
def doSomething(t: => Thing)
}
trait Thing
@RunWith(classOf[JUnitRunner])...
I'm trying to write some code to help unit test WCF services. These services are accessed through a facade class that creates the proxy instance, then calls the proxy method and returns the result; for each proxy method. I'd like to be able to replace the current creation code with something that either creates the real service or a fake...
I've run into this problem with testing. Let's assume I have two models, User and Post, where user has_many :posts.
I'm trying to spec out a code block that includes something like this:
user = User.find(123)
post = user.posts.find(456)
I know how to mock out the User.find and user.posts parts. The user.posts mock returns an array of...
I like the idea of using an In-Memory Database such as SQLite when testing instead of creating Mocks for my Repositories. This way I can also test the code of my Repositories without any performance issues.
What are the pros and cons of this strategy?
...
I created the following interface:
<?php
interface Action
{
public function execute(\requests\Request $request, array $params);
}
Then I try to make a Mock object of this interface with PHPUnit 3.4, but I get the following error:
Fatal error: Declaration of Mock_Action_b389c0b1::execute() must be compatible with that of Action::e...
Hi everyone!
I'm using Moq & NUnit as a unit test framework.
I've written a method that is given a NetworkStream object as a parameter:
public static void ReadDataIntoBuffer(NetworkStream networkStream, Queue dataBuffer)
{
if ((networkStream != null) && (dataBuffer != null))
{
while (networkStream.DataAvailable)
{
...
I have a C# class that gets generated using the wsdl.exe tool that looks something like this:
public partial class SoapApi : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public SOAPTypeEnum AskServerQuestion()
{
object[] results = return this.Invoke("AskServerQuestion");
return (SOAPTypeEnum) results[0]...
I want to mock ASP.NET 3.5 behavior in order to unit test my WebControls: I want to test how they perform with mock data with existing system of events. Basically I want to test generated result HTML based on input mock data.
How to do it?
I looked into NMock, but it doesn't suit my needs for 2 reasons:
It just runs ASP.NET server in...
I am trying to experiment with RhinoMocks, where I have to say I am a newbie and probably I don't get some obvious thing here. What I'm doing is something like :
[TestMethod]
public void SaveResponsibleUserFromChangeset()
{
var action = mocks.StrictMock<GenomeAction>();
var changeset = new ActionChangeset();
...
I'm brand new to unit testing and mocking and still wet behind the ears. I'm using the Moq framework and I need to mock a collection such that it yields a single member with a value I supply.
The collection class in question is a System.Configuration.SettingsPropertyCollection, which contains SettingsProperty objects.
In turn, the Sett...
I don't have much experience doing unit testing. From what I learned, code should be decoupled, and I should not strive to test private code, just public methods, setters, etc etc.
Now, I have grasped some basic testing concepts, but I have troubles applying more advanced stuff to this case... Dependency Injection, Inversion of Control,...
I'm trying to create a doctest with mock of function that resides in a separate module
and that is imported as bellow
from foomodule import foo
def bar():
"""
>>> from minimock import mock
>>> mock('foo', nsdicts=(bar.func_globals,), returns=5)
>>> bar()
Called foo()
10
"""
return foo() * 2
import doct...
I use RhinoMocks for a very simple test (I have to say I'm a beginner here). I tried to mock my object like this
var mock = MockRepository.GenerateMock<MyClass>();
create a helper stub :
var stubLinkedObject = MockRepository.GenerateStub<MyClass>();
then execute some logic which should call the method AddLink of the class MyClass ...
When testing a class that uses a Moq dependency, I'd like the class to supply the arguments to a Moq method, rather than creating the arguments myself in the test case.
I have an interface, that has one method, which takes one argument.
public interface IMessageForwardProxy
{
IMessage Send(IMessage request);
}
I have a class that...
I'm wrapping RemoteObject inside a class for easier managing of retries, timeouts, failures and such non standard scenarios. So when wrapping a RemoteObject inside another class, how would I go about unit testing this?
Here is an example of how to use the class:
// set up the object as you would a RemoteObject, but without events:
var...
If I do this:
var repository = new Mock<IRepository<Banner>>();
repository.Setup(x => x.Where(banner => banner.Is.AvailableForFrontend())).Returns(list);
"Where" is a method on my repository that takes a Func<T, ISpecification<T>. AvailableForFrontend returns an implementation of ISpecification, and list is an IEnumberable of the gene...
I'm trying to use groovy's MockFor and proxyDelegateInstance to mock a java class with constructor parameters, but I can't seem to get it right. My Java class looks like:
class MyJavaClass {
private MyObject myObj
public MyJavaClass(MyObject myObj) {
this.myObj = myObj;
}
}
class MyGroovyTest {
@Test
void testMyJ...
Hi,
We have two components: enterprise application X, and Web service Y
We want to make our (automated) testing tool that will test application X (that interact with Y) only,
and we have not the web service Y available.
Notes:
The testing tool will be a desktop application.
We Don't want to use another external tools-e.g. SoapUI- fo...