public async Task <int> IterateUserNumber(UserType userType, Application application, bool isProdUser, TestType testType)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            List <User> users;

            if (testType == TestType.Automated)
            {
                users = await db.Users
                        .Where(x => x.UserType == userType.MapToContractEnum() && x.Application == application.MapToContractEnum() && x.IsProdUser == isProdUser)
                        .AsNoTracking()
                        .ToListAsync();
            }
            else
            {
                users = await db.Users
                        .Where(x => x.UserType == userType.MapToContractEnum() && x.IsProdUser == isProdUser)
                        .AsNoTracking()
                        .ToListAsync();
            }

            if (users.Count.Equals(0))
            {
                return(1);
            }

            return(users.Select(user => user.Number).ToList().Max() + 1);
        }
        public async Task <RecentUser> GetRecentUserByUsername(string username)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            return(await db.RecentUsers
                   .Where(x => x.Username == username)
                   .AsNoTracking()
                   .SingleOrDefaultAsync());
        }
        public async Task <User> GetUserById(Guid userId)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            return(await db.Users
                   .Where(x => x.Id == userId)
                   .AsNoTracking()
                   .SingleOrDefaultAsync());
        }
        public async Task <RecentUser> SeedRecentUser(string username)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);
            var recentUser = new RecentUser(username);
            await db.RecentUsers.AddAsync(recentUser);

            await db.SaveChangesAsync();

            return(recentUser);
        }
Beispiel #5
0
        public static void SeedHostDb(TestApiDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
        public async Task <Allocation> SeedAllocation(Guid userId)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var user = await db.Users.AsNoTracking().SingleOrDefaultAsync(x => x.Id == userId);

            var allocation = new Allocation(user);
            await db.Allocations.AddAsync(allocation);

            await db.SaveChangesAsync();

            return(allocation);
        }
        public async Task DeleteUsers()
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var users = await db.Users
                        .Where(x => x.Application == Application.TestApi.MapToContractEnum())
                        .AsNoTracking()
                        .ToListAsync();

            foreach (var user in users)
            {
                db.Remove(user);
                await db.SaveChangesAsync();
            }
        }
        public async Task DeleteRecentUsers()
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var recentUsers = await db.RecentUsers
                              .Where(x => x.Username == EmailData.RECENT_USER_USERNAME)
                              .AsNoTracking()
                              .ToListAsync();

            foreach (var user in recentUsers)
            {
                db.Remove(user);
                await db.SaveChangesAsync();
            }
        }
        public async Task <Allocation> AllocateUser(Guid userId, int expiresInMinutes = 1)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var allocation = await db.Allocations
                             .Where(x => x.UserId == userId)
                             .AsNoTracking()
                             .SingleOrDefaultAsync();

            allocation.Allocate(expiresInMinutes);
            db.Allocations.Update(allocation);
            await db.SaveChangesAsync();

            return(allocation);
        }
Beispiel #10
0
        public async Task <UserDto> SeedUser(TestType testType, UserType userType = UserType.Judge)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            const Application APPLICATION  = Application.TestApi;
            const bool        IS_PROD_USER = false;

            var number = await IterateUserNumber(userType, APPLICATION, IS_PROD_USER, testType);

            var user = new UserBuilder(_context.Config.UsernameStem, number)
                       .WithUserType(userType)
                       .ForApplication(APPLICATION)
                       .ForTestType(testType)
                       .BuildUser();

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(UserToUserDtoMapper.Map(user));
        }
Beispiel #11
0
        public async Task <UserDto> SeedUser(UserType userType = UserType.Judge, bool isProdUser = false)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            const Application application = Application.TestApi;
            const TestType    testType    = TestType.Automated;

            var number = await IterateUserNumber(userType, application, isProdUser, testType);

            var user = new UserBuilder(_context.Config.UsernameStem, number)
                       .WithUserType(userType)
                       .ForApplication(application)
                       .IsProdUser(isProdUser)
                       .BuildUser();

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(UserToUserDtoMapper.Map(user));
        }
Beispiel #12
0
        private async Task <List <PairData> > FormDataAsync()
        {
            var testDate1 = new DateTime(2020, 1, 1);
            var testDate2 = new DateTime(2020, 1, 5);

            _bittrexService = new BittrexService(TestApiDbContext);
            var testPairs = new List <PairData>
            {
                new PairData
                {
                    PairName       = "BTC-USD",
                    BuyPrice       = 254.0m,
                    SellPrice      = 254.0m,
                    LastTradePrice = 254.0m,
                    HighPrice      = 254.0m,
                    LowPrice       = 254.0m,
                    Volume         = 1234567,
                    Updated        = testDate1
                },
                new PairData
                {
                    PairName       = "LTC-XRP",
                    BuyPrice       = 123.0m,
                    SellPrice      = 123.0m,
                    LastTradePrice = 123.0m,
                    HighPrice      = 123.0m,
                    LowPrice       = 123.0m,
                    Volume         = 999999,
                    Updated        = testDate2
                }
            };

            await TestApiDbContext.Pairs.AddRangeAsync(testPairs);

            await TestApiDbContext.SaveChangesAsync();

            return(testPairs);
        }
Beispiel #13
0
 public CreateNewRecentUserByUsernameCommandHandler(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public HostRoleAndUserCreator(TestApiDbContext context)
 {
     _context = context;
 }
 public CreateNewUserCommandHandler(TestApiDbContext context)
 {
     _context = context;
 }
 public GetAllAllocationsForAUserQueryHandler(TestApiDbContext context)
 {
     _context = context;
 }
 public GetUserByIdQueryHandler(TestApiDbContext context)
 {
     _context = context;
 }
 public GetAllUsersByFilterQueryHandler(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #19
0
 public UnallocateUserCommandHandler(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #20
0
 public TestTableservices(TestApiDbContext _db)
 {
     testApiDbContext = _db;
 }
Beispiel #21
0
 public GetAllocatedUserByUserTypeQueryHandler(TestApiDbContext context, IAllocationService service)
 {
     _context = context;
     _service = service;
 }
Beispiel #22
0
 public DefaultLanguagesCreator(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #23
0
 public CardInDeckRepository(TestApiDbContext options) : base(options)
 {
 }
 public CardRepository(TestApiDbContext context) : base(context)
 {
 }
 public DeckRepository(TestApiDbContext context) : base(context)
 {
 }
Beispiel #26
0
 public InitialHostDbBuilder(TestApiDbContext context)
 {
     _context = context;
 }
 public GetRecentUserByUsernameQueryHandler(TestApiDbContext context)
 {
     _context = context;
 }
 public EmployeesController(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #29
0
 public GetAllocationByUserIdQueryHandler(TestApiDbContext context)
 {
     _context = context;
 }
Beispiel #30
0
 public DefaultSettingsCreator(TestApiDbContext context)
 {
     _context = context;
 }