Пример #1
0
        public void TestAddWithStartDateMoreThanEndDateAuction()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result     = this.auctionUserService.AddAuctionUser(auctionUser, Role.Seller);
            var startPrice = new Price {
                Currency = "Euro", Value = 88.5
            };
            var priceResult = this.priceService.AddPrice(startPrice);
            var category    = new Category {
                Name = "Legume"
            };
            var categoryResult = this.categoryService.AddCategory(category);
            var product        = new Product {
                Name = "Fasole", Category = new[] { category }
            };
            var productResult = this.productService.AddProduct(product);
            var startDate     = DateTime.Now;
            var auction       = new Auction
            {
                Auctioneer = auctionUser,
                Product    = product,
                StartPrice = startPrice,
                StartDate  = startDate.AddDays(5),
                EndDate    = startDate,
                Ended      = false,
            };
            var auctionResult = this.auctionService.AddAuction(auction);

            Assert.True(!this.libraryContextMock.Auctions.Any());
        }
Пример #2
0
        /// <summary>
        /// Check if user has max number of started auction.
        /// </summary>
        /// <param name="auctionUser">The auctionUser.</param>
        /// <returns>If user has max number of started auction.</returns>
        private bool CheckIfUserHasMaxNumberOfStartedAuction(AuctionUser auctionUser)
        {
            var startedAuctions = this.GetStartedAuctionsByUser(auctionUser);
            var k = int.Parse(ConfigurationManager.AppSettings["MAX_NUMBER_OF_AUCTION"]);

            return(startedAuctions.Count() == k);
        }
Пример #3
0
        public void TestAddWithEndDateMoreThanMaxMonthsAuction()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result     = this.auctionUserService.AddAuctionUser(auctionUser, Role.Seller);
            var startPrice = new Price {
                Currency = "Euro", Value = 88.5
            };
            var priceResult = this.priceService.AddPrice(startPrice);
            var category    = new Category {
                Name = "Legume"
            };
            var categoryResult = this.categoryService.AddCategory(category);
            var product        = new Product {
                Name = "Fasole", Category = new[] { category }
            };
            var productResult     = this.productService.AddProduct(product);
            var maxNumberOfMonths = int.Parse(ConfigurationManager.AppSettings["MAX_NUMBER_OF_MONTHS"]);
            var startDate         = DateTime.Now;
            var auction           = new Auction
            {
                Auctioneer = auctionUser,
                Product    = product,
                StartPrice = startPrice,
                StartDate  = startDate,
                EndDate    = startDate.AddMonths(maxNumberOfMonths + 1),
                Ended      = false,
            };
            var auctionResult = this.auctionService.AddAuction(auction);

            Assert.True(!this.libraryContextMock.Auctions.Any());
        }
Пример #4
0
        public void TestAddWithStartPriceLessThanMinPriceAuction()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result   = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);
            var category = new Category {
                Name = "Legume"
            };
            var minPrice   = double.Parse(ConfigurationManager.AppSettings["MIN_PRICE"]);
            var startPrice = new Price {
                Currency = "Euro", Value = minPrice - 1
            };
            var priceResult    = this.priceService.AddPrice(startPrice);
            var categoryResult = this.categoryService.AddCategory(category);
            var product        = new Product {
                Name = "Fasole", Category = new[] { category }
            };
            var productResult = this.productService.AddProduct(product);
            var auction       = new Auction
            {
                Auctioneer = auctionUser,
                Product    = product,
                StartPrice = startPrice,
                StartDate  = DateTime.Now,
                EndDate    = DateTime.Now.AddDays(5),
                Ended      = false,
            };
            var auctionResult = this.auctionService.AddAuction(auction);

            Assert.True(!this.libraryContextMock.Auctions.Any());
        }
Пример #5
0
        public void TestGetAllUserReviewsWithAWrongUser()
        {
            var userReview = new AuctionUser {
                Id = 1, FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var reviewUser = new AuctionUser {
                Id = 2, FirstName = "Popa", LastName = "Andrei", Gender = "M"
            };
            var resultUser1 = this.auctionUserService.AddAuctionUser(userReview, Role.Buyer);
            var resultUser2 = this.auctionUserService.AddAuctionUser(reviewUser, Role.Buyer);
            var user1       = this.auctionUserService.GetAuctionUserByFistNameAndLastName("Ionel", "Pascu");
            var user2       = this.auctionUserService.GetAuctionUserByFistNameAndLastName("Popa", "Andrei");

            var review1 = new UserReview
            {
                Description = "He is a good man", Score = 4, ReviewByUser = user2, ReviewForUser = user1
            };
            var review2 = new UserReview
            {
                Description = null, Score = 2, ReviewByUser = userReview, ReviewForUser = user2
            };
            var resultReview1 = this.userReviewService.AddUserReview(review1);
            var resultReview2 = this.userReviewService.AddUserReview(review2);

            var reviews = this.userReviewService.GetUserReviews();

            Assert.IsFalse(reviews.Count() == 2);
        }
Пример #6
0
        public async Task <IActionResult> JoinAuction(int id, string callBack)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var au = await _db.AuctionHeader.FirstOrDefaultAsync(a => a.Id == id);


            var a_user = new AuctionUser()
            {
                UserId           = claim.Value,
                AuctionId        = id,
                LastPriceOffered = au.CurrentPrice + au.PriceStep
            };

            if (au.CurrentPrice < a_user.LastPriceOffered)
            {
                var outbided_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.AuctionId == au.Id && a.LastPriceOffered == au.CurrentPrice);

                if (outbided_user != null)
                {
                    await NotiApi.SendNotiAuction(_db, "You were outbided, check the auction for more details", outbided_user.UserId, au.Id);
                }
                await NotiApi.SendNotiAuction(_db, "You bid for $" + a_user.LastPriceOffered.ToString("F2") + " in an auction, check the auction for more details", a_user.UserId, au.Id);

                au.CurrentPrice = Math.Max(au.CurrentPrice, a_user.LastPriceOffered);
            }



            _db.AuctionUser.Add(a_user);
            _db.SaveChanges();

            return(RedirectToAction("Details", new{ id = id, status = SD.ActiveStatus, callBack = callBack }));
        }
Пример #7
0
        public async Task Buy_WithCorrectId_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ItemService Buy() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var dummyItemId = "EyePatchId";

            var dummyUser = new AuctionUser
            {
                Id = "Hugo"
            };

            context.Users.Add(dummyUser);

            bool actualResult = await this.itemService.Buy(dummyItemId, dummyUser.Id);

            Assert.True(actualResult, errorMessagePrefix);
        }
Пример #8
0
        public void TestAddLongerDescriptionUserReview()
        {
            var userReview = new AuctionUser {
                Id = 1, FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var reviewUser = new AuctionUser {
                Id = 2, FirstName = "Popa", LastName = "Andrei", Gender = "M"
            };
            var resultUser1 = this.auctionUserService.AddAuctionUser(userReview, Role.Buyer);
            var resultUser2 = this.auctionUserService.AddAuctionUser(reviewUser, Role.Buyer);
            var user1       = this.auctionUserService.GetAuctionUserByFistNameAndLastName("Ionel", "Pascu");
            var user2       = this.auctionUserService.GetAuctionUserByFistNameAndLastName("Popa", "Andrei");

            var review1 = new UserReview
            {
                Description =
                    "bFuDu3e8H7LuEGyZbYTUfxdKm9gweGGho3e8H9m2hlgBHgglrMME0Rf6CI99bdLg1wnSwBj3dKsJ2LpRENQIloUp4m7oj4Xs9mMbxbFuDu3e8H7LuEGyZbYTUfxdKm9gweGGho3e8H9m2hlgBHgglrMME0Rf6CI99bdLg1wnSwBj3dKsJ2LpRENQIloUp4m7oj4Xs9mMbx",
                Score         = 4,
                ReviewByUser  = user2,
                ReviewForUser = user1
            };
            var resultReview1 = this.userReviewService.AddUserReview(review1);

            Assert.True(!this.libraryContextMock.UserReviews.Any());
        }
Пример #9
0
        /// <summary>
        /// Check if user has max number of started auction.
        /// </summary>
        /// <param name="auctionUser">The auctionUser.</param>
        /// <returns>If user has max number of started auction.</returns>
        private bool CheckIfUserCanOpenANewAuction(AuctionUser auctionUser)
        {
            var userScore = this.auctionUserService.GetAuctionUserScore(auctionUser.Id);
            var minScore  = int.Parse(ConfigurationManager.AppSettings["MIN_SCORE"]);

            if (userScore < minScore)
            {
                var     blockDays   = int.Parse(ConfigurationManager.AppSettings["NUMBER_OF_BLOCK_DAYS"]);
                Auction lastAuction = this.GetLastAuctionForUser(auctionUser);
                if (lastAuction != null)
                {
                    var blockUntil = lastAuction.EndDate.AddDays(blockDays);
                    return(DateTime.Compare(lastAuction.EndDate, blockUntil) > 0);
                }
                else
                {
                    LoggerUtil.LogInfo("User doesn't have an auction.", MethodBase.GetCurrentMethod());
                }
            }
            else
            {
                LoggerUtil.LogInfo("User is able to add an new auction.", MethodBase.GetCurrentMethod());
            }

            return(true);
        }
Пример #10
0
        public void TestAddWithNullStartPriceAuction()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result   = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);
            var category = new Category {
                Name = "Legume"
            };
            var categoryResult = this.categoryService.AddCategory(category);
            var product        = new Product {
                Name = "Fasole", Category = new[] { category }
            };
            var productResult = this.productService.AddProduct(product);
            var auction       = new Auction
            {
                Auctioneer = auctionUser,
                Product    = product,
                StartPrice = null,
                StartDate  = DateTime.Now,
                EndDate    = DateTime.Now.AddDays(5),
                Ended      = false,
            };
            var auctionResult = this.auctionService.AddAuction(auction);

            Assert.True(!this.libraryContextMock.Auctions.Any());
        }
        /// <summary>
        /// Get auctionUser score.
        /// </summary>
        /// <param name="id">The auctionUser id.</param>
        /// <returns>Value of user score.</returns>
        public int GetAuctionUserScore(int id)
        {
            AuctionUser user         = this.GetAuctionUserById(id);
            var         userReviews  = this.userReviewService.GetUserReviewsForUser(user);
            var         defaultScore = int.Parse(ConfigurationManager.AppSettings["DEFAULT_SCORE"]);
            var         averageOf    = int.Parse(ConfigurationManager.AppSettings["SCORE_AVERAGE_OF"]);
            var         enumerable   = userReviews.ToList();

            if (enumerable.IsNullOrEmpty())
            {
                return(defaultScore);
            }

            var sum = 0;

            if (enumerable.Count() < averageOf)
            {
                foreach (var review in enumerable)
                {
                    sum += review.Score;
                }

                return(sum / enumerable.Count());
            }
            else
            {
                for (int index = 0; index <= averageOf; index++)
                {
                    sum += enumerable.ToArray()[index].Score;
                }

                return(sum / averageOf);
            }
        }
Пример #12
0
        public void TestAddNullFirstNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = null, LastName = "Pascu", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #13
0
        public void TestAddAuctionUserWithNullRole()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, null);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #14
0
        public void TestAddLowercaseLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Case", LastName = "lower", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #15
0
        public void TestAddDashLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Galusca", LastName = "Aly-Baba", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(this.libraryContextMock.AuctionUsers.Count() == 1);
        }
Пример #16
0
        public void TestAddSymbolLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Horatiu", LastName = "Vlad$@%^@#%$)_*", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #17
0
        public void TestAddDigitLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Fratele", LastName = "Galusca5", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #18
0
        public void TestAddEmptyLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Horatiu", LastName = string.Empty, Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #19
0
        public void TestAddSymbolFirstNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Aly$^@*#^*", LastName = "Baba", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(this.libraryContextMock.AuctionUsers.Count() == 0);
        }
Пример #20
0
        public void TestAddDigitFirstNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Al13Mihai", LastName = "Cioran", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
Пример #21
0
        public void TestAddEmptyGenderAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = string.Empty
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(!this.libraryContextMock.AuctionUsers.Any());
        }
        /// <summary>
        /// Update an AuctionUser.
        /// </summary>
        /// <param name="auctionUser">The AuctionUser.</param>
        /// <returns>If auctionUser was updated.</returns>
        public bool UpdateAuctionUser(AuctionUser auctionUser)
        {
            if (this.ValidateAuctionUser(auctionUser))
            {
                return(this.auctionUserRepository.UpdateAuctionUser(auctionUser));
            }

            return(false);
        }
Пример #23
0
        public void TestAddAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            Assert.True(this.libraryContextMock.AuctionUsers.Count() == 1);
        }
Пример #24
0
        public void ShouldMap_AuctionUser_To_ListAllUsersResponseModel()
        {
            var entity = new AuctionUser();

            var result = this.mapper.Map <ListAllUsersResponseModel>(entity);

            result.Should().NotBeNull();
            result.Should().BeOfType <ListAllUsersResponseModel>();
        }
Пример #25
0
        public void TestGetAuctionUserByGoodId()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result          = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);
            var auctionUserById = this.auctionUserService.GetAuctionUserById(auctionUser.Id);

            Assert.NotNull(auctionUserById);
        }
Пример #26
0
        public void TestGetBadNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            auctionUser = this.auctionUserService.GetAuctionUserByFistNameAndLastName("Ionel", "Teodorescu");
            Assert.Null(auctionUser);
        }
Пример #27
0
        public void TestGetNullLastNameAuctionUser()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Estera", LastName = "Pascu", Gender = "M"
            };
            var result = this.auctionUserService.AddAuctionUser(auctionUser, Role.Buyer);

            auctionUser = this.auctionUserService.GetAuctionUserByFistNameAndLastName(auctionUser.FirstName, null);
            Assert.Null(auctionUser);
        }
Пример #28
0
        public void TestGetLastAuctionForUserWithoutAuctions()
        {
            var auctionUser = new AuctionUser {
                FirstName = "Ionel", LastName = "Pascu", Gender = "M"
            };
            var result2     = this.auctionUserService.AddAuctionUser(auctionUser, Role.Seller);
            var lastAuction = this.auctionService.GetLastAuctionForUser(auctionUser);

            Assert.IsNull(lastAuction);
        }
Пример #29
0
        /// <summary>
        /// Get All Auction started by an specific user.
        /// </summary>
        /// <param name="user">The user what will be checked.</param>
        /// <returns>All Auction started by a user.</returns>
        public IEnumerable <Auction> GetStartedAuctionsByUser(AuctionUser user)
        {
            var auctions         = this.GetAuctions();
            var filteredAuctions =
                from auction in auctions
                where auction.Auctioneer.Id == user.Id && !this.CheckIfAuctionIsEnded(auction)
                select auction;

            return(filteredAuctions);
        }
Пример #30
0
        public async Task <IActionResult> Delete(string name)
        {
            var id = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            AuctionUser user = await this.userService.GetById(id);

            await this.userService.Delete(user.Id, name);

            return(this.RedirectToAction(ProfileDetailsAction));
        }