作成操作のコントローラユニットテストを作成しようとしています ユニットからコントローラ作成アクションメソッドを呼び出すために現在のユーザIDを取得できませんテスト機能。 「System.NullReferenceException: 'オブジェクト参照がオブジェクトのインスタンスに設定されていません。」というエラーが表示されます。 "コントローラMVCでの作成/編集操作の試行中C#
[HttpPost]
public ActionResult Create(TransactionCodeEditViewModel TransactionCodeViewModel)
{
TransactionCode transactioncode = new TransactionCode()
{
Number = TransactionCodeViewModel.Number,
Name = TransactionCodeViewModel.Name,
Description= TransactionCodeViewModel.Description,
IsActive = true
};
if (ModelState.IsValid)
{
_TransactionCodeService.Add(transactioncode, User.Identity.Name);
}
else
{
return View();
}
return RedirectToAction("Index");
どのように値をUser.Identity.Nameに渡して機能させるか。