public async Task Delete_NoSuchRegistration_ReturnsBadRequest()
        {
            // Arrange 
            var user = DummyData.UserFaker.Generate();
            var registrationId = Guid.NewGuid();

            _sut.ControllerContext = FakeControllerContext.For(user);

            _userRepository.GetBy(user.Email).Returns(user);
            _registrationRepository.GetBy(Arg.Any<Guid>(), user.Email).ReturnsNull();

            var appUser = FakeAppUser.For(user).WithClaims("admin");
            _um.FindByNameAsync(user.Email).Returns(Task.FromResult(appUser));


            // Act 
            var numberOfRegistrations = user.Registrations.Count;
            var result = await _sut.DeleteAsync(registrationId);

            // Assert 
            result.Should().BeOfType<BadRequestResult>();

            user.Registrations.Count.Should().Be(numberOfRegistrations);
            _userRepository.Received().GetBy(user.Email);
            _registrationRepository.Received().GetBy(registrationId, user.Email);
            _registrationRepository.DidNotReceive().Delete(Arg.Any<Registration>(), user.Email);
        }
        public async Task UpdateProfile_ProfileUpdated_Success()
        {
            // Arrange
            var updateProfileDTO = DummyData.UpdateProfileDTOFaker.Generate();
            var user             = DummyData.UserFaker.Generate();
            var appUser          = FakeAppUser.For(user);

            _updateProfileValidator.SetupPass();
            _um.FindByNameAsync(appUser.Email).Returns(appUser);
            _um.UpdateAsync(appUser).Returns(IdentityResult.Success);

            _sut.ControllerContext = FakeControllerContext.For(user);
            _userRepository.GetBy(user.Email).Returns(user);

            // Act
            var result = await _sut.Update(updateProfileDTO);

            // Assert
            result.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(
                updateProfileDTO,
                options => options.Excluding(u => u.Friends)
                );
            _userRepository.Received().Update(user);
        }
        public async Task Delete_LoggedInUserWithGoodRegistration_ShouldDeleteRegistrationAndReturnsOk()
        {
            // Arrange 
            var user = DummyData.UserFaker.Generate();
            var registration = user.Registrations.Last();

            _sut.ControllerContext = FakeControllerContext.For(user);

            _userRepository.GetBy(user.Email).Returns(user);
            _registrationRepository.GetBy(registration.Id, user.Email).Returns(registration);

            var appUser = FakeAppUser.For(user).WithClaims("admin");
            _um.FindByNameAsync(user.Email).Returns(Task.FromResult(appUser));

            // Act 
            var result = await _sut.DeleteAsync(registration.Id);

            // Assert 
            result.Should().BeOfType<OkObjectResult>()
                .Which.Value.Should().BeEquivalentTo(
                    registration,
                    options => options.Using(new EnumAsStringAssertionRule()) //treat enums as strings
                );


            _userRepository.Received().GetBy(user.Email);
            _registrationRepository.Received().Delete(registration, user.Email);
        }
        public async Task DeleteProfile_ProfileDeleted_Succes()
        {
            // Arrange
            var user   = DummyData.UserFaker.Generate();
            var idUser = FakeAppUser.For(user);

            _um.FindByNameAsync(idUser.Email).Returns(idUser);
            _um.DeleteAsync(idUser).Returns(IdentityResult.Success);
            _sut.ControllerContext = FakeControllerContext.For(user);
            _userRepository.GetBy(user.Email).Returns(user);

            // Act
            var result = await _sut.Delete();

            // Assert
            result.Should().BeOfType <OkResult>();
            _userRepository.Received().Delete(user);
        }
        public async Task UpdateProfile_UserNotFound_ShouldReturnBadRequest()
        {
            // Arrange
            var updateProfileDTO = DummyData.UpdateProfileDTOFaker.Generate();
            var user             = DummyData.UserFaker.Generate();
            var appUser          = FakeAppUser.For(user);

            _um.FindByNameAsync(appUser.Email).Returns(appUser);
            _updateProfileValidator.SetupPass();
            _sut.ControllerContext = FakeControllerContext.For(user);

            _userRepository.GetBy(user.Email).ReturnsNull();

            // Act
            var result = await _sut.Update(updateProfileDTO);

            // Assert

            result.Should().BeOfType <BadRequestObjectResult>();
        }