Skip to content

Instantly share code, notes, and snippets.

View GraemeF's full-sized avatar

Graeme Foster GraemeF

View GitHub Profile
@GraemeF
GraemeF / RequestExtensions.cs
Created July 30, 2011 20:02
Request/Response extensions
public static class RequestExtensions
{
public static string AsString(this RequestStream requestStream)
{
return new StreamReader(requestStream).ReadToEnd();
}
public static XDocument AsXml(this RequestStream requestStream)
{
return XDocument.Load(requestStream);
Comma and semicolon
Use the comma (,) and semi-colon (;) characters to indicate nonhierarchical portions
of the URI. The semicolon convention is used to identify matrix parameters:
http://www.example.org/co-ordinates;w=39.001409,z=-84.578201
http://www.example.org/axis;x=0,y=9
These characters are valid in the path and query portions of URIs, but not all code
libraries recognize the comma and semicolon as separators and may require custom
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();
}