Ejemplo n.º 1
0
        public async Task ReturnExactCocktailName()
        {
            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,
            };

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

            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);
                var foundBar = await sut.GetBasicDTOAsync(barId);

                Assert.AreEqual(barTestName, foundBar.Name);
            };
        }
Ejemplo n.º 2
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.GetBasicDTOAsync(barId));
            };
        }