public void WhenGettingAll_ShouldReturnAllAds() { // Arrange var ads = new List <Ad> { new Ad { Id = 1, Name = "WWDC" }, new Ad { Id = 2, Name = "MWC" }, }; _dbContext.Ads.AddRange(ads); _dbContext.SaveChanges(); // Act var actual = _adsController.GetAll(); // Assert actual.Value.Should().BeEquivalentTo(new AdsListRepresentation(new List <AdRepresentation> { new AdRepresentation { Id = 1, Name = "WWDC", Href = "~/api/v1/ads/1", Rel = "ads" }, new AdRepresentation { Id = 2, Name = "MWC", Href = "~/api/v1/ads/2", Rel = "ads" } }, 2, LinkTemplates.V1.Ads.GetAds.CreateLink()) ); }
public void CanCallGetAll() { var ads = new List<Ad>() { new Ad() { Id = 1, Name = "1", Description = "1"}, new Ad() { Id = 2, Name = "2", Description = "2"} }.AsQueryable(); var mock = new Mock<IAdRepository>(); mock.Setup(c => c.GetAll()).Returns(ads); //mock.Setup(x => x.GetCustomerTotal(It.IsAny<int>())).Returns(25.5); var controller = new AdsController(mock.Object); var results = controller.GetAll(); Assert.IsTrue(results.Count() > 1); Assert.IsTrue(results.First().Id == 1); Assert.IsTrue(results.Last().Description == "2"); }