Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to Asp.NET MVC Admin area route unite test with telerik just mock lite.But I cant test.

Here is My Trying Code:

C#
[TestMethod]
 public void AdminRouteUrlIsRoutedToHomeAndIndex()
 {
     //spts.saglik.gov.tr/admin
     //create route collection
     var routes = new RouteCollection();

     var areaRegistration = new AdminAreaRegistration();
     Assert.AreEqual("Admin",areaRegistration.AreaName);

     // Get an AreaRegistrationContext for my class. Give it an empty RouteCollection
     var areaRegistrationContext = new AreaRegistrationContext(areaRegistration.AreaName, routes);
     areaRegistration.RegisterArea(areaRegistrationContext);

     // Mock up an HttpContext object with my test path (using Moq)
     var context = Mock.Create<HttpContext>();
     context.Arrange(c=>c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/Admin");

     // Get the RouteData based on the HttpContext
     var routeData = routes.GetRouteData(context.Request.RequestContext.HttpContext);

     //assert has route
     Assert.IsNotNull(routeData,"route config");

 }


When
C#
var context = Mock.Create<HttpContext>();
just mock tells this error

C#
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.Web.HttpContext'. JustMock Lite can only mock interface members, virtual/abstract members in non-sealed classes, delegates and all members on classes derived from MarshalByRefObject on instances created with Mock.Create or Mock.CreateLike. For any other scenario you need to use the full version of JustMock.


So How can I do area registration route unit test with telerik just mock lite? How can I Solve this issue?

Thanks a lot.

What I have tried:

C#
var routes = new RouteCollection();

        var areaRegistration = new AdminAreaRegistration();
        Assert.AreEqual("Admin",areaRegistration.AreaName);

        // Get an AreaRegistrationContext for my class. Give it an empty RouteCollection
        var areaRegistrationContext = new AreaRegistrationContext(areaRegistration.AreaName, routes);
        areaRegistration.RegisterArea(areaRegistrationContext);

        // Mock up an HttpContext object with my test path (using Moq)
        var context = Mock.Create<httpcontext>();
        context.Arrange(c=>c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/Admin");

        // Get the RouteData based on the HttpContext
        var routeData = routes.GetRouteData(context.Request.RequestContext.HttpContext);

        //assert has route
        Assert.IsNotNull(routeData,"route config");</httpcontext>
Posted
Updated 10-May-16 0:23am
v2

1 solution

Unit Testing is for testing your own code, not code from third parties. You are just going to have to assume that Microsoft have tested that code themselves and that the code works. It's a fundamental principal of development.
 
Share this answer
 

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