public async Task ValidateBeer_GivenABeerWithAnInvalidBreweryId_ShouldThrowAHttpExceptionWithCorrectMessage() { //Arrange var beer = new Beer { Name = "Test name", Brewery = new Brewery { Id = Guid.NewGuid() } }; var expectedValidationMessage = "A beer must always be linked to an existing brewery"; var mockedBrandDataAccess = new Mock <IBrandDataAccess>(); mockedBrandDataAccess.Setup(dataAccess => dataAccess.GetBrewery(It.IsAny <Guid>())) .ReturnsAsync((BreweryEntity)null); var brandValidation = new BrandValidation(mockedBrandDataAccess.Object); //Act try { await brandValidation.ValidateBeer(beer); } catch (HttpException e) { //Assert Assert.Equal(HttpStatusCode.BadRequest, e.StatusCode); Assert.Equal(expectedValidationMessage, e.Message); } }
public async Task ValidateBeer_GivenABeerWithAnEmptyBreweryId_ShouldThrowAHttpExceptionWithCorrectMessage() { //Arrange var beer = new Beer { Name = "Test name", Brewery = new Brewery { Id = Guid.Empty } }; var expectedValidationMessage = "A beer must always have a brewery"; var brandValidation = new BrandValidation(null); //Act try { await brandValidation.ValidateBeer(beer); } catch (HttpException e) { //Assert Assert.Equal(HttpStatusCode.BadRequest, e.StatusCode); Assert.Equal(expectedValidationMessage, e.Message); } }
public async Task ValidateBeer_GivenAValidBeer_ShouldNotThrowAnyException() { //Arrange var beer = new Beer { Name = "Test name", Brewery = new Brewery { Id = Guid.NewGuid() } }; var mockedBrandDataAccess = new Mock <IBrandDataAccess>(); mockedBrandDataAccess.Setup(dataAccess => dataAccess.GetBrewery(It.IsAny <Guid>())) .ReturnsAsync(new BreweryEntity()); var brandValidation = new BrandValidation(mockedBrandDataAccess.Object); //Act await brandValidation.ValidateBeer(beer); //Assert mockedBrandDataAccess.Verify(dataAccess => dataAccess.GetBrewery(It.IsAny <Guid>()), Times.Once); }
public async Task ValidateBeer_GivenNoBreweryId_ShouldReturnAValidationResultWithExpectedErrorMessage() { //Arrange var guid = Guid.NewGuid(); var beer = new Beer { BreweryId = Guid.Empty }; var expectedErrorMessage = "A beer must always be linked to a brewery"; var brandValidation = new BrandValidation(null); //Act var results = await brandValidation.ValidateBeer(beer); //Assert Assert.Contains(results, result => result.ErrorMessage.Equals(expectedErrorMessage)); }
public async Task ValidateBeer_GivenValidBreweryId_ShouldReturnAllValidationResultsSuccessful() { //Arrange var guid = Guid.NewGuid(); var beer = new Beer { BreweryId = guid }; var mockedBrandQuery = new Mock <IBrandQuery>(); mockedBrandQuery.Setup(query => query.GetBrewery(It.IsAny <Guid>())) .ReturnsAsync(new Brewery()); var brandValidation = new BrandValidation(mockedBrandQuery.Object); //Act var results = await brandValidation.ValidateBeer(beer); //Assert Assert.True(results.All(result => result == ValidationResult.Success)); }
public async Task ValidateBeer_GivenAnInvalidBreweryId_ShouldReturnAValidationResultWithExpectedErrorMessage() { //Arrange var guid = Guid.NewGuid(); var beer = new Beer { BreweryId = guid }; var expectedErrorMessage = "A beer must always be linked to an existing brewery"; var mockedBrandQuery = new Mock <IBrandQuery>(); mockedBrandQuery.Setup(query => query.GetBrewery(It.IsAny <Guid>())) .ReturnsAsync((Brewery)null); var brandValidation = new BrandValidation(mockedBrandQuery.Object); //Act var results = await brandValidation.ValidateBeer(beer); //Assert Assert.Contains(results, result => result.ErrorMessage.Equals(expectedErrorMessage)); }