Click here to Skip to main content
11,789,350 members (46,905 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MVC UnitTesting
I was trying the NerdDinner in mvc 4 and at the particular code below:


i am getting an error
NUnit.Framework.Assert.IsInstanceOfType(System.Type, object)' is obsolete

Because of this unit tests are failing and are throwing a Null Exception

i've tried the internet and have not got any answer, please help

ohk this isthe test case im using....

namespace NerdDinnerTests
    /// <summary>
    /// Summary description for DinnerControllerTest
    /// </summary>
    public class DinnerControllerTest
        List < dinner >  CreateTestDinner()
            List< dinner> dinners = new List&ltdinner&gt();
            for (int i = 0; i < 101; i++)
                Dinner sampleDinner = new Dinner()
                    DinnerID = i,
                    Title = "New Title",
                    EventDate = DateTime.Now,
                    Description = "Something",
                    HostedBy = "SomeUser",
                    ContactPhone = "0120-2533244",
                    Address = "Somewhere",
                    Country = "India",
                    Latitude = 93,
                    Longitude = -92
            return dinners; 
        DinnerController CreateDinnerController()
            var repository = new NerdDinnerTests.Fake.FakeDinnerRepository(CreateTestDinner());
            return new DinnerController(repository);
        DinnerController CreateDinnerControllerAs(string userName)
            var mock = new Mock<controllercontext>();
            mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns(userName);
            mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            var controller = CreateDinnerController();
            controller.ControllerContext = mock.Object;
            return controller;
        public void DetailAction_Should_Return_Detailed_View_For_ExistingDinner()
            var controller = CreateDinnerController();
            var result = controller.Details(1) as ViewResult;
            Assert.IsInstanceOf <Viewresult>(result);
And i've been using Nunit2.6.2 with VWD 2010 Express
Posted 31-Jan-13 18:49pm
Edited 5-Feb-13 17:18pm
Sergey Alexandrovich Kryukov at 1-Feb-13 1:22am
Did you Google it in a different Universe? :-)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This method is declared obsolete, because, after introduction of generics as early as of .NET v.2.0, non-generic methods depending on types simply make no sense, they are just too bad next to generic ones.

Beginning with NUnit 2.5, generic equivalents are available: IsInstanceOf<T>, IsNotInstanceOf<T>, IsAssignableFrom<T> and IsNotAssignableFrom<T>:[^].

So, use them, don't use the obsolete.

sarahnimy at 1-Feb-13 1:45am
even after using IsInstanceof, my unit tests are not working, as in gives a null exception, eventhouch i've been using Moq
Sergey Alexandrovich Kryukov at 1-Feb-13 1:49am
Well, then you need to provide sufficient information to solve this problem. Maybe, this is just the case when the test revealed a bug... Or, did you simply use the debugger to see what exactly is going wrong?
Sergey Alexandrovich Kryukov at 1-Feb-13 1:50am
If you say "because of this", you probably know something which we cannot see, because you did not share enough information...
Sergey Alexandrovich Kryukov at 1-Feb-13 2:00am
Look, at least move it to the body of the question, to make it readable. Use "Improve question"...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 929
1 Maciej Los 765
2 KrunalRohit 666
3 CPallini 606
4 Richard MacCutchan 420

Advertise | Privacy | Mobile
Web04 | 2.8.1509028.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100