Example #1
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());
        }
        public HomeControllerIntegrationTests(ControllersFixture controllersFixture)
        {
            _httpClient = controllersFixture.HttpClient;
            VakDbContext dbContext = new VakDbContext(controllersFixture.DbContextOptions);

            _vakAccountRepository = new VakAccountRepository(dbContext, new TimeService());
            controllersFixture.ResetAccountsTable(dbContext);
        }
Example #3
0
        public VakDbContextTests(DatabaseFixture dbFixture)
        {
            _dbFixture = dbFixture;
            _dbContext = new VakDbContext(dbFixture.DbContextOptions);
            dbFixture.ResetAccountsTable(_dbContext);

            DateTimeOffset utcNow = DateTimeOffset.UtcNow;

            _testPasswordLastChanged = new DateTimeOffset(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute,
                                                          utcNow.Second, utcNow.Offset);
            _testSecurityStamp = Guid.NewGuid();
        }
Example #4
0
        //public async Task ResetClaimsTable()
        //{
        //    await DbContext.ExecuteAsync("Delete from [dbo].[Claims];" +
        //        "DBCC CHECKIDENT('[dbo].[Claims]', RESEED, 0);", commandType: CommandType.Text);
        //}

        //public async Task ResetRolesTable()
        //{
        //    await DbContext.ExecuteAsync("Delete from [dbo].[Roles];" +
        //        "DBCC CHECKIDENT('[dbo].[Roles]', RESEED, 0);", commandType: CommandType.Text);
        //}

        public void ResetAccountsTable(VakDbContext dbContext)
        {
            dbContext.Database.ExecuteSqlCommand("Delete from [dbo].[Accounts]; DBCC CHECKIDENT('[dbo].[Accounts]', RESEED, 0);");
        }