public async Task ShouldNotUpdateResourceWhenItDoesntExist() { var command = ResourceCommandFaker.GenerateUpdateApiResourceCommand().Generate(); _apiResourceRepository.Setup(s => s.GetResource(It.Is <string>(q => q == command.OldResourceName))).ReturnsAsync(EntityResourceFaker.GenerateResource().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); Assert.False(result); _apiResourceRepository.Verify(s => s.GetResource(It.Is <string>(q => q == command.OldResourceName)), Times.Once); }
public async Task ShouldRemoveResource() { var command = ResourceCommandFaker.GenerateRemoveApiResourceCommand().Generate(); _apiResourceRepository.Setup(s => s.GetResource(It.Is <string>(q => q == command.Resource.Name))).ReturnsAsync(EntityResourceFaker.GenerateResource().Generate()); _apiResourceRepository.Setup(s => s.Remove(It.IsAny <int>())); _uow.Setup(s => s.Commit()).Returns(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _apiResourceRepository.Verify(s => s.GetResource(It.Is <string>(q => q == command.Resource.Name)), Times.Once); _apiResourceRepository.Verify(s => s.Remove(It.IsAny <int>()), Times.Once); Assert.True(result); }
public async Task ShouldNotSaveResourceWhenItAlreadyExist() { var command = ResourceCommandFaker.GenerateRegisterApiResourceCommand().Generate(); _apiResourceRepository.Setup(s => s.GetResource(It.Is <string>(q => q == command.Resource.Name))).ReturnsAsync(EntityResourceFaker.GenerateResource().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); Assert.False(result); _apiResourceRepository.Verify(s => s.GetResource(It.Is <string>(q => q == command.Resource.Name)), Times.Once); _uow.Verify(v => v.Commit(), Times.Never); }
public async Task ShouldUpdateResource() { var oldResourceName = "old-resource-name"; var command = ResourceCommandFaker.GenerateUpdateApiResourceCommand(oldResourceName: oldResourceName).Generate(); _apiResourceRepository.Setup(s => s.GetResource(It.Is <string>(q => q == oldResourceName))).ReturnsAsync(EntityResourceFaker.GenerateResource().Generate()); _apiResourceRepository.Setup(s => s.UpdateWithChildrens(It.Is <ApiResource>(i => i.Name == command.Resource.Name))).Returns(Task.CompletedTask); _uow.Setup(s => s.Commit()).Returns(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _apiResourceRepository.Verify(s => s.UpdateWithChildrens(It.IsAny <ApiResource>()), Times.Once); _apiResourceRepository.Verify(s => s.GetResource(It.Is <string>(q => q == oldResourceName)), Times.Once); Assert.True(result); }