Ejemplo n.º 1
0
        public async void account_service_creates_new_user_correctly()
        {
            string dbName = Guid.NewGuid().ToString();
            DbContextOptions <PlayItContext> options = new DbContextOptionsBuilder <PlayItContext>()
                                                       .UseInMemoryDatabase(databaseName: dbName).Options;
            var unitOfWork = new UnitOfWork <PlayItContext>(new PlayItContext(options));
            var dbLogger   = new DbExceptionLogger(unitOfWork);

            IAccountService aService = new AccountService(new PasswordService(new SHA512HashingService(), 8, 32),
                                                          unitOfWork,
                                                          new TokenService(unitOfWork, dbLogger), new MailService(), dbLogger);

            var accountSignUp     = new AccountSignUp("*****@*****.**", "TestUserName", "123123Asda!as", "");
            var accountSignUpFail = new AccountSignUp("", "", "", "");

            //Success
            var account = await aService.CreateAccount(accountSignUp);

            Assert.True(account.Entity != null);

            //AccountSignUp Null
            await Assert.ThrowsAsync <NullReferenceException>(() =>
                                                              null);

            //userName parameter null or empty
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                             await aService.CreateAccount(accountSignUpFail));

            //Email parameter null or empty
            accountSignUpFail.UserName = "******";
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                             await aService.CreateAccount(accountSignUpFail));

            //Password parameter null or empty
            accountSignUpFail.Email = "*****@*****.**";
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                             await aService.CreateAccount(accountSignUpFail));

            accountSignUpFail.Password = "******";
            Assert.True(await aService.CreateAccount(accountSignUpFail) != null);
        }
Ejemplo n.º 2
0
        public async void account_gets_verified_correctly()
        {
            string dbName = Guid.NewGuid().ToString();
            DbContextOptions <PlayItContext> options = new DbContextOptionsBuilder <PlayItContext>()
                                                       .UseInMemoryDatabase(databaseName: dbName).Options;
            var unitOfWork = new UnitOfWork <PlayItContext>(new PlayItContext(options));
            var dbLogger   = new DbExceptionLogger(unitOfWork);

            IAccountService aService = new AccountService(new PasswordService(new SHA512HashingService(), 8, 32),
                                                          unitOfWork,
                                                          new TokenService(unitOfWork, dbLogger), new MailService(), dbLogger);

            //Create an account
            var accountSignUp = new AccountSignUp("*****@*****.**", "TestUserName", "123123Asda!as", "");
            var account       = await aService.CreateAccount(accountSignUp);

            //Token verified success
            Assert.True(await aService.VerifyAccount(account.Entity.Token.First().TokenId) != null);
            Assert.True((await aService.VerifyAccount(account.Entity.Token.First().TokenId)).Verified);

            //Token does not exists
            await Assert.ThrowsAsync <NullReferenceException>(async() =>
                                                              await aService.VerifyAccount("a"));
        }