예제 #1
0
        /// <summary>
        /// The CreateActiveAuctionsWithOneCategoryInExcess.
        /// </summary>
        /// <param name="commonCategories">The commonCategories<see cref="List{Category}"/>.</param>
        /// <returns>The <see cref="IList{Auction}"/>.</returns>
        private IList <Auction> CreateActiveAuctionsWithOneCategoryInExcess(List <Category> commonCategories)
        {
            var limit          = int.Parse(ConfigurationManager.AppSettings.Get("MaxAuctionsStartedAndNotFinalizedForCategory"));
            var activeAuctions = new List <Auction>();

            for (int i = 0; i <= limit; ++i)
            {
                var activeAuction = CreateActiveAuction();
                var product       = FakeEntityFactory.CreateProduct(commonCategories);
                product.Sellers.Add(this.seller);
                activeAuction.Products.Add(product);
                activeAuctions.Add(activeAuction);
            }
            return(activeAuctions);
        }
예제 #2
0
        public void Insert_SellerBanned_ShouldFail()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            auction.Seller.Person.BanEndDate = DateTime.Now.Date.AddDays(1);

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(1, results.Count);
            var res = results[0];

            Assert.AreEqual(ErrorMessages.SellerIsBanned, res.ErrorMessage);
        }
예제 #3
0
        /// <summary>
        /// The CreateStartedAndNotFinalizedAuctions.
        /// </summary>
        /// <param name="n">The n<see cref="int"/>.</param>
        /// <returns>The <see cref="List{Auction}"/>.</returns>
        private List <Auction> CreateStartedAndNotFinalizedAuctions(int n)
        {
            var auctions = new List <Auction>();

            for (int i = 0; i < n; ++i)
            {
                var auction = CreateActiveAuction();
                var product = FakeEntityFactory.CreateProduct();
                product.Categories.Add(FakeEntityFactory.CreateCategory());
                product.Sellers.Add(seller);
                auction.Products.Add(product);
                auctions.Add(auction);
            }

            return(auctions);
        }
예제 #4
0
        public void Insert_AuctionsWithMultipleCategories_NoCategoryInExcess_ShouldNotFail()
        {
            SetUpAuction();

            var categories = new List <Category> {
                FakeEntityFactory.CreateCategory(), FakeEntityFactory.CreateCategory()
            };
            var product = FakeEntityFactory.CreateProduct(categories);

            product.Sellers.Add(seller);
            auction.Products.Add(product);
            auction.Seller.Auctions = CreateActiveAuctionsWithMultipleCategoriesNoCategoriesInExcess().ToList();

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(0, results.Count);
        }
예제 #5
0
        /// <summary>
        /// The CreateActiveAuctionsWithMultipleCategoriesNoCategoriesInExcess.
        /// </summary>
        /// <returns>The <see cref="IList{Auction}"/>.</returns>
        private IList <Auction> CreateActiveAuctionsWithMultipleCategoriesNoCategoriesInExcess()
        {
            var limit          = int.Parse(ConfigurationManager.AppSettings.Get("MaxAuctionsStartedAndNotFinalized"));
            var activeAuctions = new List <Auction>();

            for (int i = 0; i < limit; ++i)
            {
                var categories = new List <Category> {
                    FakeEntityFactory.CreateCategory(), FakeEntityFactory.CreateCategory()
                };
                var product = FakeEntityFactory.CreateProduct(categories);
                product.Sellers.Add(this.seller);
                var activeAuction = CreateActiveAuction();
                activeAuction.Products.Add(product);
                activeAuctions.Add(activeAuction);
            }
            return(activeAuctions);
        }
예제 #6
0
        public void Insert_AuctionWithMultipleCategories_BothCategoriesInExcess_ShouldFail()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            var commonCategories = new List <Category> {
                FakeEntityFactory.CreateCategory(), FakeEntityFactory.CreateCategory()
            };

            auction.Products.Add(FakeEntityFactory.CreateProduct(commonCategories));
            auction.Seller.Auctions = CreateActiveAuctionsWithCategoriesInExcess(commonCategories).ToList();

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(1, results.Count);
            var res = results[0];

            Assert.AreEqual(ErrorMessages.TooManyAuctionsStartedAndNotFinalizedForCategory, res.ErrorMessage);
        }
예제 #7
0
        public void Insert_AuctionsWithMultipleCategories_OneCategoryInExcess_ShouldFail()
        {
            SetUpAuction();

            var commonCategories = new List <Category> {
                FakeEntityFactory.CreateCategory()
            };
            var product = FakeEntityFactory.CreateProduct(commonCategories);

            product.Sellers.Add(this.seller);
            auction.Products = new List <Product> {
                product
            };
            auction.Seller.Auctions = CreateActiveAuctionsWithCategoriesInExcess(commonCategories).ToList();

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(1, results.Count);
            var res = results[0];

            Assert.AreEqual(ErrorMessages.TooManyAuctionsStartedAndNotFinalizedForCategory, res.ErrorMessage);
        }
예제 #8
0
        /// <summary>
        /// The CreateFutureAuction.
        /// </summary>
        /// <returns>The <see cref="Auction"/>.</returns>
        private Auction CreateFutureAuction()
        {
            var userProfile = FakeEntityFactory.CreateUserProfile();
            var person      = FakeEntityFactory.CreatePerson();

            person.Id          = userProfile.Id;
            person.UserProfile = userProfile;

            var product  = FakeEntityFactory.CreateProduct();
            var category = FakeEntityFactory.CreateCategory();

            product.Sellers.Add(this.seller);
            product.Categories.Add(category);

            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller = this.seller;
            auction.Products.Add(product);
            auction.BeginDate = DateTime.Now.AddDays(1);
            auction.EndDate   = DateTime.Now.AddDays(2);
            auction.Active    = false;
            return(auction);
        }
예제 #9
0
        public void Initialize()
        {
            this.userProfile = FakeEntityFactory.CreateUserProfile();
            this.person      = FakeEntityFactory.CreatePerson();
            this.seller      = FakeEntityFactory.CreateSeller();
            this.auction     = FakeEntityFactory.CreateAuction();
            this.bidder      = FakeEntityFactory.CreateBidder();
            this.product     = FakeEntityFactory.CreateProduct();
            this.category    = FakeEntityFactory.CreateCategory();

            this.userProfileServices = new UserProfileService(new UserProfileRepository());
            this.personServices      = new PersonService(new PersonRepository());
            this.bidderServices      = new BidderService(new BidderRepository());
            this.sellerServices      = new SellerService(new SellerRepository());
            this.categoryServices    = new CategoryService(new CategoryRepository());
            this.bidServices         = new BidService(new BidRepository());
            this.productServices     = new ProductService(new ProductRepository());
            this.auctionServices     = new AuctionService(new AuctionRepository());

            using (var auctionDBContext = new AuctionDBContext())
            {
                auctionDBContext.Database.Delete();
            }
        }