public async Task ShouldNotUpdateResourceWhenItDoesntExist() { var command = IdentityResourceCommandFaker.GenerateUpdateCommand().Generate(); _identityResourceRepository.Setup(s => s.GetByName(It.Is <string>(q => q == command.OldIdentityResourceName))).ReturnsAsync(EntityIdentityResourceFaker.GenerateEntity().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeFalse(); _identityResourceRepository.Verify(s => s.GetByName(It.Is <string>(q => q == command.OldIdentityResourceName)), Times.Once); }
public async Task ShouldUpdateResource() { var oldResourceName = "old-resource-name"; var command = IdentityResourceCommandFaker.GenerateUpdateCommand(oldIdentityResourceName: oldResourceName).Generate(); _identityResourceRepository.Setup(s => s.GetByName(It.Is <string>(q => q == oldResourceName))).ReturnsAsync(EntityIdentityResourceFaker.GenerateEntity().Generate()); _identityResourceRepository.Setup(s => s.UpdateWithChildrens(It.Is <IdentityResource>(i => i.Name == command.Resource.Name))).Returns(Task.CompletedTask); _uow.Setup(s => s.Commit()).Returns(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _identityResourceRepository.Verify(s => s.UpdateWithChildrens(It.IsAny <IdentityResource>()), Times.Once); _identityResourceRepository.Verify(s => s.GetByName(It.Is <string>(q => q == oldResourceName)), Times.Once); result.Should().BeTrue(); }
public async Task ShouldRemoveResource() { var command = IdentityResourceCommandFaker.GenerateRemoveCommand().Generate(); _identityResourceRepository.Setup(s => s.GetByName(It.Is <string>(q => q == command.Resource.Name))).ReturnsAsync(EntityIdentityResourceFaker.GenerateEntity().Generate()); _identityResourceRepository.Setup(s => s.Remove(It.IsAny <int>())); _uow.Setup(s => s.Commit()).Returns(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _identityResourceRepository.Verify(s => s.GetByName(It.Is <string>(q => q == command.Resource.Name)), Times.Once); _identityResourceRepository.Verify(s => s.Remove(It.IsAny <int>()), Times.Once); result.Should().BeTrue(); }