Skip to content

Instantly share code, notes, and snippets.

@patrik-hagne
patrik-hagne / gist:5345649
Created April 9, 2013 13:21
Quick example of how inline configuration on fake creation might be implemented in FIE.
public static class dlkfjslkjd
{
public static IAnyCallConfigurationWithNoReturnTypeSpecified AnyCall<T>(this IFakeOptionsBuilder<T> options)
{
var result = new Callback();
options.OnFakeCreated(x => result.Apply(A.CallTo(x)));
return result;
}
@patrik-hagne
patrik-hagne / gist:2472259
Created April 23, 2012 16:53
Why sequence equivalence should not be default in FakeItEasy when comparing arguments.
// This example illustrates why having FakeItEasy default to comparing sequence equivalence for
// enumerable types would be non intuitive.
// In this example the current implementation of FakeItEasy argument constraints would make the
// assertion (MustHaveHappened) fail, which is correct. An implementation where sequence equivalence
// would be used for the constraint the assertion would incorrectly pass.
class Program
{
public interface IPersonRepository
[Fact]
public void Should_dispose_request_when_being_disposed()
{
// Given
var request = A.Fake<Request>(x => x.WithArgumentsForConstructor(new[] {"GET", "/", "http"}));
this.context.Request = request;
// When
this.context.Dispose();
@patrik-hagne
patrik-hagne / gist:1440047
Created December 6, 2011 21:18
Overly complicated
//console = undefined;
(function(undefined) {
var log = (function() {
var inner = function(value) {
if (console != undefined && console.log != undefined) {
inner = function(value) {
console.log(value);
};
} else {
inner = function(value) {
@patrik-hagne
patrik-hagne / gist:886016
Created March 24, 2011 22:14
Tracing out of the way.
public class Foo
{
public void DoWhatever()
{
var user = this.FetchUserFromRepository("userid");
this.DoSomethingWithTheUser(user);
}
protected virtual object FetchUserFromRepository(string userid)
{
@patrik-hagne
patrik-hagne / gist:820505
Created February 10, 2011 13:25
This is how I would test that a decorator delegates to the wrapped object in FakeItEasy.
public interface IRobot
{
string Name { get; set; }
}
public class RoboCop
: IRobot
{
private readonly IRobot robot;
Fake.GetCalls(_log).
Single(call => call.Method.Name == "set_Offset").
GetArgument<TimeSpan>(0).
Should().Equal(newOffset);
// This example illustrates why having FakeItEasy default to comparing sequence equivalence for
// enumerable types would be non intuitive.
// In this example the current implementation of FakeItEasy argument constraints would make the
// assertion (MustHaveHappened) fail, which is correct. An implementation where sequence equivalence
// would be used for the constraint the assertion would incorrectly pass.
class Program
{
public interface IPersonRepository