Ejemplo n.º 1
0
        public void RegisteringUser_WhenGivenUsernameNotExists_AddsUser()
        {
            var dbContext     = DbContextProvider.CreateMainDbForTests(MethodBase.GetCurrentMethod().Name);
            var aggregateRoot = new UserAggregateRoot(null, dbContext);

            const string alreadyAddedUserName = "******";
            const string testedUserName       = "******";


            dbContext.Users.Add(new EFDAL.Entities.User()
            {
                FirstName    = "aa",
                LastName     = "bb",
                EmailAddress = "*****@*****.**",
                PasswordHash = "abcdefgh",
                Username     = alreadyAddedUserName,
            });
            dbContext.SaveChanges();

            var userModel = new EditUserModel()
            {
                FirstName    = "testFirstName",
                LastName     = "testLastName",
                EmailAddress = "*****@*****.**",
                Password     = "******",
                Username     = testedUserName
            };

            aggregateRoot.AddNew(userModel, new SHA256PasswordHasher());

            Assert.AreEqual(2, dbContext.Users.Count());
            Assert.IsNotNull(dbContext.Users.Single(x => x.Username == testedUserName));
        }
Ejemplo n.º 2
0
        public void RegisteringUser_WhenGivenUsernameExists_Fails()
        {
            var          dbContext      = DbContextProvider.CreateMainDbForTests(MethodBase.GetCurrentMethod().Name);
            var          aggregateRoot  = new UserAggregateRoot(null, dbContext);
            const string testedUserName = "******";

            dbContext.Users.Add(new EFDAL.Entities.User()
            {
                FirstName    = "aa",
                LastName     = "bb",
                EmailAddress = "*****@*****.**",
                PasswordHash = "abcdefgh",
                Username     = testedUserName,
            });
            dbContext.SaveChanges();

            var userModel = new EditUserModel()
            {
                FirstName    = "testFirstName",
                LastName     = "testLastName",
                EmailAddress = "*****@*****.**",
                Password     = "******",
                Username     = testedUserName
            };

            Assert.ThrowsException <HavingFunBusinessValidationException>(() => aggregateRoot.AddNew(userModel, new SHA256PasswordHasher()));
        }