I Have a Class that needs to make an HTTP request to a server in order to get some information. For example:
- (NSUInteger)newsCount {
NSHTTPURLResponse *response;
NSError *error;
NSURLRequest *request = ISKBuildRequestWithURL(ISKDesktopURL, ISKGet, cookie, nil, nil);
NSData *data = [NSURLConnection sendSynchronousReques...
We are a few months into a green-field project to rework the Logic and Business layers of our product. By utilizing MEF (dependency injection) we have achieved high levels of code coverage and I believe that we have a pretty solid product. As we have been working through some of the more complex logic I have found it increasingly difficu...
Are there any ways to mock a WCF client proxy using Rhino mocks framework so I have access to the Channel property? I am trying to unit test Proxy.Close() method but as the proxy is constructed using the abstract base class ClientBase<T> which has the ICommunicationObject interface, my unit test is failing as the internal infrastructure ...
I have a class:
class MyClass(object):
@property
def myproperty(self):
return 'hello'
Using mox and py.test, how do I mock out myproperty?
I've tried:
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty = 'goodbye'
and
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty.AndReturns('goodbye')
...
I have a class that roughly looks like this:
public class ViewModel
{
public ViewModel(IWebService service)
{
this.WebService = service;
}
private IWebService WebService{get;set;}
private IEnumerable<SomeData> MyData{get;set;}
private void GetReferenceData()
{
this.WebService.BeginGetStaticReferenceData(GetRefe...
I'm using the mock-0.6 library from http://www.voidspace.org.uk/python/mock/mock.html to mock out a framework for testing, and I want to have a mock method return a series of values, each time it's called.
Right now, this is what I figured should work:
def returnList(items):
def sideEffect(*args, **kwargs):
for item in items:
...
Is there any ability to mock methods that are provided with RIA Services?
I would like to test my Silverlight App without communication to the server side...
I see a following approach:
create a separate interface;
add it to "base classes" for my RiaService;
define each autogenerated RIA-method in this interface;
insert dependency so...
How can I mock my location on a physical device (Nexus One)? I know you can do this with the emulator in the Emulator Control panel, but this doesn't work for a physical device.
...
Hello there.
I'm trying to make this test fail :)
it "should display the question" do
@ui.should_receive(:puts).with("What's your name?").once
@ui.ask_question("What's your name?")
end
At the moment it passes even if I don't call puts in my function.
...
I'd like to write F# unit test with mock objects. I'm using NUnit.
But unfortunately I couldn't find any examples.
Here's an example of the code under test:
type ICustomer = interface
abstract Id: int with get
abstract Name: string with get
abstract CalculateBalanceWithDiscount: decimal -> decimal
end
type Customer = cla...
Greetings,
I'm fairly new to TDD and ran across a unit test that I'm not entirely sure how to address.
Basically, I'm testing a couple of legacy class methods which read/write a binary stream to a file. The class functions take a serializable object as a parameter, which handles the actual reading/writing to the file.
For testing this...
In my unit test, i'm looking to stub the behaviour of php's inbuilt file_get_contents() method.
Is there a way to stub native methods in PHP (such as file_get_contents() or print_r()) and the likes?
...
Moq allows developers to mock protected members. I was looking for the same functionality in Rhino.Mocks but fail to find it.
Here's an example from Moq Quick Start page how to mock protected method.
// at the top of the test fixture
using Moq.Protected()
// in the test
var mock = new Mock<CommandBase>();
mock.Protected()
.Setup...
How can I mock an array's sort expect a lambda expression?
This is a trivial example of my problem:
# initializing the data
l = lambda { |a,b| a <=> b }
array = [ 1, 2, 3, 4, 5 ]
sorted_array = [ 2, 3, 8, 9, 1]
# I expect that sort will be called using the lambda as a parameter
array.expects(:sort).with( l ).returns( sorted_array )
#...
I want to extensively test some pieces of C code for memory leaks.
On my machine I have 4 Gb of RAM, so it's very unlikely for a dynamic memory allocation to fail. Still I want to see the comportment of the code if memory allocation fails, and see if the recover mechanism is "strong" enough.
What do you suggest ? How do I emulate an en...
I am trying to use Rhino Mocks to mock the following lambda, but keep hitting a brick wall
var result = rep.Find<T>(x => (x as IEntity).ID == (entity as IEntity).ID).FirstOrDefault();
Any ideas?
...
I'm only new to Unit Testing and ASP.NET MVC. I've been trying to get my head into both using Steve Sanderson's "Pro ASP.NET MVC Framework". In the book there is this piece of code:
public class AdminController : Controller
{
...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product product, HttpPostedFileBase image)
...
Hey there!
I'm wondering how to stub/mock a helper method in functional tests?
Thanks!
(And Yes, I already googled & used the search - but couldn't find any working solution, strange!?)
...
I'm somewhat new to Unity and dependency injection. I'm trying to write a unit test that goes something like this:
[Test]
public void Test()
{
UnityContainer container = new UnityContainer();
DynamicMock myMock = new DynamicMock(typeof(IMyInterface));
container.RegisterInstance(typeof(IMyInterface), myMock.MockInstance); //...
I'm attempting to mock some file operations. In the "real" object I have:
StreamWriter createFile( string name )
{
return new StreamWriter( Path.Combine( _outFolder, name ), false, Encoding.UTF8 ) );
}
In the mock object I'd like to have:
StreamWriter createFile( string name )
{
var ms = new MemoryStream();
_files.Add( Path.Com...