public async Task Handler_should_throw_unable_to_change_state_exception_if_user_is_supervisor()
        {
            //Arrange
            var fakeUser = new User
            {
                Id = Guid.NewGuid().ToString()
            };


            _identityDataContextMock.Setup(x => x.Users).ReturnsDbSet(new List <User> {
                fakeUser
            });
            _userManagerMock.Setup(x => x.Users).Returns(_identityDataContextMock.Object.Users);
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(true));

            var cancellationToken = new CancellationToken();
            var command           = new ChangeUserActivationStateCommand(fakeUser.Id, true);
            var handler           =
                new ChangeUserActivationStateCommandHandler(_userManagerMock.Object);

            //Act
            Task Act() => handler.Handle(command, cancellationToken);

            //Assert
            await Assert.ThrowsAsync <UserUnableToChangeStateException>(Act);
        }
        public async Task Handler_should_return_true()
        {
            //Arrange
            var fakeUser = new User
            {
                Id = Guid.NewGuid().ToString()
            };

            _identityDataContextMock.Setup(x => x.Users).ReturnsDbSet(new List <User> {
                fakeUser
            });
            _userManagerMock.Setup(x => x.Users).Returns(_identityDataContextMock.Object.Users);
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(false));

            var cancellationToken = new CancellationToken();
            var command           = new ChangeUserActivationStateCommand(fakeUser.Id, true);
            var handler           =
                new ChangeUserActivationStateCommandHandler(_userManagerMock.Object);

            //Act
            var result = await handler.Handle(command, cancellationToken);

            //Assert
            Assert.True(result);
        }
        public async Task Handler_should_call_user_manager_update()
        {
            //Arrange
            var fakeUser = new User
            {
                Id       = Guid.NewGuid().ToString(),
                IsActive = false
            };


            _identityDataContextMock.Setup(x => x.Users).ReturnsDbSet(new List <User> {
                fakeUser
            });
            _userManagerMock.Setup(x => x.Users).Returns(_identityDataContextMock.Object.Users);
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(false));

            var cancellationToken = new CancellationToken();
            var command           = new ChangeUserActivationStateCommand(fakeUser.Id, !fakeUser.IsActive);
            var handler           =
                new ChangeUserActivationStateCommandHandler(_userManagerMock.Object);

            //Act
            var result = await handler.Handle(command, cancellationToken);

            //Assert
            _userManagerMock.Verify(x => x.UpdateAsync(It.Is <User>(it => it == fakeUser)), Times.Once);
        }
        public async Task Handler_should_throw_exception_if_dependency_is_null()
        {
            //Arrage

            //Act
            void Act()
            {
                var command = new ChangeUserActivationStateCommandHandler(null);
            }

            //Assert
            Assert.Throws <ArgumentNullException>(Act);
        }
        public async Task Handler_should_throw_not_found_exception_if_user_doesnt_exist()
        {
            //Arrange
            _identityDataContextMock.Setup(x => x.Users).ReturnsDbSet(new List <User>());
            _userManagerMock.Setup(x => x.Users).Returns(_identityDataContextMock.Object.Users);

            var cancellationToken = new CancellationToken();
            var command           = new ChangeUserActivationStateCommand("322", true);
            var handler           =
                new ChangeUserActivationStateCommandHandler(_userManagerMock.Object);

            //Act
            Task Act() => handler.Handle(command, cancellationToken);

            //Assert
            await Assert.ThrowsAsync <UserNotFoundException>(Act);
        }