Example #1
0
        public async Task SaveAccountClanInfoAsync(long accountId, AccountClanInfo accountClanInfo)
        {
            var existingClanInfo = await _dbContext.AccountClanInfo
                                   .FirstOrDefaultAsync(c => c.AccountId == accountId);

            if (accountClanInfo == null || accountClanInfo.ClanId == 0)
            {
                // Account not in clan - delete clan info from DB
                if (existingClanInfo != null)
                {
                    _dbContext.Entry(existingClanInfo).State = EntityState.Deleted;
                    await _dbContext.SaveChangesAsync();
                }
                return;
            }

            if (existingClanInfo == null)
            {
                // Insert new clan info
                await _dbContext.AccountClanInfo.AddAsync(accountClanInfo);

                await _dbContext.SaveChangesAsync();

                return;
            }

            // Update clan info
            _dbContext.Entry(existingClanInfo).State = EntityState.Detached;
            accountClanInfo.AccountClanInfoId        = existingClanInfo.AccountClanInfoId;
            _dbContext.AccountClanInfo.Attach(accountClanInfo);
            _dbContext.Entry(accountClanInfo).State = EntityState.Modified;
            await _dbContext.SaveChangesAsync();
        }
Example #2
0
        public async Task SaveAccountClanInfoTest(
            long accountId,
            long dbClanId,
            long wgClanId,
            string dbPlayerRole,
            string wgPlayerRole)
        {
            var accountDataAccessor = _container.Resolve <IAccountDataAccessor>();

            if (dbClanId > 0)
            {
                var dbAccountClanInfo = new AccountClanInfo
                {
                    AccountId  = accountId,
                    ClanId     = dbClanId,
                    PlayerRole = dbPlayerRole
                };
                await _dbContext.AccountClanInfo.AddAsync(dbAccountClanInfo);

                await _dbContext.SaveChangesAsync();

                _dbContext.Entry(dbAccountClanInfo).State = EntityState.Detached;
            }

            var wgAccountClanInfo = new AccountClanInfo
            {
                AccountId  = accountId,
                ClanId     = wgClanId,
                PlayerRole = wgPlayerRole
            };

            await accountDataAccessor.SaveAccountClanInfoAsync(accountId, wgAccountClanInfo);

            var savedClanInfo = await _dbContext.AccountClanInfo
                                .SingleOrDefaultAsync(c => c.AccountId == accountId);

            if (wgClanId > 0)
            {
                Assert.NotNull(savedClanInfo);
                Assert.Equal(wgClanId, savedClanInfo.ClanId);
                Assert.Equal(wgPlayerRole, savedClanInfo.PlayerRole);
            }
            else
            {
                Assert.Null(savedClanInfo);
            }
        }
Example #3
0
        public async Task CreateClanHistoryOperationTest(
            long accountId,
            int databaseClanId,
            int wgClanId,
            string databasePlayerRole,
            string wgPlayerRole,
            bool historyMustBeCreated)
        {
            var operation = _container.Resolve <CreateAccountClanHistoryOperation>();

            // FillingDatabase
            if (databaseClanId > 0)
            {
                var clanInfo = new AccountClanInfo
                {
                    AccountId  = accountId,
                    ClanId     = databaseClanId,
                    PlayerRole = databasePlayerRole
                };
                await _dbContext.AccountClanInfo.AddAsync(clanInfo);

                await _dbContext.SaveChangesAsync();

                _dbContext.Entry(clanInfo).State = EntityState.Detached;
            }
            var operationContext = new StatisticsCollectorOperationContext
            {
                Accounts = new List <SatisticsCollectorAccountOperationContext>
                {
                    new SatisticsCollectorAccountOperationContext
                    {
                        WargamingAccountInfo = new AccountInfo
                        {
                            AccountId       = accountId,
                            AccountClanInfo = new AccountClanInfo
                            {
                                ClanId     = wgClanId,
                                PlayerRole = wgPlayerRole
                            }
                        },
                        CurrentAccountInfo = new AccountInfo
                        {
                            AccountId = accountId
                        }
                    }
                }
            };

            await operation.Execute(operationContext);

            var history = operationContext.Accounts.Single().AccountClanHistory;

            if (historyMustBeCreated)
            {
                Assert.NotNull(history);
                Assert.Equal(wgClanId, history.ClanId ?? 0);
                Assert.Equal(wgPlayerRole, history.PlayerRole);
            }
            else
            {
                Assert.Null(history);
            }
        }