public void GivenNegativeOrZeroCategoryId_ShouldReturnEmptyCollection(int categoryId) { var repo = new List <ProductCategory>(); var randomNumber = new Random(); var currentRepoSize = randomNumber.Next(10, 100); for (int i = 0; i < currentRepoSize; i++) { repo.Add(new ProductCategory() { CategoryId = randomNumber.Next(10, 20), ProductId = randomNumber.Next(1, 2), }); } // Arange var mappingRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >(); mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); // Act var cut = new ProductCategoryMappingsApiService(mappingRepo); var result = cut.GetMappings(categoryId: categoryId); // Assert Assert.IsEmpty(result); }
public void GivenNonEmptyValidRepositoryWithMoreThanTheMaxItems_ShouldReturnDefaultLimitItems() { var repo = new List <ProductCategory>(); var randomNumber = new Random(); var currentRepoSize = Configurations.MaxLimit * 2; for (int i = 0; i < currentRepoSize; i++) { repo.Add(new ProductCategory() { CategoryId = randomNumber.Next(10, 20), ProductId = randomNumber.Next(1, 2), }); } // Arange var mappingRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >(); mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); // Act var cut = new ProductCategoryMappingsApiService(mappingRepo); var result = cut.GetMappings(); // Assert Assert.IsNotEmpty(result); Assert.AreEqual(Configurations.DefaultLimit, result.Count); }
public void GivenPositiveProductId_ShouldReturnCollectionContainingAllMappingsWithThisProductId() { var repo = new List <ProductCategory>(); var randomNumber = new Random(); var productId = 1; repo.Add(new ProductCategory() { CategoryId = randomNumber.Next(10, 20), ProductId = productId, }); // Arange var mappingRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >(); mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); // Act var cut = new ProductCategoryMappingsApiService(mappingRepo); var result = cut.GetMappings(productId: productId); // Assert Assert.IsTrue(result.Select(x => new { x.CategoryId, x.ProductId }) .SequenceEqual(repo.Where(x => x.ProductId == productId).Select(x => new { x.CategoryId, x.ProductId }))); }
public void GivenEmptyRepository_ShouldReturnEmptyCollection() { var repo = new List <ProductCategory>(); // Arange var mappingRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >(); mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); // Act var cut = new ProductCategoryMappingsApiService(mappingRepo); var result = cut.GetMappings(); // Assert Assert.IsEmpty(result); }
public void GivenPositiveCategoryId_ShouldReturnCollectionContainingAllMappingsWithThisCategoryId() { var repo = new List <ProductCategory>(); var randomNumber = new Random(); var currentRepoSize = randomNumber.Next(51, 100); for (int i = 0; i < currentRepoSize; i++) { repo.Add(new ProductCategory() { CategoryId = randomNumber.Next(1, 2), ProductId = randomNumber.Next(10, 20), }); } var categoryId = 1; repo.Add(new ProductCategory() { CategoryId = categoryId, ProductId = randomNumber.Next(10, 20), }); // Arange var mappingRepo = MockRepository.GenerateStub <IRepository <ProductCategory> >(); mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); // Act var cut = new ProductCategoryMappingsApiService(mappingRepo); var result = cut.GetMappings(categoryId: categoryId); // Assert Assert.IsTrue(result.Select(x => new { x.CategoryId, x.ProductId }) .SequenceEqual(repo.Where(x => x.CategoryId == categoryId).Take(Configurations.DefaultLimit).Select(x => new { x.CategoryId, x.ProductId }))); }