예제 #1
0
        public async Task ReturnUndeletedRecords_IfNotAdmin()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnUndeletedRecords_IfNotAdmin));

            var barList = new List <Bar>();

            for (int i = 1; i <= 20; i++)
            {
                var bar = new Bar()
                {
                    Name       = "BestBar" + i,
                    Rating     = 4,
                    TimesRated = 1,
                    ImageSrc   = null,
                    IsDeleted  = false,
                    Address    = "Street " + i,
                    Country    = "България",
                    District   = "District " + i,
                    Email      = "*****@*****.**",
                    Phone      = "+ " + i + "8888888",
                    Town       = "София",
                    LocationId = null,
                };

                if (i % 2 == 0)
                {
                    bar.IsDeleted = true;
                }

                barList.Add(bar);
            }

            using (var context = new BCcontext(options))
            {
                await context.Bars.AddRangeAsync(barList);

                await context.SaveChangesAsync();
            }

            var mockMapper = new Mock <IBarMapper>();


            mockMapper.Setup((x) => x.MapEntityToDTO(It.IsAny <Bar>()))
            .Returns((Bar b) => new BarDTO()
            {
                Id         = b.Id,
                Name       = b.Name,
                Rating     = b.Rating,
                TimesRated = b.TimesRated,
                ImageSrc   = b.ImageSrc,
                IsDeleted  = b.IsDeleted,
                Address    = b.Address,
                Country    = b.Country,
                District   = b.District,
                Email      = b.Email,
                LocationId = b.LocationId,
                Phone      = b.Phone,
                Town       = b.Town
            });

            var http          = new Mock <IHttpClientFactory>();
            var coctailMapper = new Mock <ICocktailMapper>();

            //Act & Assert
            using (var context = new BCcontext(options))
            {
                var sut    = new BarsService(context, mockMapper.Object, http.Object, coctailMapper.Object);
                var result = await sut.GetAllAsync("0", "20", string.Empty, "asc", false);

                Assert.AreEqual(result.Count(), 10);
                Assert.AreEqual(result.Any(b => b.IsDeleted == true), false);
            }
        }
예제 #2
0
        public async Task ThrowArgumentException_IfParameterIncorect()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ThrowArgumentException_IfParameterIncorect));

            using (var context = new BCcontext(options))
            {
            }

            var mockMapper    = new Mock <IBarMapper>();
            var http          = new Mock <IHttpClientFactory>();
            var coctailMapper = new Mock <ICocktailMapper>();

            //Act & Assert
            using (var context = new BCcontext(options))
            {
                var sut = new BarsService(context, mockMapper.Object, http.Object, coctailMapper.Object);

                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.GetAllAsync("a", "10", string.Empty, "asc", true));

                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.GetAllAsync("0", "a", string.Empty, "asc", true));
            }
        }