Beispiel #1
0
        public async Task VakDbContext_AccountRowVersionValueGeneratedOnAddOrUpdate()
        {
            // Arrange
            VakAccount account = new VakAccount
            {
                Email               = _testEmail1,
                PasswordHash        = _testPasswordHash,
                PasswordLastChanged = _testPasswordLastChanged,
                SecurityStamp       = _testSecurityStamp
            };

            // Act
            await _dbContext.AddAsync(account);

            await _dbContext.SaveChangesAsync();

            byte[] initialRowVersion = account.RowVersion;

            account.DisplayName = _testDisplayName;
            await _dbContext.SaveChangesAsync();

            byte[] finalRowVersion = account.RowVersion;

            // Assert
            Assert.NotEqual(initialRowVersion, finalRowVersion);
        }
Beispiel #2
0
        public async Task VakDbContext_AccountRowVersionIsConcurrencyToken()
        {
            // Arrange
            VakAccount account = new VakAccount
            {
                Email               = _testEmail1,
                PasswordHash        = _testPasswordHash,
                PasswordLastChanged = _testPasswordLastChanged,
                SecurityStamp       = _testSecurityStamp
            };
            VakDbContext dbContext2 = new VakDbContext(_dbFixture.DbContextOptions);

            // Act
            await _dbContext.AddAsync(account);

            await _dbContext.SaveChangesAsync();

            VakAccount account2 = await dbContext2.Accounts.FirstOrDefaultAsync(a => a.AccountId == account.AccountId);

            account2.DisplayName = _testDisplayName;
            await dbContext2.SaveChangesAsync();

            account.DisplayName = _testDisplayName;

            // Assert
            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() => await _dbContext.SaveChangesAsync());
        }
Beispiel #3
0
        public async Task VakDbContext_AccountAccountIdValueGeneratedOnAdd()
        {
            // Arrange
            VakAccount account1 = new VakAccount
            {
                Email               = _testEmail1,
                PasswordHash        = _testPasswordHash,
                PasswordLastChanged = _testPasswordLastChanged,
                SecurityStamp       = _testSecurityStamp
            };
            VakAccount account2 = new VakAccount
            {
                Email               = _testEmail2,
                PasswordHash        = _testPasswordHash,
                PasswordLastChanged = _testPasswordLastChanged,
                SecurityStamp       = _testSecurityStamp
            };

            // Act
            await _dbContext.AddAsync(account1);

            await _dbContext.SaveChangesAsync();

            await _dbContext.AddAsync(account2);

            await _dbContext.SaveChangesAsync();

            // Assert
            Assert.Equal(1, account1.AccountId);
            Assert.Equal(2, account2.AccountId);
        }
Beispiel #4
0
        public async Task <IActionResult> GetAccountDetails()
        {
            VakAccount account = await _accountService.GetAccountDetailsActionAsync();

            if (account == null)
            {
                // Logged in but unable to retrieve account
                throw new NullReferenceException(nameof(account));
            }

            return(Ok(new GetAccountDetailsResponseModel
            {
                AltEmail = account.AltEmail,
                AltEmailVerified = account.AltEmailVerified,
                DisplayName = account.DisplayName,
                DurationSinceLastPasswordChange = (DateTime.UtcNow - account.PasswordLastChanged).ToElapsedDurationString(),
                Email = account.Email,
                EmailVerified = account.EmailVerified,
                TwoFactorEnabled = account.TwoFactorEnabled
            }));
        }