rhino mocks, visual studio 2012, c# : setup, configure?

648 views
Skip to first unread message

littlechap22

unread,
Dec 5, 2012, 2:31:53 AM12/5/12
to rhino...@googlegroups.com, little...@gmail.com
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.4

program.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

Mark Wilkinson

unread,
Dec 5, 2012, 12:44:16 PM12/5/12
to rhino...@googlegroups.com
Also, I'm running short on time getting Mountain Lion installed.

I'm installing it now, it wouldn't download from my wifi last night for whatever reason, we have had bad ATT service for the last couple of weeks for the DSL.  So I brought it to work this morning downloaded it, tried making a bootable USB drive without success, then started installing it an hour ago, it's still installing, after it finishes I need to go into the Recovery mode and reformat, then reinstall so it's a fresh install with all of my profile and apps gone.  Hopefully this is completed by 1, if not would you be able to meet maybe an hour later like 2?

let me know.

I can meet anytime after 1 all the way up until 4-5.


From: littlechap22 <little...@gmail.com>
To: rhino...@googlegroups.com
Cc: little...@gmail.com
Sent: Wednesday, December 5, 2012 1:31 AM
Subject: [RhinoMocks] rhino mocks, visual studio 2012, c# : setup, configure?

--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhinomocks/-/LEpigLEIxB0J.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.


Mark Wilkinson

unread,
Dec 5, 2012, 12:44:45 PM12/5/12
to rhino...@googlegroups.com, little...@gmail.com
sorry guys, sent out an email that was meant for someone else, ignore.

-mark


From: littlechap22 <little...@gmail.com>
To: rhino...@googlegroups.com
Cc: little...@gmail.com
Sent: Wednesday, December 5, 2012 1:31 AM
Subject: [RhinoMocks] rhino mocks, visual studio 2012, c# : setup, configure?

Stephen Bohlen

unread,
Dec 5, 2012, 12:58:27 PM12/5/12
to rhinomocks
This issue is unrelated to RhinoMocks (e.g., there's nothing about RM that would prevent VS2012 from properly displaying your tests in the VS test-runner).  I have three suggestions to explore:

1. Try to create a completely new solution with a single MSTEST test in it and see if VS2012 can properly display that test (should demonstrate/isolate your issue from RhinoMocks)

2. The post you mentioned was re: using MbUnit but you're using the [TestMethod] attribute (from MSTest) in your code -- ensure that you're using the testing framework you think you are

3. Did you build/compile the solution at least once?  AFAIK the VS test-runner reflects over the build assemblies to 'discover' the test methods so you must build/compile the solution/projects at least once for them to properly appear in the VS2012 test-runner.

HTH,

-Steve B.



-littlechap22

--

hesselmann

unread,
Jun 24, 2013, 2:08:38 AM6/24/13
to rhino...@googlegroups.com, little...@gmail.com
The root cause could be the visibility of the test class.

Reason why I raise my point of view is that I could run the two test cases below after make the test class public.



Am Mittwoch, 5. Dezember 2012 08:31:53 UTC+1 schrieb littlechap22:

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]
   public    class Program

cyberwillis

unread,
Jun 24, 2013, 5:24:56 AM6/24/13
to rhino...@googlegroups.com
I don´t know why are you using this:

using SampleRhinoMocksTestingApplication;

Anyway have you referenced the DLL correctly ?


--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rhinomocks+...@googlegroups.com.

To post to this group, send email to rhino...@googlegroups.com.
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages