public void Create_Should_Return_Data_For_The_Last_Page() { //arrange var items = new List <Item>(); for (var i = 0; i <= 5; i++) { items.AddRange(TestSeed.GetItemsForTesting()); } var sourceCount = items.Count; var paginationData = new DataTablesOptions { Length = 5, Start = 15 }; //act var result = PagedList <Item> .Create(items.AsQueryable(), paginationData); //assert result.Count.Should().Be(sourceCount - paginationData.Start); result.PageSize.Should().Be(paginationData.Length); result.PageNumber.Should().Be(4); result.TotalCount.Should().Be(sourceCount); }
public async Task CreateAsync_Should_Create_Item() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var itemToAdd = new Item { Name = "Find Princess Leia", AdditionalInformation = "Princess has been abducted, we have to find her!", Completed = false, Deadline = DateTime.Today.AddDays(1), LastUpdated = DateTime.Today, UserId = Guid.NewGuid() }; var totalCount = await context.ToDoItems.CountAsync(); var result = await repository.CreateAsync(itemToAdd); //assert result.Should().NotBeNull(); result.Id.Should().NotBe(Guid.Empty); context.ToDoItems.Count().Should().Be(totalCount + 1); } }
public async Task GetSingleAsync_No_Such_Item_Should_Return_Null() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var result = await repository.GetSingleAsync(Guid.NewGuid()); //assert result.Should().BeNull(); } }
public async Task ItemExistsAsync_ItemDosNotExist_Should_Return_False() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var result = await repository.ItemExistsAsync(Guid.Empty); //assert result.Should().BeFalse(); } }
public async Task FindByAsync_ItemDosNotExist_Should_Return_EmptyCollection() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var result = await repository.FindByAsync(item => item.Name.Equals("Oh my God, Zombies!")); //assert result.Should().BeNullOrEmpty(); } }
public async Task GetAllAsync_Should_Return_All_Entries() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var result = await repository.GetAllAsync(); //assert result.Should().NotBeNullOrEmpty(); result.Count.Should().BeGreaterOrEqualTo(TestSeed.GetItemsForTesting().Count); } }
public async Task FindByAsync_ItemExists_Should_Return_Item() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var result = await repository.FindByAsync(item => item.Completed); //assert result.Should().NotBeNull(); result.Count.Should().Be(1); } }
public async Task ItemExistsAsync_ItemExists_Should_Return_True() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var item = await context.ToDoItems.FirstAsync(); var result = await repository.ItemExistsAsync(item.Id); //assert result.Should().BeTrue(); } }
public async Task GetSingleAsync_Should_Return_Signle_Item() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var itemToFind = await context.ToDoItems.FirstAsync(); var result = await repository.GetSingleAsync(itemToFind.Id); //assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(itemToFind); } }
public async Task DeleteAsync_Should_Remove_Item() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var itemToDelete = await context.ToDoItems.FirstAsync(); var totalItems = await context.ToDoItems.CountAsync(); await repository.DeleteAsync(itemToDelete.Id); //assert context.ToDoItems.Count().Should().Be(totalItems - 1); } }
public void Create_Should_Create_PagedList_With_Data_Only_For_The_First_Page() { //arrange var paginationData = new DataTablesOptions { Length = 3, Start = 0 }; var items = TestSeed.GetItemsForTesting(); //act var result = PagedList <Item> .Create(items.AsQueryable(), paginationData); //assert result.Count.Should().Be(paginationData.Length); result.PageSize.Should().Be(paginationData.Length); result.PageNumber.Should().Be(1); result.TotalCount.Should().Be(items.Count); }
public void HandleDataTablesRequest_OderBy_Name_Desc_Should_Return_Items_Ordered_By_Name_Desc() { //arrange var queryString = "{" + "\"draw\":1," + "\"columns\":" + "[" + "{\"data\":\"id\",\"name\":\"\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}" + ",{\"data\":\"name\",\"name\":\"\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"deadLine\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"lastUpdated\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"completed\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}" + "]," + "\"order\":[{\"column\":1,\"dir\":\"desc\"}],\"start\":0,\"length\":10,\"search\":{\"value\":\"\",\"regex\":false}" + "}"; //act var result = TestSeed.GetItemsForTesting().AsQueryable().HandleDataTablesRequest(queryString); //assert result.Should().BeInDescendingOrder(i => i.Name); }
public async Task UpdateAsync_Should_Update_Item() { using (var context = await InMemoryDbContext.GetContext().SeedDabase(TestSeed.GetItemsForTesting())) { //arrange var repository = new ToDoItemRepository(context); //act var item = await context.ToDoItems.FirstAsync(); item.AdditionalInformation = "New Info"; item.Name = "New Name"; await repository.UpdateAsync(item); //assert var updatedItem = await context.ToDoItems.FirstAsync(); updatedItem.AdditionalInformation.Should().Be(item.AdditionalInformation); updatedItem.Name.Should().Be(item.Name); } }
public void HandleDataTablesRequest_Search_Not_Empty_Should_Return_Items_With_Name_Containing_Search_Term() { //arrange var searchTerm = "Luke"; var queryString = "{" + "\"draw\":2," + "\"columns\":" + "[" + "{\"data\":\"id\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"name\",\"name\":\"\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"deadLine\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"lastUpdated\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}," + "{\"data\":\"completed\",\"name\":\"\",\"searchable\":false,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false}}" + "]," + "\"order\":[{\"column\":0,\"dir\":\"asc\"}],\"start\":0,\"length\":10,\"search\":{\"value\":\"Luke\",\"regex\":false}" + "}"; //act var result = TestSeed.GetItemsForTesting().AsQueryable().HandleDataTablesRequest(queryString); //assert result.Count.Should().BeGreaterOrEqualTo(1); result.First().Name.Should().Contain(searchTerm); }