예제 #1
0
        private async Task CreateSellMeUserFavoriteProductAsync(int adId, string currentUserId)
        {
            var sellMeUserFavoriteProduct = new SellMeUserFavoriteProduct
            {
                AdId         = adId,
                SellMeUserId = currentUserId
            };

            await context.SellMeUserFavoriteProducts.AddAsync(sellMeUserFavoriteProduct);

            await context.SaveChangesAsync();
        }
예제 #2
0
        public async Task RemoveFromFavoritesAsync_WithExistingAdInFavorites_ShouldReturnTrue()
        {
            //Arrange
            var context = InitializeContext.CreateContextForInMemory();

            var moqUserService = new Mock <IUsersService>();

            moqUserService.Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(new SellMeUser
            {
                Id       = Guid.NewGuid().ToString(),
                UserName = "******",
                SellMeUserFavoriteProducts = new List <SellMeUserFavoriteProduct>
                {
                    new SellMeUserFavoriteProduct
                    {
                        AdId = 1
                    }
                }
            });

            favoritesService = new FavoritesService(context, moqUserService.Object);
            var testingAd = new Ad
            {
                Id                = 1,
                Title             = "Iphone 6s",
                Description       = "PerfectCondition",
                ActiveFrom        = DateTime.UtcNow,
                ActiveTo          = DateTime.UtcNow.AddDays(30),
                AvailabilityCount = 1,
                Price             = 120,
                Condition         = new Condition {
                    Name = "Brand New"
                },
                Address = new Address
                {
                    Country      = "Bulgaria",
                    City         = "Sofia",
                    Street       = "Ivan Vazov",
                    District     = "Student city",
                    ZipCode      = 1000,
                    PhoneNumber  = "0895335532",
                    EmailAddress = "*****@*****.**"
                }
            };

            var sellMeUserFavoriteProduct = new SellMeUserFavoriteProduct
            {
                AdId         = 1,
                SellMeUserId = moqUserService.Object.GetCurrentUserAsync().Result.Id
            };

            await context.SellMeUserFavoriteProducts.AddAsync(sellMeUserFavoriteProduct);

            await context.Ads.AddAsync(testingAd);

            await context.SaveChangesAsync();

            //Act
            var actual = await favoritesService.RemoveFromFavoritesAsync(1);

            //Assert
            Assert.True(actual);
        }