Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void Create_Should_Return_Fail_Result_For_Invalid_genderType(int genderType)
        {
            var genderResult = Gender.Create(genderType);

            genderResult.IsSuccessed.Should().BeFalse();
            genderResult.GetErrorString().Should().Be(Gender.Invalid_Gender_Type);
        }
Exemplo n.º 6
0
        public void Create_Should_Return_Success_Result_For_Valid_genderType(int genderType)
        {
            var expectedValue = (GenderType)genderType;

            var genderResult = Gender.Create(genderType);

            genderResult.IsSuccessed.Should().BeTrue();
            genderResult.Value.GenderType.Should().Be(expectedValue);
        }
Exemplo n.º 7
0
 public void Create_Int32MinValue_ThrowsArgumentOutOfRangeException()
 {
     ExceptionAssert.CatchArgumentOutOfRangeException
         (() =>
     {
         Gender.Create(Int32.MinValue);
     },
         "val",
         "Not a valid gender");
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public void Create_17_ThrowsArgumentOutOfRangeException()
 {
     using (new CultureInfoScope("en-GB"))
     {
         ExceptionAssert.CatchArgumentOutOfRangeException(() =>
         {
             Gender.Create(17);
         },
                                                          "val",
                                                          "Not a valid gender");
     }
 }
Exemplo n.º 10
0
        public Option <Student> AddNewStudent(string firstName, string lastName, int age, string gender)
        {
            var optionName   = Name.Create(firstName, lastName);
            var optionAge    = Age.Create(age);
            var optionGender = Gender.Create(gender);
            AddStudentApply <Name, Age, Gender, Option <Student> > method = Add;

            return(method.Curry()
                   .Apply(optionName)
                   .Apply(optionAge)
                   .Apply(optionGender));
        }
Exemplo n.º 11
0
 private Name CreateName(Nombres name, Frecuency frecuency) => new Name(name.Nombre, name.EsCompuesto, frecuency, Gender.Create(name.Sexo));
 public Recipient(string name, string gender)
 {
     Name   = name;
     Gender = Gender.Create(gender);
 }