Пример #1
0
        public void InitializeTest()
        {
            // Initializes the database with 10 sample users.
            MembershipCreateStatus status;

            for (int i = 1; i <= 10; i++)
            {
                mongoProvider.CreateUser("username" + i, "password" + i, "user" + i + "@example.com",
                                         "What is MongoDB?",
                                         "A cool NoSQL database", true, Guid.NewGuid(), out status);
            }
        }
Пример #2
0
        public void CreateUserTest()
        {
            DateTime startTest = DateTime.Now;

            string username          = "******";
            string upperCaseUsername = "******";
            string email             = "*****@*****.**";
            string upperCaseEmail    = "*****@*****.**";
            string password          = "******";
            string question          = "What is MongoDB?";
            string answer            = "A cool NoSQL database";
            bool   isApproved        = true;

            MembershipUser         user;
            MembershipCreateStatus status;

            // Create a user.  This is a valid call.
            user = mongoProvider.CreateUser(username, password, email,
                                            question, answer, isApproved, Guid.NewGuid(), out status);

            Assert.IsNotNull(user, "A user should have been created");
            Assert.AreEqual(username, user.UserName, "Username property does not coincide");
            Assert.AreEqual(question, user.PasswordQuestion, "Question property does not coincide");


            Assert.AreEqual(status, MembershipCreateStatus.Success, "The creation should have been successful");


            // Create a user with the same username.
            user = mongoProvider.CreateUser(username, password, "*****@*****.**",
                                            question, answer, isApproved, Guid.NewGuid(), out status);

            Assert.IsNull(user, "No user should have been created since the username is already taken");
            Assert.AreEqual(status, MembershipCreateStatus.DuplicateUserName, "Expecting a DuplicateUserName status");

            // Create a user with the same username but this time with different case
            user = mongoProvider.CreateUser(upperCaseUsername, password, "*****@*****.**",
                                            question, answer, isApproved, Guid.NewGuid(), out status);

            Assert.IsNull(user, "No user should have been created since the username is already taken");
            Assert.AreEqual(status, MembershipCreateStatus.DuplicateUserName, "Expecting a DuplicateUserName status");


            // Create a user with a different same username but the same email.
            user = mongoProvider.CreateUser("newUserName", password, email,
                                            question, answer, isApproved, Guid.NewGuid(), out status);

            Assert.IsNull(user, "No user should have been created since the email is already taken");
            Assert.AreEqual(status, MembershipCreateStatus.DuplicateEmail, "Expecting DuplicateEmail status");

            // Create a user with a different same username but the same email.
            user = mongoProvider.CreateUser("newUserName", password, upperCaseEmail,
                                            question, answer, isApproved, Guid.NewGuid(), out status);

            Assert.IsNull(user, "No user should have been created since the email is already taken");
            Assert.AreEqual(status, MembershipCreateStatus.DuplicateEmail, "Expecting DuplicateEmail status");



            double durationMiliseconds = DateTime.Now.Subtract(startTest).TotalMilliseconds;

            Console.WriteLine(String.Format("Test Duration: {0} miliseconds.", durationMiliseconds));
        }