public async Task PostDeleteShouldReturnRedirectWithValidId() { // Arrange const int idValue = 1; int modelId = 0; var adService = new Mock <IAdminAdService>(); adService .Setup(u => u.Delete(It.IsAny <int>())) .Callback((int id) => { modelId = id; }).Returns(Task.FromResult(true)); var controller = new AdsController(adService.Object); // Act var result = await controller.Delete(idValue); // Assert modelId.Should().Be(idValue); result.Should().BeOfType <string>(); result.Should().Be($"The ad has been succesffuly deleted."); }
public void CanCallDelete() { var ad = new Ad() { Id = 40, Name = "40", Description = "40" }; var mock = new Mock<IAdRepository>(); mock.Setup(c => c.Delete(It.IsAny<int>())).Returns<Ad>(null); mock.Setup(c => c.Get(It.IsAny<int>())).Returns(ad); var controller = new AdsController(mock.Object); controller.Delete(ad.Id); mock.Verify(repo => repo.Delete(It.IsAny<int>()), Times.AtLeastOnce()); }
public void ShouldThrowDuringDeleteIfEntityDoesNotExist() { var mock = new Mock<IAdRepository>(); mock.Setup(c => c.Update(It.IsAny<Ad>(), It.IsAny<int>())).Returns((Ad)null); mock.Setup(c => c.Get(It.IsAny<int>())).Returns((Ad)null); var controller = new AdsController(mock.Object); controller.Delete(1); }