using System;
using System.Collections.Generic;
using System.Text;
using NMock2;
using NUnit.Framework;
namespace NUnitSandbox
{
public interface IThingInterface
{
int GetThingNumber();
}
public class RealThing
{
public int GetThingNumber()
{
return 13;
}
}
public class ClassToBeTested
{
protected virtual IThingInterface GetThing()
{
return new RealThing() as IThingInterface;
}
public int WhatIsTheThingNumber()
{
IThingInterface iThing = GetThing();
return iThing.GetThingNumber();
}
}
/// <summary>
/// This class inherits from ClassToBeTested, so it can override the Virtual Thing Factory method (GetThing).
/// </summary>
[TestFixture]
public class TestClass : ClassToBeTested
{
private Mockery mocks = new Mockery();
/// <summary>
/// This is the key.
/// </summary>
protected override IThingInterface GetThing()
{
IThingInterface mockThing = mocks.NewMock<IThingInterface>();
Expect.AtLeastOnce.On(mockThing).Method("GetThingNumber").Will(Return.Value(42));
return mockThing;
}
[Test]
public void TestGetThingNumber()
{
Assert.AreEqual(42, this.WhatIsTheThingNumber(), "Get Thing Number value should return 42 as specified by the mock.");
}
}
}
<%
' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
'
' This work is licensed under the Creative Commons Attribution License. To view
' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
' 94305, USA.
' Returns the current date and time (UTC) from the NIST server in Boulder, Colorado.
function utcnow()
dim xmlhttp
dim response
' Server to query datetime from
Const TimeServer = "http://time.nist.gov:13"
' Use XML HTTP object to request web page content
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", TimeServer, false, "", ""
xmlhttp.Send
response = xmlhttp.ResponseText
set xmlhttp = nothing
' Parse UTC date
utcnow = cDate(mid(response, 11, 2) & "/" & mid(response, 14, 2) & "/" & mid(response, 8, 2) & " " & mid(response, 16, 9))
end function
' Returns the current date and time, offset to local time zone, from the NIST server in Boulder, Colorado.
' This is more accurate than VBScript's built-in Now() function in situations where the local server is not synchronized.
' There is expected to be some lag caused by this function, but the order of magnitude should only be milliseconds.
' REQUIRES: utcnow()
function atomicnow()
dim utc
dim offset
utc = utcnow()
' The order of the dates is important here!
offset = DateDiff("h", utc, now())
atomicnow = DateAdd("h", offset, utc)
end function
%>