public void UpdateCategory() { var inputParameter = new Domain.Category("name", 1, "description"); var command = new UpdateCategoryCommand { Id = "1", Name = inputParameter.Name, SortOrder = inputParameter.SortOrder, Description = inputParameter.Description }; var dto = Substitute.For <ICategoryDto>(); var datastore = Substitute.For <ICategoryDatastore>(); datastore.Create(inputParameter).Returns <ICategoryDto>(dto); var taskDatastore = Substitute.For <ITaskDatastore>(); UpdateCategoryCommandHandler handler = new UpdateCategoryCommandHandler(datastore, taskDatastore); GenericValidationCommandHandlerDecorator <UpdateCategoryCommand> val = new GenericValidationCommandHandlerDecorator <UpdateCategoryCommand>( handler, new List <IValidator <UpdateCategoryCommand> > { new UpdateCategoryValidator(TestUtils.GetInt32IdValidator()) } ); val.Execute(command); datastore.ReceivedWithAnyArgs(1).Update(inputParameter); }
public async Task Category_Update() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new UpdateCategoryCommandHandler(context, TestHelper.GetMapperInstance()); var command = new UpdateCategoryCommand(); command.Data = new UpdateCategoryRequest { CategoryId = 1, UserName = "******", Name = "Task test updated" }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var count = context.AcCategories.Where(e => e.CategoryId == 1 && e.CategoryName == "Task test updated"); Assert.Equal(1, count.Count()); } } finally { connection.Close(); } }
public async Task UpdateCategoryCommandTestAsync(string identityUserId, int categoryId, string title, string titleImagePath, CreateCategoryResponse result) { UpdateCategoryCommand request = new UpdateCategoryCommand { CategoryId = categoryId, IdentityUserId = identityUserId, Title = title, TitleImagePath = titleImagePath, }; UpdateCategoryCommandHandler handler = new UpdateCategoryCommandHandler(_updateFixture.Context); var expectedResult = await handler.Handle(request, new CancellationToken()); Assert.Equal(expectedResult.IsSuccessful, result.IsSuccessful); if (expectedResult.IsSuccessful) { Category category = await _updateFixture.Context.Categories .Include(c => c.Creator) .Include(c => c.TitleImage) .Where(c => c.Id == expectedResult.Id) .SingleOrDefaultAsync(); Assert.Equal(category.Title, title); Assert.Equal(category.TitleImage.Path, titleImagePath); Assert.Equal(category.Creator.IdentityUserId, identityUserId); } Assert.Equal(expectedResult.Message, result.Message); }
public async Task Update_Category() { using (var context = GetContextWithData()) { var handler = new UpdateCategoryCommandHandler(context); var command = new UpdateCategoryCommand { Id = (await context.Categories.FirstOrDefaultAsync()).Id, Name = "Test2" }; await handler.Handle(command, CancellationToken.None); Assert.Equal(command.Name, (await context.Categories.FindAsync(command.Id)).Name); } }
public async Task GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var sut = new UpdateCategoryCommandHandler(_context); var categoryId = 10; // Act var ex = await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(new UpdateCategoryCommand { Id = categoryId, Name = "", UpdateSlug = false }, CancellationToken.None)); // Assert Assert.IsType <NotFoundException>(ex); }
public async Task UpdateCategoryHandler_Updates_Category() { var category = await GetRandomCategory(); var message = new UpdateCategoryCommand() { Id = category.Id, Name = "New name", Description = "New description" }; var handler = new UpdateCategoryCommandHandler(RequestDbContext); var result = await handler.Handle(message, CancellationToken.None); Assert.IsType <SuccessResult>(result); using (var context = TestContext.CreateNewContext()) { var updatedCategory = await context.Categories.FindAsync(category.Id); Assert.Equal("New name", updatedCategory.Name); Assert.Equal("New description", updatedCategory.Description); } }
public void GivenValidRequest_ShouldUpdateCategoryCorrectly() { // Arrange var sut = new UpdateCategoryCommandHandler(_context); var entity = new Category("Update Category 1"); _context.Categories.Add(entity); _context.SaveChanges(); // Act var result = sut.Handle(new UpdateCategoryCommand { Id = entity.Id, Name = "New Update Category 1 Name", UpdateSlug = true }, CancellationToken.None); Assert.IsType <Unit>(result.Result); Assert.True(entity.Id > 0); Assert.Equal("New Update Category 1 Name", entity.Name); Assert.Equal("new-update-category-1-name", entity.Slug); Assert.Empty(entity.Posts); }