public async Task DeleteAsync_TemplateWithGivenIdExistsAndItShouldBeDeleted_ReturnsZero() { var id = Guid.Parse("ae674f86-1175-4699-b5b9-702e1ef64d79"); var mapperMock = new Mock <IMapper>(); var templateRepositoryMock = new Mock <ITemplateRepository>(); templateRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>())) .ReturnsAsync(new Template()); var templateService = new TemplateService(templateRepositoryMock.Object, mapperMock.Object); var result = await templateService.DeleteAsync(id); templateRepositoryMock.Verify(x => x.GetAsync(It.IsAny <Guid>()), Times.Once); result.Should().Be(0); }
public async Task DeleteAsync_TemplateDoesNotExists_ThrowsException() { var id = Guid.Parse("ae674f86-1175-4699-b5b9-702e1ef64d79"); var mapperMock = new Mock <IMapper>(); var templateRepositoryMock = new Mock <ITemplateRepository>(); templateRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>())) .ReturnsAsync(value: null); var templateService = new TemplateService(templateRepositoryMock.Object, mapperMock.Object); var exception = await Assert.ThrowsAsync <ServiceException>( () => templateService.DeleteAsync(id)); templateRepositoryMock.Verify(x => x.DeleteAsync(It.IsAny <Guid>()), Times.Never); exception.Code.Should().Be("template_not_found"); }