public async Task AddCocktailToBar_Throws_When_Cocktail_IsAreadyListed()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(AddCocktailToBar_Throws_When_Cocktail_IsAreadyListed));


            var bar = new Bar
            {
                Id      = Guid.NewGuid(),
                Name    = "Cosmos",
                Country = new Country
                {
                    Id   = Guid.NewGuid(),
                    Name = "Bulgaria"
                }
            };

            var cocktail = new Cocktail
            {
                Id   = Guid.NewGuid(),
                Name = "Manhattan",
            };

            var cocktailDTO = new CocktailDTO
            {
                Id   = cocktail.Id,
                Name = cocktail.Name,
            };

            var barCocktail = new BarCocktail
            {
                BarId      = bar.Id,
                CocktailId = cocktail.Id,
            };

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Bars.AddAsync(bar);

                await arrangeContext.Cocktails.AddAsync(cocktail);

                await arrangeContext.BarCocktails.AddAsync(barCocktail);

                await arrangeContext.SaveChangesAsync();
            }


            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext);

                await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => sut.AddCocktailToBar(bar.Id, cocktailDTO.Id));
            }
        }
        public async Task AddCocktailToBar_Adds_Correctly_When_Params_Are_Valid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(AddCocktailToBar_Adds_Correctly_When_Params_Are_Valid));


            var bar = new Bar
            {
                Id      = Guid.NewGuid(),
                Name    = "Cosmos",
                Country = new Country
                {
                    Id   = Guid.NewGuid(),
                    Name = "Bulgaria"
                }
            };

            var cocktail = new Cocktail
            {
                Id   = Guid.NewGuid(),
                Name = "Manhattan",
            };

            var cocktailDTO = new CocktailDTO
            {
                Id   = cocktail.Id,
                Name = cocktail.Name,
            };

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Bars.AddAsync(bar);

                await arrangeContext.Cocktails.AddAsync(cocktail);

                await arrangeContext.SaveChangesAsync();
            }


            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut    = new BarServices(assertContext);
                var result = await sut.AddCocktailToBar(bar.Id, cocktailDTO.Id);

                Assert.AreEqual(1, assertContext.BarCocktails.Count());
                Assert.AreEqual(1, result.BarCocktails.Count());
                Assert.AreEqual(true, result.BarCocktails.ToList()[0].IsListed);
                Assert.IsInstanceOfType(result, typeof(BarDTO));
            }
        }
Ejemplo n.º 3
0
        public async Task ThrowMagicExeption_IfNullValue_Bar_Passed()
        {
            var options = TestUtils.GetOptions(nameof(ThrowMagicExeption_IfNullValue_Bar_Passed));

            var fileService = new Mock <IFileUploadService>();

            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext, fileService.Object);

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.AddCocktailToBar(null, null));
            }
        }
        public async Task AddCocktailToBar_Throws_WhenBarId_IsInvalid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(AddCocktailToBar_Throws_WhenBarId_IsInvalid));

            var cocktailID = Guid.NewGuid();
            var barID      = Guid.NewGuid();

            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.AddCocktailToBar(barID, cocktailID));
            }
        }
Ejemplo n.º 5
0
        public async Task ThrowCorrectMagicExeption_IfNullValue_Bar_Passed()
        {
            var options = TestUtils.GetOptions(nameof(ThrowCorrectMagicExeption_IfNullValue_Bar_Passed));

            var fileService = new Mock <IFileUploadService>();

            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext, fileService.Object);

                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.AddCocktailToBar(new Cocktail {
                    Id = "1", Name = "cocktail"
                }, null));

                Assert.AreEqual("Bar cannot be null!", ex.Message);
            }
        }
Ejemplo n.º 6
0
        public async Task DontAddNew_BarCocktailConnectionInDb_IfThisCocktailAlreadyExistInBar()
        {
            var options = TestUtils.GetOptions(nameof(DontAddNew_BarCocktailConnectionInDb_IfThisCocktailAlreadyExistInBar));

            var fileService = new Mock <IFileUploadService>();
            var bar         = new Bar
            {
                Id           = "112",
                Name         = "Bar",
                BarCocktails = new List <BarCocktail>
                {
                    new BarCocktail {
                        BarId = "112", CocktailId = "2"
                    }
                }
            };
            var cocktail = new Cocktail
            {
                Id   = "2",
                Name = "Cocktail"
            };

            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext, fileService.Object);
                assertContext.Bars.Add(bar);
                assertContext.Cocktails.Add(cocktail);

                await sut.AddCocktailToBar(cocktail, bar);


                await assertContext.SaveChangesAsync();

                Assert.AreEqual(1, assertContext.BarCocktails.Count());

                Assert.AreEqual("2", assertContext.BarCocktails
                                .First().CocktailId);
            }
        }
Ejemplo n.º 7
0
        public async Task AddNew_BarCocktailConnectionInDb_WhenValidModelsPassed()
        {
            var options = TestUtils.GetOptions(nameof(AddNew_BarCocktailConnectionInDb_WhenValidModelsPassed));

            var fileService = new Mock <IFileUploadService>();
            var bar         = new Bar
            {
                Id           = "112",
                Name         = "Bar",
                BarCocktails = new List <BarCocktail> {
                    new BarCocktail {
                        BarId = "112", CocktailId = "2"
                    }
                }
            };
            var cocktail = new Cocktail
            {
                Id   = "151",
                Name = "Cocktail"
            };

            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext, fileService.Object);
                assertContext.Bars.Add(bar);
                assertContext.Cocktails.Add(cocktail);

                await sut.AddCocktailToBar(cocktail, bar);


                await assertContext.SaveChangesAsync();

                Assert.AreEqual(2, assertContext.BarCocktails.Count());

                Assert.AreEqual("151", assertContext.BarCocktails
                                .First(x => x.BarId == "112" && x.CocktailId == "151").CocktailId);
            }
        }
        public async Task AddCocktailToBar_Throws_When_BarCocktail_IsNotNull()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(AddCocktailToBar_Throws_When_BarCocktail_IsNotNull));

            var barID      = Guid.NewGuid();
            var cocktailId = Guid.NewGuid();


            var barCocktail = new BarCocktail
            {
                BarId      = barID,
                CocktailId = cocktailId
            };

            var cocktailDTO = new CocktailDTO
            {
                Id   = cocktailId,
                Name = "Manhattan"
            };

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.BarCocktails.AddAsync(barCocktail);

                await arrangeContext.SaveChangesAsync();
            }

            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.AddCocktailToBar(barID, cocktailDTO.Id));
            }
        }