Skip to content

Instantly share code, notes, and snippets.

View GraemeF's full-sized avatar

Graeme Foster GraemeF

View GitHub Profile
@GraemeF
GraemeF / gist:771591
Created January 9, 2011 10:36
Failing test for JsonFx deserializing a List<T>
namespace Tests
{
using System.Collections.Generic;
using System.Linq;
using JsonFx.Json;
using Should.Fluent;
using Xunit;
@GraemeF
GraemeF / readable.cs
Created January 14, 2011 21:45 — forked from johnnonolan/readable.cs
Now more readable :P
namespace iDoc.specs.When
{
[Subject("AccountManagement")]
public class CreatingAUserAccount : BaseContext<AccountController>
{
const string EmailAddress = @"1@2.com";
Establish context = () =>
{
model = new RegistrationModel {
@GraemeF
GraemeF / gist:793212
Created January 24, 2011 13:30
ReplaceSpacesWithUnderscores
Sub ReplaceSpacesWithUnderscores()
Dim textSelection As EnvDTE.TextSelection
textSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
textSelection.Text = textSelection.Text.Replace(" ", "_")
End Sub
@GraemeF
GraemeF / Player.cs
Created January 27, 2011 11:50
Runner up hangman player - done in a hurry so UNCLEAN! :P
namespace Graeme
{
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using CodeFest2PlayerRef;
[Export(typeof(ICanPlayCodeFest2))]
public class Player : ICanPlayCodeFest2
@GraemeF
GraemeF / gist:820437
Created February 10, 2011 12:25
How can I check that "_log.Offset = newOffset" happened?
Fake.GetCalls(_log).
Single(call => call.Method.Name == "set_Offset").
GetArgument<TimeSpan>(0).
Should().Equal(newOffset);
@GraemeF
GraemeF / MyFixture.cs
Created February 10, 2011 15:16
Setup with Moq
public class MyFixture
{
private readonly ICloseLogFileCommand _closeCommand = Mock.Of<ICloseLogFileCommand>();
private readonly ILog _log = Mocks.Of<ILog>().
First(x => x.Name == @"C:\Path\To\File.log" &&
x.Count == 42 &&
x.Offset == TimeSpan.FromSeconds(69));
...
}
@GraemeF
GraemeF / MyFixture.cs
Created February 10, 2011 15:17
Setup with NSubstitute
public class MyFixture
{
private readonly ICloseLogFileCommand _closeCommand = Substitute.For<ICloseLogFileCommand>();
private readonly ILog _log = Substitute.For<ILog>();
public MyFixture()
{
_log.Name.Returns(@"C:\Path\To\File.log");
_log.Count.Returns(42);
@GraemeF
GraemeF / MyFixture.cs
Created February 10, 2011 15:24
Setup with FakeItEasy
public class MyFixture
{
private readonly ICloseLogFileCommand _closeCommand = A.Fake<ICloseLogFileCommand>();
private readonly ILog _log = A.Fake<ILog>();
public MyFixture()
{
A.CallTo(() => _log.Name).Returns(@"C:\Path\To\File.log");
A.CallTo(() => _log.Count).Returns(42);
[Fact]
public void Initialize_Always_InitializesParserPresenter()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
Mock.Get(_parserPresenter).Verify(x => x.Initialize());
}
[Fact]
public void Initialize_Always_InitializesParserPresenter()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
A.CallTo(() => _parserPresenter.Initialize()).MustHaveHappened();
}