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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }