示例#1
0
        public async Task CreateCocktailCorrectly()
        {
            //Arrange
            var options = TestUtilities.GetOptions(nameof(CreateCocktailCorrectly));

            var ingredientServiceMock   = new Mock <ICocktailIngredientService>();
            var cocktailMapperToDTOMock = new Mock <IDTOServiceMapper <CocktailDTO, Cocktail> >();
            var cocktailMapperMock      = new Mock <IDTOServiceMapper <Cocktail, CocktailDTO> >();
            var commentMapperToDTOMock  = new Mock <IDTOServiceMapper <CommentDTO, CocktailComment> >();
            var commentMapperMock       = new Mock <IDTOServiceMapper <CocktailComment, CommentDTO> >();
            var addCocktailMapperMock   = new Mock <IDTOServiceMapper <Cocktail, AddCocktailDTO> >();
            var cocktailRatingToDTOMock = new Mock <IDTOServiceMapper <RatingDTO, CocktailRating> >();

            var cocktailDTOMock           = new Mock <CocktailDTO>();
            var cocktailIngredientDTOMock = new Mock <List <CocktailIngredientDTO> >();
            var cocktailMock = new Mock <Cocktail>();

            cocktailDTOMock.Object.Ingredients = cocktailIngredientDTOMock.Object;
            //Act
            cocktailMapperToDTOMock.Setup(m => m.MapFrom(It.IsAny <CocktailDTO>())).Returns(cocktailMock.Object);

            using (var actContext = new IriOnCocktailServiceDbContext(options))
            {
                var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object);

                await sut.CreateCocktail(cocktailDTOMock.Object);
            }

            using (var assertContext = new IriOnCocktailServiceDbContext(options))
            {
                Assert.AreEqual(1, assertContext.Cocktails.Count());
            }
        }
        public async Task Throw_Exception_When_Cocktail_IsNull()
        {
            var options = Utils.GetOptions(nameof(Throw_Exception_When_Cocktail_IsNull));

            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailService(assertContext);
                await Assert.ThrowsExceptionAsync <ArgumentNullException>
                    (async() => await sut.CreateCocktail(null));
            }
        }
示例#3
0
        public async Task CreateCocktail_ThrowWhenDTOIsNull()
        {
            //Arrange
            var options = TestUtilities.GetOptions(nameof(CreateCocktail_ThrowWhenDTOIsNull));

            var ingredientServiceMock   = new Mock <ICocktailIngredientService>();
            var cocktailMapperToDTOMock = new Mock <IDTOServiceMapper <CocktailDTO, Cocktail> >();
            var cocktailMapperMock      = new Mock <IDTOServiceMapper <Cocktail, CocktailDTO> >();
            var commentMapperToDTOMock  = new Mock <IDTOServiceMapper <CommentDTO, CocktailComment> >();
            var commentMapperMock       = new Mock <IDTOServiceMapper <CocktailComment, CommentDTO> >();
            var addCocktailMapperMock   = new Mock <IDTOServiceMapper <Cocktail, AddCocktailDTO> >();
            var cocktailRatingToDTOMock = new Mock <IDTOServiceMapper <RatingDTO, CocktailRating> >();

            using (var actContext = new IriOnCocktailServiceDbContext(options))
            {
                var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object);

                await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.CreateCocktail(null));
            }
        }
        public async Task Create_Correct_Cocktail()
        {
            var options = Utils.GetOptions(nameof(Create_Correct_Cocktail));

            using (var arrangeContext = new CMContext(options))
            {
                var sut         = new CocktailService(arrangeContext);
                var cocktailDTO = await sut.CreateCocktail(
                    new CocktailDTO
                {
                    Id          = Guid.Parse("9ef97551-87f6-40ce-a88b-6c0e876ccb51"),
                    Name        = "Margarita",
                    Description = "The Margarita is one of the most popular cocktails " +
                                  "in North America—for good reason. Combining the tang of lime and " +
                                  "the sweetness of orange liqueur with the distinctive strength of " +
                                  "tequila, our classic Margarita strikes all of the right keys."
                });
            }

            using (var assertContext = new CMContext(options))
            {
                Assert.AreEqual("Margarita", assertContext.Cocktails.First().Name);
            }
        }