public async Task CreateAsync_ValidData_Successful() { // Arrange Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var createItemListDto = GetCreateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); var comparer = new ItemListDtoComparer(); // Act var resultItemListDto = await itemListService.CreateAsync(createItemListDto); // Assert Assert.AreEqual(0, comparer.Compare(_expectedReturnItemListDto, resultItemListDto)); }
private void button1_Click(object sender, EventArgs e) { if (t_Name.Text == string.Empty || t_Price.Text == string.Empty || comboBox1.SelectedItem.ToString() == string.Empty) { MessageBox.Show("Please Enter Values"); } else { ItemListService itemListService = new ItemListService(); Item item = itemListService.GetById(id); item.Id = id; item.ItemName = t_Name.Text; item.ItemPrice = Convert.ToSingle(t_Price.Text); item.ItemDescription = t_Description.Text; item.Category_Name = comboBox1.SelectedItem.ToString(); int result = itemListService.Update(item); if (result > 0) { MessageBox.Show("Item Updated."); UpdateGridView(); } else { MessageBox.Show("Error"); } } }
public async Task GetByIdAsync_ExistingItemListId_Successful() { // Arrange. var itemListEntityToSeed = ItemListEntityToSeed; Seed(TripFlipDbContext, itemListEntityToSeed); var existingItemListId = itemListEntityToSeed.Id; var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); var expectedItemListDto = Mapper.Map <ItemListDto>(itemListEntityToSeed); var comparer = new ItemListDtoComparer(); // Act. var resultItemListDto = await itemListService.GetByIdAsync(existingItemListId); // Assert. Assert.AreEqual(0, comparer.Compare(resultItemListDto, expectedItemListDto)); }
public async Task UpdateAsync_ValidData_Successful() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEditorRoleEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var updateItemListDto = GetUpdateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act. var resultItemListDto = await itemListService.UpdateAsync(updateItemListDto); var expectedItemListDto = new ItemListDto() { Id = updateItemListDto.Id, Title = updateItemListDto.Title, RouteId = resultItemListDto.RouteId // UpdateItemListDto doesn't contain this field, so it initialized like that. }; var comparer = new ItemListDtoComparer(); // Assert. Assert.AreEqual(0, comparer.Compare(resultItemListDto, expectedItemListDto)); }
public async Task DeleteByIdAsync_ValidItemListIdAndCurrentUser_Successful() { // Arrange var validUserThatIsRouteAdmin = ValidUser; Seed(TripFlipDbContext, validUserThatIsRouteAdmin); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserService( validUserThatIsRouteAdmin.Id, validUserThatIsRouteAdmin.Email); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act await itemListService.DeleteByIdAsync(existingItemListId); // Assert bool itemListIsDeleted = TripFlipDbContext .ItemLists .Any(itemList => itemList.Id == existingItemListId) == false; Assert.IsTrue(itemListIsDeleted); }
public async Task DeleteByIdAsync_GivenNotValidCurrentUser_ExceptionThrown( string displayName, ICurrentUserService currentUserService) { // Arrange Seed(TripFlipDbContext, NonExistentUser); Seed(TripFlipDbContext, NotRouteSubscriberUser); Seed(TripFlipDbContext, NotTripSubscriberUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = currentUserService; var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.DeleteByIdAsync(existingItemListId)); }
public async Task UpdateAsync_NonExistentItemList_ExceptionThrown() { // Arrange. var updateItemListDto = GetUpdateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.UpdateAsync(updateItemListDto)); }
public async Task GetByIdAsync_NonExistentItemListId_ExceptionThrown() { // Arrange. // There is no ItemList entries in database, so any id will be non-existent. var nonExistentItemListId = 1; var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.GetByIdAsync(nonExistentItemListId)); }
public async Task DeleteByIdAsync_GivenNonExistentItemListId_ExceptionThrown() { // Arrange var nonExistentItemListId = 1; var itemListService = new ItemListService( tripFlipDbContext: TripFlipDbContext, mapper: null, currentUserService: null); // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.DeleteByIdAsync(nonExistentItemListId)); }
private void button2_Click(object sender, EventArgs e) { ItemListService itemListService = new ItemListService(); int result = itemListService.Delete(id); if (result > 0) { MessageBox.Show("Item deleted."); UpdateGridView(); } else { MessageBox.Show("Error"); } }
private void ItemListForm_Load(object sender, EventArgs e) { ItemListService itemListService = new ItemListService(); dataGridView1.DataSource = itemListService.GetAll(); CategoryListService catListService = new CategoryListService(); var list = catListService.GetAll(); List <string> categoryNames = new List <string>(); foreach (var item in list) { categoryNames.Add(item.CategoryName); } comboBox1.DataSource = categoryNames; }
public async Task GetAllByRouteIdAsync_GivenNonExistentRouteId_ExceptionThrown() { // Arrange var nonExistentRouteId = 1; var itemListService = new ItemListService( tripFlipDbContext: TripFlipDbContext, mapper: null, currentUserService: null); // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.GetAllByRouteIdAsync( routeId: nonExistentRouteId, searchString: null, paginationDto: null)); }
public async Task CreateAsync_GivenNonExistentRouteId_ExceptionThrown() { // Arrange Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var nonExistentRouteId = 2; var createItemListDto = GetCreateItemListDto(routeId: nonExistentRouteId); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.CreateAsync(createItemListDto)); }
public async Task GetAllByRouteIdAsync_ExistingRouteId_Successful() { // Arrange Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); var validRouteId = 1; var itemListService = new ItemListService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: null); var expectedItemListDto = Mapper.Map <ItemListDto>(ItemListEntityToSeed); var expectedItemListDtos = new List <ItemListDto> { expectedItemListDto }; var paginationDto = GetPaginationDto(); var comparer = new ItemListDtoComparer(); // Act var resultPagedList = await itemListService.GetAllByRouteIdAsync( routeId : validRouteId, searchString : null, paginationDto : paginationDto); var resultItemListDtos = resultPagedList.Items.ToList(); // Assert int resultItemListDtosCount = resultItemListDtos.Count; Assert.AreEqual(resultItemListDtosCount, expectedItemListDtos.Count); for (int i = 0; i < resultItemListDtosCount; i++) { Assert.AreEqual(0, comparer.Compare(resultItemListDtos[i], expectedItemListDtos[i])); } }
public async Task CreateAsync_GivenCurrentUserNotRouteAdmin_ExceptionThrown() { // Arrange Seed(TripFlipDbContext, UserWithoutRouteRoles); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserService(UserWithoutRouteRoles.Id, UserWithoutRouteRoles.Email); var createItemListDto = GetCreateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act & Assert await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await itemListService.CreateAsync(createItemListDto)); }
public async Task UpdateAsync_CurrentUserNotRouteEditor_ExceptionThrown() { // Arrange. Seed(TripFlipDbContext, UserWithoutRouteRoles); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService(UserWithoutRouteRoles.Id, UserWithoutRouteRoles.Email); var updateItemListDto = GetUpdateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await itemListService.UpdateAsync(updateItemListDto)); }
public async Task UpdateAsync_InvalidCurrentUser_ExceptionThrown( string displayName, ICurrentUserService currentUserService) { // Arrange. Seed(TripFlipDbContext, NonExistentUser); Seed(TripFlipDbContext, NotRouteSubscriberUser); Seed(TripFlipDbContext, NotTripSubscriberUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); CurrentUserService = currentUserService; var updateItemListDto = GetUpdateItemListDto(); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.UpdateAsync(updateItemListDto), displayName); }
public async Task DeleteByIdAsync_GivenNotAdminCurrentUser_ExceptionThrown() { // Arrange var userThatIsRouteSubButNotAdmin = ValidUser; Seed(TripFlipDbContext, userThatIsRouteSubButNotAdmin); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService( userThatIsRouteSubButNotAdmin.Id, userThatIsRouteSubButNotAdmin.Email); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act & Assert await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await itemListService.DeleteByIdAsync(existingItemListId)); }
public ItemManager(DataBaseContext db) { itemService = new ItemService(db); itemlistService = new ItemListService(db); }
void UpdateGridView() { ItemListService itemListService = new ItemListService(); dataGridView1.DataSource = itemListService.GetAll(); }