title: Xunit test not working for mongodb service
body: <p>I want to make a small XUnit test but it is not working. (<code>AddTest</code> is working but <code>GetAllRestaurantsCountShouldReturnThree</code> not working. ) </p>
  
  <p>I am new to unit testing and I don't know about Moq and how to use it.</p>
  
  <p>How can I mock my <code>IMongoService</code> and get restaurant count?</p>
  
  <p>MongoService.cs</p>
  
  <pre><code>public class MongoService : IMongoService
  {
  
      private readonly IMongoDatabase _mongoDatabase;
      private readonly IMongoClient _mongoClient;
  
      public MongoService()
      {
          _mongoClient = new MongoClient("mongodb://localhost:27017");
          _mongoDatabase = _mongoClient.GetDatabase("Restaurant");
      }
  
      public List&lt;RestaurantDto&gt; GetAllRestaurants()
      {
          var collection = _mongoDatabase.GetCollection&lt;RestaurantDto&gt;("Restaurant");
          return collection.Find(_ =&gt; true).ToList();
      }
  }
  </code></pre>
  
  <p>MongoServiceTest.cs</p>
  
  <pre><code>public class ReviewServiceTests
  {
      private List&lt;RestaurantDto&gt; _allRestaurants = new List&lt;RestaurantDto&gt;()
      {
          new RestaurantDto() {Name="xxx", ZipCode = "111" },
          new RestaurantDto() {Name="yyy", ZipCode = "222" },
          new RestaurantDto() {Name="zzz", ZipCode = "333" },
      };
  
      [Fact] //Not Working
      public void GetAllRestaurantsCountShouldReturnThree()
      {
  
          var _mongoService = new Mock&lt;IMongoService&gt;();
          _mongoService.Setup(x =&gt; x.GetAll()).Returns(_allRestaurants );
          var count = _mongoService.GetAll(); //GetAll() not seeing
  
          Assert.Equal(count, 3);
  
      }
  
      [Fact] //Working
      public void AddTest()
      {
          Assert.Equal(10, Add(8, 2));
      }
  
      int Add(int a, int b)
      {
          return a + b;
      }
  }
  </code></pre>