Null reference on user identity
<p>I am new to writing a unit test case. I am getting error on <code>User.Identity</code>. I saw mocking is the resolution for that and I tried which is not working in my case. I have added my code</p>

<p>My Controller</p>

<pre><code>public ActionResult CreateStage ( EnthiranStageViewModel enthiranStage )
{
    if ( ModelState.IsValid )
    {
        Stage stage = enthiran.Insert_Stage(enthiranStage);
        //logging Stage Creation
        util.ApplicationLog(new ViewModel.Logs.ApplicationLogViewModel
        {
         GameCategorys = GameCategory.Enthiran,
         Event = Events.EnthiranStageCreation,
         SessionAttemptId = null,
         UserId = User.Identity.GetUserId&lt;int&gt;( ),
         OptionalParameter1 = enthiranStage.GameId,
         OptionalParameter2 = stage.Id,
         Description = "Enthiran stage created"
        });
        return RedirectToAction("Stages", new
        {
            id = stage.GameId
        });
    }
    return View( );
}
</code></pre>

<p>and below is my test case</p>

<pre><code>[TestMethod( )]
public void createStage ( )
{
    EnthiranStageViewModel enthiranStage = new EnthiranStageViewModel
    {
        StageType=0,
        TriggerBeginType = Akton.Areas.Challenge.Models.TriggerType.Manual,
        TriggerEndType= Akton.Areas.Challenge.Models.TriggerType.Manual,
        TimeLimit = new TimeSpan(9, 6, 13),
        TriggerBeginTime= new DateTime(2016, 09, 3, 9, 6, 13),
        TriggerEndTime= new DateTime(2016, 09, 3, 9, 6, 13),
        StartValueType= Akton.Areas.Challenge.Models.StartValueType.Global,
        StageDate= new DateTime(2016, 09, 3, 9, 6, 13),
        Proforma=25,
        GameId=19,
        CreatedTime=new DateTime(2016, 09, 3, 9, 6, 13),
        UpdatedTime= new DateTime(2016, 09, 3, 9, 6, 13),
        StageName="Test",

    };
    EnthiranController controller = new EnthiranController( );
    JsonResult actual = controller.CreateStage(enthiranStage) as JsonResult;
    var result = actual.Data;
    Assert.AreEqual("{ success = True }", result.ToString( ));
}
</code></pre>

<p>Here I have to pass the <code>userId</code> in the <code>ViewModel.Logs.ApplicationLogViewModel</code>, I have no idea how to do that. </p>

<p>How do I get the <code>userId</code> which is passing through <code>applicationLogViewModel</code>?</p>