Ejemplo n.º 1
0
        /// <summary>
        /// The CreateProduct.
        /// </summary>
        /// <param name="categories">The categories<see cref="IList{Category}"/>.</param>
        /// <returns>The <see cref="Product"/>.</returns>
        public static Product CreateProduct(IList <Category> categories)
        {
            var product = FakeEntityFactory.CreateProduct();

            product.Categories.AddRange(categories);
            return(product);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The CreateFutureAuction.
        /// </summary>
        /// <returns>The <see cref="Auction"/>.</returns>
        private static Auction CreateFutureAuction()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.BeginDate = DateTime.Now.AddDays(1);
            auction.EndDate   = DateTime.Now.AddDays(2);
            auction.Active    = false;
            return(auction);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The CreateActiveAuction.
        /// </summary>
        /// <returns>The <see cref="Auction"/>.</returns>
        private static Auction CreateActiveAuction()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.BeginDate = System.DateTime.Now;
            auction.EndDate   = System.DateTime.Now.AddDays(1);
            auction.Active    = true;
            return(auction);
        }
Ejemplo n.º 4
0
        public void Update_ValidCategory()
        {
            this.mockRepository.Setup(x => x.Update(It.IsAny <Category>()));

            var services = new CategoryService(this.mockRepository.Object);

            var category = FakeEntityFactory.CreateCategory();

            var results = services.Update(category);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 5
0
        public void Insert_ValidBidder()
        {
            this.mockRepository.Setup(x => x.Update(It.IsAny <Bidder>()));

            var services = new BidderService(this.mockRepository.Object);

            var bidder = FakeEntityFactory.CreateBidder();

            bidder.Person = FakeEntityFactory.CreatePerson();

            var results = services.Insert(bidder);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 6
0
        public void Update_ValidSeller()
        {
            this.mockRepository.Setup(x => x.Update(It.IsAny <Seller>()));

            var services = new SellerService(this.mockRepository.Object);

            var seller = FakeEntityFactory.CreateSeller();

            seller.Person = FakeEntityFactory.CreatePerson();

            var results = services.Update(seller);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 7
0
        public void Insert_ValidAuction()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));

            var auctionServices = new AuctionService(this.mockRepository.Object);

            auctionServices.Insert(auction).Should().BeEmpty();
        }
Ejemplo n.º 8
0
        public void Update_NoScores()
        {
            this.mockRepository.Setup(x => x.Update(It.IsAny <Person>()));

            var services = new PersonService(this.mockRepository.Object);

            var person = FakeEntityFactory.CreatePerson();

            person.UserProfile = FakeEntityFactory.CreateUserProfile();

            var results = services.Update(person);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// The CreateActiveAuctionsWithOneCategoryInExcess.
        /// </summary>
        /// <param name="commonCategories">The commonCategories<see cref="List{Category}"/>.</param>
        /// <returns>The <see cref="IList{DomainModel.Auction}"/>.</returns>
        private static IList <DomainModel.Auction> CreateActiveAuctionsWithOneCategoryInExcess(List <Category> commonCategories)
        {
            var limit          = int.Parse(ConfigurationManager.AppSettings.Get("MaxAuctionsStartedAndNotFinalizedForCategory"));
            var activeAuctions = new List <DomainModel.Auction>();

            for (int i = 0; i <= limit; ++i)
            {
                var activeAuction = CreateActiveAuction();
                var product       = FakeEntityFactory.CreateProduct(commonCategories);
                activeAuction.Products.Add(product);
                activeAuctions.Add(activeAuction);
            }

            return(activeAuctions);
        }
Ejemplo n.º 10
0
        public void Update_ChangesInActiveAuctions()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller = FakeEntityFactory.CreateSeller();
            auction.Products.Add(FakeEntityFactory.CreateProduct());

            this.mockRepository.Setup(x => x.GetByID(It.IsAny <object>())).Returns(auction);
            this.mockRepository.Setup(x => x.Update(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Update(auction);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 11
0
        public void Update_ValidProduct()
        {
            this.mockRepository.Setup(x => x.Update(It.IsAny <Product>()));

            var services = new ProductService(this.mockRepository.Object);

            var product = FakeEntityFactory.CreateProduct();

            product.Categories.Add(FakeEntityFactory.CreateCategory());
            product.Sellers.Add(FakeEntityFactory.CreateSeller());

            var results = services.Update(product);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 12
0
        public void Insert_SingleCategory_NoCategoryInExcess()
        {
            var limit   = int.Parse(ConfigurationManager.AppSettings.Get("MaxAuctionsStartedAndNotFinalizedForCategory"));
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            auction.Seller.Auctions = CreateActiveAuctionsWithNoCategoryInExcess().ToList();

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 13
0
        public void Update_MissingRequiredProperty()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller = FakeEntityFactory.CreateSeller();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            auction.Name = null;
            this.mockRepository.Setup(x => x.GetByID(It.IsAny <object>())).Returns(auction);
            this.mockRepository.Setup(x => x.Update(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Update(auction);

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

            Assert.AreEqual(ErrorMessages.NameRequired, res.ErrorMessage);
        }
Ejemplo n.º 14
0
        public void Insert_ValidAuctionPeriod()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());

            auction.BeginDate = DateTime.Now;
            auction.EndDate   = DateTime.Now.AddDays(1);

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 15
0
        public void Insert_InvalidProperty()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            auction.CurrencyName = "MyCoin";
            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

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

            Assert.AreEqual(ErrorMessages.CurrencyNameIsNotValid, res.ErrorMessage);
        }
Ejemplo n.º 16
0
        public void Insert_SellerBanned()
        {
            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);

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

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

            Assert.AreEqual(ErrorMessages.SellerIsBanned, res.ErrorMessage);
        }
Ejemplo n.º 17
0
        public void Insert_LastValidEndDate()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            var auctionMaxPeriodInMonths = int.Parse(ConfigurationManager.AppSettings.Get("AuctionMaxPeriodInMonths"));

            auction.BeginDate = DateTime.Now;
            auction.EndDate   = DateTime.Now.AddMonths(auctionMaxPeriodInMonths).AddDays(-1);

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 18
0
        public void Insert_AuctionWithMultipleCategories_NoCategoryInExcess()
        {
            var auction = FakeEntityFactory.CreateAuction();

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

            auction.Products.Add(FakeEntityFactory.CreateProduct(categories));
            auction.Seller.Auctions = CreateActiveAuctionsWithMultipleCategoriesNoCategoriesInExcess().ToList();

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 19
0
        public void Update_ChangesInExpiredAuctions()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            auction.BeginDate = DateTime.Now.AddDays(-1);
            auction.EndDate   = DateTime.Now;

            this.mockRepository.Setup(x => x.GetByID(It.IsAny <object>())).Returns(auction);
            this.mockRepository.Setup(x => x.Update(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Update(auction);

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

            Assert.AreEqual(ErrorMessages.ChangesNotAllowedInExpiredAuctions, res.ErrorMessage);
        }
Ejemplo n.º 20
0
        public void Insert_TooManyAuctionsStartedAndNotFinalized()
        {
            var auction = FakeEntityFactory.CreateAuction();

            auction.Seller        = FakeEntityFactory.CreateSeller();
            auction.Seller.Person = FakeEntityFactory.CreatePerson();
            auction.Products.Add(FakeEntityFactory.CreateProduct());
            var limit = int.Parse(ConfigurationManager.AppSettings.Get("MaxAuctionsStartedAndNotFinalized"));

            auction.Seller.Auctions = CreateStartedAndNotFinalizedAuctions(limit + 1);

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

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

            Assert.AreEqual(ErrorMessages.TooManyAuctionsStartedAndNotFinalized, res.ErrorMessage);
        }
Ejemplo n.º 21
0
        public void Insert_AuctionWithMultipleCategories_BothCategoriesInExcess()
        {
            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();

            this.mockRepository.Setup(x => x.Insert(It.IsAny <DomainModel.Auction>()));
            var auctionServices = new AuctionService(this.mockRepository.Object);

            var results = auctionServices.Insert(auction);

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

            Assert.AreEqual(ErrorMessages.TooManyAuctionsStartedAndNotFinalizedForCategory, res.ErrorMessage);
        }