Click here to Skip to main content
15,868,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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....

C#
namespace NerdDinnerTests
{
    /// <summary>
    /// Summary description for DinnerControllerTest
    /// </summary>
    [TestFixture]
    public class DinnerControllerTest
    {
        List < dinner >  CreateTestDinner()
        {
            List< dinner> dinners = new List<dinner>();
            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
Updated 5-Feb-13 17:18pm
v6
Comments
Sergey Alexandrovich Kryukov 1-Feb-13 1:22am    
Did you Google it in a different Universe? :-)
—SA

1 solution

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
 
Share this answer
 
v2
Comments
scarletwitch1990 1-Feb-13 1:45am    
even after using IsInstanceof<t>, my unit tests are not working, as in gives a null exception, eventhouch i've been using Moq
Sergey Alexandrovich Kryukov 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900