Example #1
0
        public async Task ShouldNotUpdateResourceWhenNameIsntProvided()
        {
            var command = IdentityResourceCommandFaker.GenerateUpdateCommand().Generate();

            command.Resource.Name = null;

            var result = await _commandHandler.Handle(command, _tokenSource.Token);

            result.Should().BeFalse();
            _uow.Verify(v => v.Commit(), Times.Never);
        }
Example #2
0
        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 Should_Not_Remove_Resource_When_It_Doesnt_Exist()
        {
            var command = IdentityResourceCommandFaker.GenerateUpdateCommand().Generate();

            _identityResourceRepository.Setup(s => s.GetByName(It.Is <string>(q => q == command.OldIdentityResourceName))).ReturnsAsync((IdentityResource)null);

            var result = await _commandHandler.Handle(command, _tokenSource.Token);


            result.Should().BeFalse();
            _uow.Verify(v => v.Commit(), Times.Never);
            _identityResourceRepository.Verify(s => s.GetByName(It.Is <string>(q => q == command.OldIdentityResourceName)), Times.Once);
        }
Example #4
0
        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();
        }