Ejemplo n.º 1
0
        public void AddUserTest()
        {
            var userBuilder = new UserBuilder();

            var randomUserDraftGenerator = new RandomUserDraftGenerator();
            var userDraft = randomUserDraftGenerator.GenerateUserDraft();

            var user = userBuilder.BuildUser(userDraft);

            var registrationService = _container.GetInstance <RegistrationService>();

            registrationService.RegisterUser(user);

            var addedUser = _userManager.GetUserByLogin(userDraft.userName);

            Assert.AreEqual(user.DateOfBirth.ToString(), addedUser.DateOfBirth.ToString());
            Assert.AreEqual(user.FirstName, addedUser.FirstName);
            Assert.AreEqual(user.LastName, addedUser.LastName);
            Assert.AreEqual(user.UserName, addedUser.UserName);

            Assert.AreEqual(user.Address.Country, addedUser.Address.Country);
            Assert.AreEqual(user.Address.City, addedUser.Address.City);
            Assert.AreEqual(user.Address.State, addedUser.Address.State);
            Assert.AreEqual(user.Address.Zipcode, addedUser.Address.Zipcode);
            Assert.AreSame(addedUser.Address.User, addedUser);

            Assert.IsNotNull(addedUser.MobilePhone);
            Assert.AreEqual(user.MobilePhone.Value, addedUser.MobilePhone.Value);
            Assert.AreEqual(user.MobilePhone.IsConfirmed, addedUser.MobilePhone.IsConfirmed);
            Assert.AreSame(addedUser.MobilePhone.User, addedUser);

            Assert.IsNotNull(addedUser.Emails[0]);
            Assert.AreEqual(user.Emails[0].Value, addedUser.Emails[0].Value);
            Assert.AreEqual(user.Emails[0].IsConfirmed, addedUser.Emails[0].IsConfirmed);
            Assert.AreSame(addedUser.Emails[0].User, addedUser);

            Assert.IsNotNull(addedUser.Credentials);
            Assert.IsNotNull(addedUser.Credentials.Logins);
            Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.Email).Value, addedUser.Emails[0].Value);
            Assert.AreSame(addedUser.Credentials.Logins.Find(x => x.Type == LoginType.Email).Credentials, addedUser.Credentials);
            Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.MobilePhone).Value, addedUser.MobilePhone.Value);
            Assert.AreSame(addedUser.Credentials.Logins.Find(x => x.Type == LoginType.MobilePhone).Credentials, addedUser.Credentials);
            Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.Username).Value, addedUser.UserName);
            Assert.AreSame(addedUser.Credentials.Logins.Find(x => x.Type == LoginType.Username).Credentials, addedUser.Credentials);
            Assert.IsNotNull(addedUser.Credentials.Passwords);
            Assert.AreEqual(addedUser.Credentials.Passwords.Count, 1);
            Assert.AreEqual(user.Credentials.Passwords[0].Value, addedUser.Credentials.Passwords[0].Value);
            Assert.AreEqual(user.Credentials.Passwords[0].IsActive, addedUser.Credentials.Passwords[0].IsActive);
            Assert.IsNotNull(addedUser.Credentials.Passwords[0].ExpirationDate);
            Assert.AreSame(addedUser.Credentials.Passwords[0].Credentials, addedUser.Credentials);
            Assert.AreEqual(addedUser.Credentials.User, addedUser);

            Assert.IsNotNull(addedUser.UserRoles);
            Assert.AreEqual(addedUser.UserRoles.Count, 1);
            Assert.AreEqual(user.UserRoles[0].Name, addedUser.UserRoles[0].Name);
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            _container = new Container();

            _container.Register <BookLibraryContext, BookLibraryContext>(Lifestyle.Singleton);
            _container.Register <IUserManager, UserManager>(Lifestyle.Singleton);
            _container.Register <IConfirmationCodeManager, ConfirmationCodeManager>(Lifestyle.Singleton);
            _container.Register <IEmailManager, EmailManager>(Lifestyle.Singleton);
            _container.Register <IPasswordPolicy, PasswordPolicy>();
            _container.Register <ICodeValidationRule, CodeValidationRule>();
            _container.Register <IConfirmationCodeService, ConfirmationCodeService>();
            _container.Register <IEmailConfirmationService, EmailConfirmationService>();
            _container.Register <IConfirmationSenderService, ConfirmationSenderService>();
            _container.Register <IPasswordHasher, PasswordHasher>();
            _container.Register <ICodeGenerator, CodeGenerator>();
            _container.Register <INotificationTransportService, NotificationTransportService>();

            _context = _container.GetInstance <BookLibraryContext>();
            var userBuilder = new UserBuilder();

            _userManager = _container.GetInstance <UserManager>();

            _confirmationCodeManager = _container.GetInstance <ConfirmationCodeManager>();

            _emailManager = _container.GetInstance <EmailManager>();

            var confirmationSenderService = _container.GetInstance <ConfirmationSenderService>();

            var randomUserDraftGenerator = new RandomUserDraftGenerator();
            var userDraft = randomUserDraftGenerator.GenerateUserDraft();

            var user = userBuilder.BuildUser(userDraft);

            user.Emails[0].IsConfirmed = true;
            user.ChangeEmailTo(userDraft.email);

            var registrationService = _container.GetInstance <RegistrationService>();

            registrationService.RegisterUser(user);

            confirmationSenderService.SendConfirmation(user.Email, ConfirmationCodeType.EmailConfirmation);

            confirmationSenderService.SendConfirmation(user.Email, ConfirmationCodeType.EmailConfirmation);

            _context.Codes.ToList()[1].IsActive = false;

            confirmationSenderService.SendConfirmation(user.Email, ConfirmationCodeType.EmailConfirmation);

            _context.Codes.ToList()[2].ExpirationDate = new DateTimeOffset(1971, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);

            _context.SaveChanges();
        }