Click here to Skip to main content
Rate this: bad
good
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:

Assert.IsInstanceOfType(typeof(ViewResult),result);

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>
    [TestFixture]
    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
                };
                dinners.Add(sampleDinner);
            }
            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;
        }
 
        [Test]
        public void DetailAction_Should_Return_Detailed_View_For_ExistingDinner()
        {
            //Arrange
            var controller = CreateDinnerController();
            //Act
            var result = controller.Details(1) as ViewResult;
 
            //Assert
            Assert.IsInstanceOf <Viewresult>(result);
        }
}
And i've been using Nunit2.6.2 with VWD 2010 Express
Posted 31-Jan-13 19:49pm
Edited 5-Feb-13 18:18pm
v6
Comments
Sergey Alexandrovich Kryukov at 1-Feb-13 1:22am
   
Did you Google it in a different Universe? :-)
—SA

1 solution

Rate this: bad
good
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>:
http://www.nunit.org/index.php?p=typeAsserts&r=2.5.1[^].
 
So, use them, don't use the obsolete.
 
—SA
  Permalink  
v2
Comments
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?
—SA
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...
—SA
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"...
—SA

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

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
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