public async Task ValidateBeerExists_GivenANonExisting_ShouldThrowAHttpExceptionWithCorrectMessage() { //Arrange var beerId = Guid.NewGuid(); var expectedValidationMessage = "The beer does not exist"; var mockedBrandDataAccess = new Mock <IBrandDataAccess>(); mockedBrandDataAccess.Setup(dataAccess => dataAccess.GetBeer(It.IsAny <Guid>())) .ReturnsAsync((BeerEntity)null); var brandValidation = new BrandValidation(mockedBrandDataAccess.Object); //Act try { await brandValidation.ValidateBeerExists(beerId); } catch (HttpException e) { //Assert Assert.Equal(HttpStatusCode.BadRequest, e.StatusCode); Assert.Equal(expectedValidationMessage, e.Message); } }
public async Task ValidateBeerExists_GivenAValidBeer_ShouldNotThrowAnyException() { //Arrange var beerId = Guid.NewGuid(); var mockedBrandDataAccess = new Mock <IBrandDataAccess>(); mockedBrandDataAccess.Setup(dataAccess => dataAccess.GetBeer(It.IsAny <Guid>())) .ReturnsAsync(new BeerEntity()); var brandValidation = new BrandValidation(mockedBrandDataAccess.Object); //Act await brandValidation.ValidateBeerExists(beerId); //Assert mockedBrandDataAccess.Verify(dataAccess => dataAccess.GetBeer(It.IsAny <Guid>()), Times.Once); }