public void Create_Should_Return_Fail_Result_For_Distance_Greater_Than_Hundred(int distance)
        {
            var userMatchPreferenceResult = UserMatchPreference.Create(Gender.Create(1).Value, 20, 25, distance);

            userMatchPreferenceResult.IsSuccessed.Should().BeFalse();
            userMatchPreferenceResult.GetErrorString().Should().Be(UserMatchPreference.Distance_Should_Be_Less_Than_Or_Equal_To_100);
        }
        private static Result <User> BuildUser(UserRegistrationDTO userRegistrationDTO, byte[] randomByteArray)
        {
            var hashingServiceMock = new Mock <IHashingService>();


            var ageResult = Age.Create(userRegistrationDTO.DateOfBirth);
            var lookingForGenderResult = Gender.Create(userRegistrationDTO.LookingFor);
            var matchPreference        = UserMatchPreference.Create(lookingForGenderResult.Value, userRegistrationDTO.MinAge, userRegistrationDTO.MaxAge, userRegistrationDTO.Distance);
            var phoneNumberResult      = UserPhoneNumber.Create(userRegistrationDTO.PhoneNumber, userRegistrationDTO.CountryCode);
            var genderResult           = Gender.Create(userRegistrationDTO.Gender);
            var loctionResult          = Location.Create(userRegistrationDTO.Latitude, userRegistrationDTO.Longitude);


            hashingServiceMock.Setup(x => x.GenerateSalt()).Returns(randomByteArray);
            hashingServiceMock.Setup(x => x.GetHash(userRegistrationDTO.Password, It.IsAny <byte[]>())).Returns(randomByteArray);
            var passwordSalt   = hashingServiceMock.Object.GenerateSalt();
            var passwordHash   = hashingServiceMock.Object.GetHash(userRegistrationDTO.Password, passwordSalt);
            var passwordResult = Password.Create(passwordHash, passwordSalt);

            var result = UserBuilder.Builder()
                         .WithName(userRegistrationDTO.FullName)
                         .WithPhoneNumber(phoneNumberResult.Value)
                         .WithPassword(passwordResult.Value)
                         .WithGender(genderResult.Value)
                         .WithMatchPreference(matchPreference.Value)
                         .WithAge(ageResult.Value)
                         .WithBucketList(userRegistrationDTO.BucketList)
                         .WithFunAndInterestingThings(userRegistrationDTO.FunAndInteresting)
                         .WithSchool(userRegistrationDTO.School)
                         .WithProfession(userRegistrationDTO.Profession)
                         .WithLocation(loctionResult.Value)
                         .Build();

            return(result);
        }
        public void Create_Should_Return_Fail_Result_For_MinAge_Greater_MaxAge(int minAge, int maxAge)
        {
            var userMatchPreferenceResult = UserMatchPreference.Create(Gender.Create(1).Value, minAge, maxAge, 50);

            userMatchPreferenceResult.IsSuccessed.Should().BeFalse();
            userMatchPreferenceResult.GetErrorString().Should().Be(UserMatchPreference.Maximum_age_Preference_Should_Be_Greater_Than_Or_Equal_To_Minimum_Age_Preference);
        }
        public void Create_Should_Return_Fail_Result_For_MaxAge_Greater_Than_Hundred(int maxAge)
        {
            var userMatchPreferenceResult = UserMatchPreference.Create(Gender.Create(1).Value, 18, maxAge, 50);

            userMatchPreferenceResult.IsSuccessed.Should().BeFalse();
            userMatchPreferenceResult.GetErrorString().Should().Be(UserMatchPreference.Maximum_age_Preference_Should_Not_Cross_100);
        }
        public void Create_Should_Return_Fail_Result_For_Invalid_Gender()
        {
            Gender lookingFor = null;
            var    userMatchPreferenceResult = UserMatchPreference.Create(lookingFor, 20, 25, 50);

            userMatchPreferenceResult.IsSuccessed.Should().BeFalse();
            userMatchPreferenceResult.GetErrorString().Should().Be(UserMatchPreference.Gender_Preference_Is_Required);
        }
Exemple #6
0
        public async Task <Result <User> > CreateUserAsync(UserRegistrationDTO userRegistrationDTO)
        {
            if (string.IsNullOrWhiteSpace(userRegistrationDTO.Password))
            {
                return(Result.Fail <User>(Password_Is_Required));
            }

            var ageResult = Age.Create(userRegistrationDTO.DateOfBirth);
            var lookingForGenderResult = Gender.Create(userRegistrationDTO.LookingFor);
            var matchPreference        = UserMatchPreference.Create(lookingForGenderResult.Value, userRegistrationDTO.MinAge, userRegistrationDTO.MaxAge, userRegistrationDTO.Distance);
            var phoneNumberResult      = UserPhoneNumber.Create(userRegistrationDTO.PhoneNumber, userRegistrationDTO.CountryCode);
            var genderResult           = Gender.Create(userRegistrationDTO.Gender);

            var passwordSalt   = _hashingService.GenerateSalt();
            var passwordHash   = _hashingService.GetHash(userRegistrationDTO.Password, passwordSalt);
            var passwordResult = Password.Create(passwordHash, passwordSalt);

            var locationResult = Location.Create(userRegistrationDTO.Latitude, userRegistrationDTO.Longitude);

            var finalResult = Result.Combine(ageResult,
                                             lookingForGenderResult,
                                             matchPreference,
                                             phoneNumberResult,
                                             genderResult,
                                             passwordResult,
                                             locationResult);

            if (!finalResult.IsSuccessed)
            {
                return(Result.Fail <User>(finalResult.GetErrorString()));
            }

            var userResult = UserBuilder.Builder()
                             .WithName(userRegistrationDTO.FullName)
                             .WithPhoneNumber(phoneNumberResult.Value)
                             .WithPassword(passwordResult.Value)
                             .WithGender(genderResult.Value)
                             .WithMatchPreference(matchPreference.Value)
                             .WithAge(ageResult.Value)
                             .WithBucketList(userRegistrationDTO.BucketList)
                             .WithFunAndInterestingThings(userRegistrationDTO.FunAndInteresting)
                             .WithSchool(userRegistrationDTO.School)
                             .WithProfession(userRegistrationDTO.Profession)
                             .WithLocation(locationResult.Value)
                             .Build();

            var setUserInterestsResult = await _userDomainService.SetUserInterests(userResult.Value, userRegistrationDTO.InterestIds);

            if (!setUserInterestsResult.IsSuccessed)
            {
                return(Result.Fail <User>(setUserInterestsResult.GetErrorString()));
            }

            return(userResult);
        }
        public void Create_Should_Return_Success_Result_For_Valid_Arguments(Tuple <Gender, int, int, int> input)
        {
            Gender lookingFor = input.Item1;
            int    minAge     = input.Item2;
            int    maxAge     = input.Item3;
            int    distance   = input.Item4;

            var userMatchPreferenceResult = UserMatchPreference.Create(lookingFor, minAge, maxAge, distance);

            userMatchPreferenceResult.IsSuccessed.Should().BeTrue();
        }
Exemple #8
0
 public UserBuilder WithMatchPreference(UserMatchPreference userPreference)
 {
     this._userPreference = userPreference;
     return(this);
 }