Can't seem to be able to figure out the first part of this nunit test

Hello,

Im struggling to understand what going on in the first part of the test.

[Test]
public void Can_Delete_Product()
{
// Arrange: Given a repository containing some product…
var mockRepository = new Mock<IProductsRepository>();
var product = new Product { ProductID = 24, Name = “P24” };
mockRepository.Setup(x => x.Products).Returns(new[] { product }.AsQueryable());

  // Act: ... when the user tries to delete that product
  var controller = new AdminController(mockRepository.Object);
  var result = controller.Delete(24);

  // Assert: ... then it's deleted, and the user sees a confirmation
  mockRepository.Verify(x =&gt; x.DeleteProduct(product));
  result.ShouldBeRedirectionTo(new { action = "Index" });
  controller.TempData["message"].ShouldEqual("P24 was deleted");

}

Why this ? mockRepository.Setup(x => x.Products).Returns(new { product }.AsQueryable());

It actually tell the products in the repository to return a new product which is asqueryable ? but why?

If anyone with some experience in unit tests could help me i would be glad!

Thanks.

Why? So you can test that your controller redirects to Index and your message is “P24 was deleted” without having to get a working copy of the full stack running. Full stack principally meaning your database setup.