Exemplo n.º 1
0
        public async Task ThrowsExceptionWhen_BarIsDeleted()
        {
            var barFactoryMock         = new Mock <IBarFactory>();
            var barCocktailFactoryMock = new Mock <IBarCocktailFactory>();

            var imagaUrlTest = "https://www.google.com/";
            var barTestName  = "NameTest";

            var addressTest = new Address
            {
                Name = "AddressTest",
                City = new City {
                    Name = "SofiaTest"
                },
                Latitude  = 1.1,
                Longitude = 1.1
            };

            var barTest = new Bar
            {
                Name      = barTestName,
                ImagePath = imagaUrlTest,
                Address   = addressTest,
                IsDeleted = true
            };

            var options = TestUtilities.GetOptions(nameof(ThrowsExceptionWhen_BarIsDeleted));

            using (var arrangeContext = new CocktailMagicianDb(options))
            {
                arrangeContext.Bars.Add(barTest);
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CocktailMagicianDb(options))
            {
                var barId = await assertContext.Bars.Where(b => b.Name == barTestName).Select(b => b.Id).FirstAsync();

                var sut = new BarServices(assertContext, barFactoryMock.Object, barCocktailFactoryMock.Object);
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => sut.GetPresentCocktailsAsync(barId));
            };
        }
Exemplo n.º 2
0
        public async Task ReturnCocktailsOfferedInBar()
        {
            var barFactoryMock         = new Mock <IBarFactory>();
            var barCocktailFactoryMock = new Mock <IBarCocktailFactory>();

            var imagaUrlTest = "https://www.google.com/";
            var barTestName  = "NameTest";

            var cocktail1TestName = "Cocktail1Test";
            var cocktail2TestName = "Cocktail2Test";

            var addressTest = new Address
            {
                Name = "AddressTest",
                City = new City {
                    Name = "SofiaTest"
                },
                Latitude  = 1.1,
                Longitude = 1.1
            };

            var barTest = new Bar
            {
                Name      = barTestName,
                ImagePath = imagaUrlTest,
                Address   = addressTest,
            };

            var cocktail1Test = new Cocktail
            {
                Name      = cocktail1TestName,
                ImagePath = imagaUrlTest,
            };
            var cocktail2Test = new Cocktail
            {
                Name      = cocktail2TestName,
                ImagePath = imagaUrlTest,
            };


            var options = TestUtilities.GetOptions(nameof(ReturnCocktailsOfferedInBar));

            using (var arrangeContext = new CocktailMagicianDb(options))
            {
                arrangeContext.BarCocktails.Add(new BarCocktail {
                    Bar = barTest, Cocktail = cocktail1Test
                });
                arrangeContext.Cocktails.Add(cocktail2Test);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new CocktailMagicianDb(options))
            {
                var barId = await assertContext.Bars.Where(b => b.Name == barTestName).Select(b => b.Id).FirstAsync();

                var sut = new BarServices(assertContext, barFactoryMock.Object, barCocktailFactoryMock.Object);

                var listOfCocktails = await sut.GetPresentCocktailsAsync(barId);

                Assert.AreEqual(1, listOfCocktails.Count());
                Assert.IsTrue(listOfCocktails.Any(c => c.Name == cocktail1TestName));
            }
        }