public void RegisterAndLoginTest2()
        {
            // test when the user was registered before
            UserService target = CreateNewUserService();

            // 1- do register and login
            RegisterInfoOffsite p = new RegisterInfoOffsite()
            {
                DefaultRoleID = TestEnums.Role.constPatientRoleID,
                Email         = "*****@*****.**",
                FirstName     = TestUtils.RandomUtils.RandomString(10),
                LastName      = TestUtils.RandomUtils.RandomString(10),
                Password      = "******"
            };

            var result = target.RegisterAndGetLoginToken(p);

            Assert.AreEqual(true, result.Result, "Result of RegisterAndLogin should be true");
            //string sampleLoginToken = "YKjsZNbws0wkxvIs/82PrCBeIU2Ig2yT8FtWTiZx+fepFD5M01GD1aJsbkLe7Brxmh9WYk1t0j/nKiyNzP8ZYysT2EwtXUAqn7PGrRaXmFKIFuA3h7WI7V86dQ2l6X0PzlUMTmH+r+IZbqAtGe6vCw==";
            // can't validate by string as it changes by time

            // 2- validate returned token
            var u = target.LoginWithLoginToken(result.LoginToken);
            var expectedUserID = 17;

            Assert.IsTrue(u.HasValue, "RegisterAndLogin should return a valid user id");
            Assert.AreEqual(expectedUserID, u.Value, "RegisterAndLogin should return a valid user id");
        }
Exemple #2
0
        public bool RegisterAndLogin(RegisterInfoOffsite p, BusinessRuleErrorList errors, bool throwIfException)
        {
            //ValidatePassword(p.Password, errors, false);
            //ValidateUserName(p.UserName, null, errors, RuleFunctionSEnum.Insert, false);
            ValidateEmail(p.Email, null, errors, RuleFunctionSEnum.Insert, false);
            ValidatePhoneNumber(p.PhoneNumber, null, true, errors, RuleFunctionSEnum.Insert, false);

            if (errors.Count > 0 && throwIfException)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
        public void RegisterAndLoginSecureTest()
        {
            // test when it's a completely new user
            UserService target = CreateNewUserService();

            // 1- Creating register and login encrypted data
            RegisterInfoOffsite p = new RegisterInfoOffsite()
            {
                DefaultRoleID = TestEnums.Role.constPatientRoleID,
                Email         = TestUtils.RandomUtils.RandomEmail(),
                FirstName     = TestUtils.RandomUtils.RandomString(10),
                LastName      = TestUtils.RandomUtils.RandomString(10),
                Password      = "******"
            };

            string loginInfoJson = FWUtils.EntityUtils.JsonSerializeObject(p);
            string encryptedData = FWUtils.EncryptionUtils.EncryptString(loginInfoJson, "64C6B83A-0EFF-4122-A15A-507D4765FC9A");

            //string sampleEncryptedData = "IqX8tHxoAt+XMCzhFgpLA6pwaxY0GyCqM5NyM3dRrCBNIm96cbaE5DIuera8/vJXzWTffx80cWTyJn/7mPQQrbx18F8OVoyjHv4m1W5XZQ8+d4+Bf7X97FioLg1oVLa8F1PReCdFu4MROpDZT290WSRD+yqXHk8F5yQrhyvRin9/dSdz2cN7Enh8J+LTItyUGCk+F37vnE5twqqL8FQilNeQlzBxIUWXe2aXl1KO1fQ=";

            // 2- do register and login
            var result = target.RegisterAndGetLoginTokenSecure(new RegisterAndGetLoginTokenSecureSP()
            {
                RegisterInfoEncBase64 = encryptedData
            });

            Assert.AreEqual(true, result.Result, "Result of RegisterAndLogin should be true");

            // 3- validate returned token
            var u = target.LoginWithLoginToken(result.LoginToken);

            Assert.IsTrue(u.HasValue, "RegisterAndLogin should return a valid user id");

            // 4- see if user is saved in the database
            var user = target.GetByID(u.Value);

            Assert.IsTrue(user != null, "User information should be saved in the database");

            // 5- clean up test
            try
            {
                target.Delete(user);
            }
            catch (Exception)
            {
            }
        }
        public void RegisterAndLoginTest()
        {
            // test when it's a completely new user
            UserService target = CreateNewUserService();

            // 1- do register and login
            RegisterInfoOffsite p = new RegisterInfoOffsite()
            {
                DefaultRoleID = 1,
                Email         = TestUtils.RandomUtils.RandomEmail(),
                FirstName     = TestUtils.RandomUtils.RandomString(10),
                LastName      = TestUtils.RandomUtils.RandomString(10),
                Password      = "******"
            };

            var result = target.RegisterAndGetLoginToken(p);

            Assert.AreEqual(true, result.Result, "Result of RegisterAndLogin should be true:" + result.Error);

            // 2- validate returned token
            var u = target.LoginWithLoginToken(result.LoginToken);

            Assert.IsTrue(u.HasValue, "RegisterAndLogin should return a valid user id");

            // 3- see if user is saved in the database
            var user = target.GetByID(u.Value);

            Assert.IsTrue(user != null, "User information should be saved in the database");

            // 4- clean up test
            try
            {
                target.Delete(user);
            }
            catch (Exception)
            {
            }
        }