title: System.ArgumentNullException : Value cannot be null in unit test - C#
body: <p>I'm getting this error when I run the unit test: 
  <code>Error Message:
   System.ArgumentNullException : Value cannot be null.
  Parameter name: logger</code> and also I'm getting this warning: 
  <code>Field 'OrderControllerTest._logger' is never assigned to, and will always have its default value null</code></p>
  
  <p>Is there a way to silence the logger or test it?</p>
  
  <p>Still new to programming and eager to learn. Have struggled with this for a long time. Appreciate your help and guidance.</p>
  
  <p><strong>Update with stack trace</strong></p>
  
  <pre><code>Stack Trace:
     at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
     at Microsoft.Extensions.Logging.LoggerExtensions.LogError(ILogger logger, Exception exception, String message, Object[] args)
     at Project.Controllers.OrderController.CustomerOrders(String customerId) in C:\projects\Project\Controllers\OrderController.cs:line 34
     at Tests.OrderControllerTest.AllOrdersForCustomer() in C:\projects\UnitTests\Project.Service.Tests\OrderControllerTest.cs:line 74
  </code></pre>
  
  <p>What I have so far:</p>
  
  <p>OrderControllerTest.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using NUnit.Framework;
  using Project.Models;
  using Project.Controllers;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  
  namespace Tests
  {
    [TestFixture]
    public class OrderControllerTest
    {
        ILogger&lt;OrderController&gt; _logger;
  
        public OrderControllerTest()
        {
  
        }
  
        [Test]
        public void AllOrdersForCustomer()
        {
          // Arrange
          var controller  = new OrderController(_logger);
          var expectedResult = new List&lt;Order&gt;();
          var oneOrder = new Order()
          {
              orderId = 228, 
              product= "Jeans",
              status = "Ready for shipping",
              price= 20$
          };
  
          var twoOrder = new Order()
          {
              caseId = 512, 
              creditorName = "Basketball",
              status = "Shipped",
              totalOpenBalance = 30$
          };
          expectedResult.Add(oneOrder);
          expectedResult.Add(twoOrder);
  
          // Act
          var actionResult = controller.CustomerOrders("1243");
          var result = (List&lt;Order&gt;)actionResult;
  
          // Assert
          for (var i = 0; i &lt; result.Count; i++)
          {               
            CollectionAssert.AreEqual(expectedResult, result);
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>OrderController.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Project.Models;
  using Project.Repositories;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  
  
  namespace Project.Controllers
  {
    public class OrderController : Controller
    {
      ILogger&lt;OrderController&gt; _logger;
  
      public OrderController(ILogger&lt;OrderController&gt; logger)
      {
          _logger = logger;
      }
  
      [HttpGet("customers/{customerId}/orders")]
      public List&lt;Order&gt; CustomerOrders(string customerId)
      {
          try
          {
              return OrderRepository.AllOrders(customerId);
          }
          catch (Exception ex)
          {
              _logger.LogError(ex, "Cant retrieve no orders.");
              return null;
          }
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <pre><code> ILogger&lt;OrderController&gt; _logger;
  
   public OrderControllerTest()
   {
      _logger = new Mock&lt;ILogger&lt;OrderController&gt;&gt;().Object;  
   }
  </code></pre>
  
  <hr>
  
  <p>OrderRepository.cs:</p>
  
  <pre><code>    public static List&lt;Order&gt; AllOrders(string customerId)
      {
          var orderlist = new List&lt;Order&gt;();
  
  
          if (Order!=null &amp;&amp; Order.Count&gt;0)
          {
              if (Order.TryGetValue(customerId, out orderlist))
                  return orderlist;
          }
          return FromDB(customerId);
  
      }
  </code></pre>