public async Task RemoveParentForCategory_Should_Remove_The_Category_Parent() { var category = Category.Create("code", "name", "url"); var parent = Category.Create("parent", "parent", "parent"); category.SetParentCategory(parent); var repositoryMock = new Mock <Repository.IRepository>(); repositoryMock.Setup(r => r.GetByKeyAsync <Category>(category.Id)) .Returns(Task.FromResult(category)); repositoryMock.Setup(r => r.GetByKeyAsync <Category>(parent.Id)) .Returns(Task.FromResult(parent)); Repository.IRepository repository = repositoryMock.Object; Core.Infrastructure.IEventBus eventBus = new Mock <Core.Infrastructure.IEventBus>().Object; Guid categoryId = category.Id; Guid parentId = parent.Id; var commands = new CategoryCommands(repository, eventBus); await commands.RemoveParentForCategory(categoryId, parentId); Assert.Null(category.Parent); }
public async Task RemoveParentForCategory_Should_Throw_ArgumentException_If_CategoryId_Is_Empty() { Repository.IRepository repository = new Mock <Repository.IRepository>().Object; Core.Infrastructure.IEventBus eventBus = new Mock <Core.Infrastructure.IEventBus>().Object; Guid categoryId = Guid.Empty; Guid parentId = Guid.NewGuid(); var commands = new CategoryCommands(repository, eventBus); var ex = await Assert.ThrowsAsync <ArgumentException>(() => commands.RemoveParentForCategory(categoryId, parentId)); Assert.Equal(nameof(categoryId), ex.ParamName); }