public void Invokes_article_repository_to_return_paged_service_result_for_GetAll() { var articleRepoMock = new Mock <IRepository <Article> >(); var articleTagRepoMock = new Mock <IRepository <ArticleTag> >(); var userRepoMock = new Mock <IRepository <User> >(); var tagRepoMock = new Mock <IRepository <Tag> >(); var logMock = new Mock <ILogger <ArticleService> >(); var mapperMock = new Mock <IMapper>(); var fakeArticles = FakeEntityFactory.GenerateFakeArticles(3); const int perPage = 20; const int pageNum = 1; articleRepoMock.Setup(s => s.GetAll( It.IsAny <int>(), It.IsAny <int>()) ).ReturnsAsync(new Models.PaginationResult <Article> { PageNumber = pageNum, ResultsPerPage = perPage, Results = fakeArticles }); var sut = new ArticleService( articleRepoMock.Object, articleTagRepoMock.Object, tagRepoMock.Object, userRepoMock.Object, logMock.Object, mapperMock.Object ); }
/// <summary> /// The CreateActiveAuction. /// </summary> /// <returns>The <see cref="Auction"/>.</returns> private Auction CreateActiveAuction() { var auction = FakeEntityFactory.CreateAuction(); auction.Seller = seller; auction.BeginDate = System.DateTime.Now; auction.EndDate = System.DateTime.Now.AddDays(1); auction.Active = true; return(auction); }
/// <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); }
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); }
/// <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); }
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); }
/// <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); }
public void Insert_AuctionWithSingleCategory_CategoryInExcess_ShouldFail() { SetUpAuction(); var commonCategories = new List <Category> { FakeEntityFactory.CreateCategory() }; product.Categories = commonCategories; auction.Products.Add(product); auction.Seller.Auctions = CreateActiveAuctionsWithOneCategoryInExcess(commonCategories).ToList(); var results = auctionServices.Insert(auction); Assert.AreEqual(1, results.Count); var res = results[0]; Assert.AreEqual(ErrorMessages.TooManyAuctionsStartedAndNotFinalizedForCategory, res.ErrorMessage); }
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); }
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); }
/// <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); }
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(); } }