Skip to content

Instantly share code, notes, and snippets.

View GraemeF's full-sized avatar

Graeme Foster GraemeF

View GitHub Profile
System.IndexOutOfRangeException was unhandled
Message=Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
Source=System.CoreEx
StackTrace:
Server stack trace:
at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
at System.Console.WriteLine(String value)
private static void UpdatePropertyValue<T, TValue>(Expression<Func<T, TValue>> property, T fake, TValue newValue) where T : class
{
property.Compile()(fake).Returns(newValue);
}
namespace Stuff
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using Moq;
[Fact]
public void Offset_WhenLogOffsetChanges_RaisesPropertyChanged()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
test.AssertThatChangeNotificationIsRaisedBy(x => x.Offset).
When(() => _log.PropertyChanged += Raise.With(new PropertyChangedEventArgs("Offset")).Now);
}
[Fact]
public void Offset_WhenLogOffsetChanges_RaisesPropertyChanged()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
test.AssertThatChangeNotificationIsRaisedBy(x => x.Offset).
When(() => _log.PropertyChanged += Raise.Event<PropertyChangedEventHandler>(this,
new PropertyChangedEventArgs("Offset")));
[Fact]
public void Offset_WhenLogOffsetChanges_RaisesPropertyChanged()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
test.AssertThatChangeNotificationIsRaisedBy(x => x.Offset).
When(() => Mock.Get(_log).Raise(x => x.PropertyChanged += null,
new PropertyChangedEventArgs("Offset")));
[Fact]
public void Initialize_Always_InitializesParserPresenter()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
_parserPresenter.Received().Initialize();
}
[Fact]
public void Initialize_Always_InitializesParserPresenter()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
A.CallTo(() => _parserPresenter.Initialize()).MustHaveHappened();
}
[Fact]
public void Initialize_Always_InitializesParserPresenter()
{
LogPresenter test = BuildTestSubject();
test.Initialize();
Mock.Get(_parserPresenter).Verify(x => x.Initialize());
}
@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);