Пример #1
0
        public async Task ReturnExactCocktail()
        {
            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(ReturnExactCocktail));

            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.GetDetailedDTOAsync(barId);

                Assert.IsInstanceOfType(foundBar, typeof(BarDetailsDTO));
                Assert.AreEqual(barTestName, foundBar.Name);
            };
        }
Пример #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.GetDetailedDTOAsync(barId));
            };
        }