Hi,
I am a newbie in testing frameworks and rhino mocks is the first one I am trying to implement in visual studio 2012 for a c# project.
I have included the rhino mocks *.dll as a reference and made two classes in a single project.
I got the code from @
http://aspalliance.com/1400_Beginning_to_Mock_with_Rhino_Mocks_and_MbUnit__Part_1.4program.cs
====
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SampleRhinoMocksTestingApplication
{
class Program
{
static void Main(string[] args)
{
ImageManagement image = new ImageManagement();
string path = image.GetImageForTimeOfDay(new DateTimeController());
Console.WriteLine(path);
Console.ReadLine();
}
}
public class DateTimeController : IDateTime
{
public int GetHour()
{
return DateTime.Now.Hour;
}
}
public class ImageManagement
{
public string GetImageForTimeOfDay(IDateTime time)
{
int currentHour = time.GetHour();
if (currentHour > 6 && currentHour < 21)
{
return "sun.jpg";
}
else
{
return "moon.jpg";
}
}
}
public interface IDateTime
{
int GetHour();
}
}
====
TestClass.cs
====
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino.Mocks;
using SampleRhinoMocksTestingApplication;
namespace RhinoTests
{
[TestClass]
class Program
{
[TestMethod]
public void DaytimeTest()
{
MockRepository mocks = new MockRepository();
IDateTime timeController = mocks.StrictMock<IDateTime>();
using (mocks.Record())
{
Expect.Call(timeController.GetHour()).Return(15);
}
using (mocks.Playback())
{
string expectedImagePath = "sun.jpg";
ImageManagement image = new ImageManagement();
string path = image.GetImageForTimeOfDay(timeController);
Assert.AreEqual(expectedImagePath, path);
}
}
[TestMethod]
public void NighttimeTest()
{
MockRepository mocks = new MockRepository();
IDateTime timeController = mocks.StrictMock<IDateTime>();
using (mocks.Record())
{
Expect.Call(timeController.GetHour()).Return(1);
}
using (mocks.Playback())
{
string expectedImagePath = "moon.jpg";
ImageManagement image = new ImageManagement();
string path = image.GetImageForTimeOfDay(timeController);
Assert.AreEqual(expectedImagePath, path);
}
}
}
}
====
I have been able to build the project successfully.
But when I go to menu bar in visual studio 2012 to; Test -> Windows -> Test Explorer; the test explorer open but I am unable to find any of the test methods in the list.
I have search the internet for configuring up rhino mocks in visual studio 2012 but unable to find a good guide. Please let me know to how to set up the framework or anything I am missing.
Thanks.
-littlechap22