Exemplo n.º 1
0
        public long MakeBet(long battleId, long teamId, long userId, string title, double amount, double coefficient, string url, bool isPrivate)
        {
            using (var unitOfWorkScope = _unitOfWorkScopeFactory.Create())
            {
                var bet = new Bet(battleId, teamId, userId, title, amount, coefficient, url, isPrivate);
                _repositoryOfBet.Add(bet);

                var teamBattleStatistics = _repositoryOfTeamBattleStatistics.Get(TeamBattleStatisticsSpecifications.BattleIdAndTeamIdAreEqualTo(battleId, teamId)).SingleOrDefault();
                if (teamBattleStatistics == null)
                {
                    teamBattleStatistics = new TeamBattleStatistics(battleId, teamId);
                    _repositoryOfTeamBattleStatistics.Add(teamBattleStatistics);
                }

                var teamStatistics = _repositoryOfTeamStatistics.Get(EntitySpecifications.IdIsEqualTo<TeamStatistics>(teamId)).Single();

                teamStatistics.Rating -= amount;
                teamBattleStatistics.Gain -= amount;

                teamStatistics.OpenedBetsCount++;
                teamBattleStatistics.OpenedBetsCount++;

                unitOfWorkScope.SaveChanges();

                return bet.Id;
            }
        }
Exemplo n.º 2
0
        public void Setup()
        {
            _transactionScope = new TransactionScope();

            var kernel = TestNinjectKernel.Kernel;
            _creator = kernel.Get<Creator>();

            var repositoryOfTeamUser = kernel.Get<IRepository<TeamUser>>();
            _repositoryOfBet = kernel.Get<IRepository<Bet>>();

            var usersService = kernel.Get<IUsersService>();
            var battlesService = kernel.Get<IBattlesService>();
            
            _betsViewService = kernel.Get<IBetsViewService>();

            _userId = usersService.Register("login", "openIdUrl", Language.English);
            _notMeUserId = usersService.Register("login1", "openIdUrl2", Language.Russian);
            _teamId = repositoryOfTeamUser.All().Where(tu => tu.UserId == _userId).Select(tu => tu.TeamId).SingleOrDefault();

            _battleId = battlesService.CreateBattle(DateTime.UtcNow, DateTime.UtcNow, BattleType.FixedBudget, 10000);
            var otherBattleId = battlesService.CreateBattle(DateTime.UtcNow, DateTime.UtcNow, BattleType.FixedBudget, 10000);

            var myOpenedPublicBetId = battlesService.MakeBet(_battleId, _teamId, _userId, "title1", 100, 1.5, "http://url2", false);

            var myClosedPublicBetId = battlesService.MakeBet(_battleId, _teamId, _userId, "title2", 10, 10, "http://url1", false);
            long closedBattleId;
            battlesService.BetSucceeded(myClosedPublicBetId, _userId, out closedBattleId);

            var myOpenedPrivateBetId = battlesService.MakeBet(_battleId, _teamId, _userId, "title3", 100, 10, "http://url3", true);

            var myClosedPrivateBetId = battlesService.MakeBet(_battleId, _teamId, _userId, "title4", 100, 10, "http://url4", true);
            battlesService.BetSucceeded(myClosedPrivateBetId, _userId, out closedBattleId);

            var notMyOpenedPrivateBetId = battlesService.MakeBet(_battleId, _teamId, _notMeUserId, "title5", 100, 2, "http://url3", true);
            var myOtherBattleOpenedPrivateBetId = battlesService.MakeBet(otherBattleId, _teamId, _userId, "title6", 100, 2, "http://url4", true);

            _myOpenedPrivateBet = GetBet(myOpenedPrivateBetId);
            _myClosedPrivateBet = GetBet(myClosedPrivateBetId);
            _myOpenedPublicBet = GetBet(myOpenedPublicBetId);
            _myClosedPublicBet = GetBet(myClosedPublicBetId);
            _myOtherBattleOpenedPrivateBet = GetBet(myOtherBattleOpenedPrivateBetId);
            _notMyOpenedPrivateBet = GetBet(notMyOpenedPrivateBetId);
        }
Exemplo n.º 3
0
        private void AssertNotClosedNotEditableBetCommon(Bet bet, BetViewModel betViewModel)
        {
            Assert.IsNull(betViewModel.CloseDateAndScreenshot);
            Assert.IsNull(betViewModel.StatusActionImage);
            Assert.AreEqual(0, betViewModel.Result);

            Assert.IsNull(betViewModel.StatusActionImages);
        }
Exemplo n.º 4
0
        private void AssertNotVisibleBetCommon(Bet bet, bool isClosed, bool isEditable, string invisibleIconClass, string invisibleIconTitle, BetViewModel betViewModel)
        {
            Assert.AreEqual(bet.Id, betViewModel.BetId);
            Assert.IsNull(betViewModel.Title);
            Assert.IsNull(betViewModel.Url);
            Assert.AreEqual(0, betViewModel.Amount);
            Assert.AreEqual(0, betViewModel.Coefficient);

            Assert.AreEqual(isClosed, betViewModel.IsClosed);
            Assert.AreEqual(isEditable, betViewModel.IsEditable);

            Assert.IsFalse(betViewModel.IsVisible);
            Assert.AreEqual(invisibleIconClass, betViewModel.InvisibleIconClass);
            Assert.AreEqual(invisibleIconTitle, betViewModel.InvisibleIconTitle);

            AssertNotVisibleDateAndScreenshot(bet.OpenBetScreenshot.CreationDateTime, betViewModel.OpenDateAndScreenshot);
        }
Exemplo n.º 5
0
        private void AssertClosedBetCommon(Bet bet, bool visible, BetViewModel betViewModel)
        {
            if (visible)
                AssertVisibleDateAndScreenshot(bet.CloseBetScreenshot.CreationDateTime, Bets.MakingScreenshot, "sc_inprogress", null, betViewModel.CloseDateAndScreenshot);
            else
                AssertNotVisibleDateAndScreenshot(bet.CloseBetScreenshot.CreationDateTime, betViewModel.CloseDateAndScreenshot);
            AssertSucceedStatusActionImage(bet.Id, betViewModel.StatusActionImage);
            Assert.AreEqual(bet.Result, betViewModel.Result);

            Assert.IsNull(betViewModel.StatusActionImages);
        }
Exemplo n.º 6
0
 private void AssertClosedPublicTeamBet(Bet bet, BetViewModel betViewModel)
 {
     AssertClosedPublicUserBet(bet, betViewModel);
     //ToDo: Add user and battle validation
 }
Exemplo n.º 7
0
        private void AssertVisibleBetCommon(Bet bet, bool isClosed, bool isEditable, BetViewModel betViewModel)
        {
            Assert.AreEqual(bet.Id, betViewModel.BetId);
            Assert.AreEqual(bet.Title, betViewModel.Title);
            Assert.AreEqual(bet.Url, betViewModel.Url);
            Assert.AreEqual(bet.Amount, betViewModel.Amount);
            Assert.AreEqual(bet.Coefficient, betViewModel.Coefficient);

            Assert.AreEqual(isClosed, betViewModel.IsClosed);
            Assert.AreEqual(isEditable, betViewModel.IsEditable);

            Assert.IsTrue(betViewModel.IsVisible);
            Assert.IsNull(betViewModel.InvisibleIconClass);

            AssertVisibleDateAndScreenshot(bet.OpenBetScreenshot.CreationDateTime, Bets.MakingScreenshot, "sc_inprogress", null, betViewModel.OpenDateAndScreenshot);
        }
Exemplo n.º 8
0
        private void AssertClosedPublicUserBet(Bet bet, BetViewModel betViewModel)
        {
            AssertVisibleBetCommon(bet, true, false, betViewModel);

            AssertClosedBetCommon(bet, true, betViewModel);
        }
Exemplo n.º 9
0
 private void AssertOpenedPrivateTeamBet(Bet beet, BetViewModel betViewModel)
 {
     AssertOpenedPrivateUserBet(beet, betViewModel);
     //ToDo: Add Battle and User validation
 }
Exemplo n.º 10
0
        private void AssertClosedPrivateUserBet(Bet bet, BetViewModel betViewModel)
        {
            AssertNotVisibleBetCommon(bet, true, false, "eye_red", Bets.BetIsPrivate, betViewModel);

            AssertClosedBetCommon(bet, false, betViewModel);
        }
Exemplo n.º 11
0
        private void AssertOpenedPublicUserBet(Bet bet, BetViewModel betViewModel)
        {
            AssertNotVisibleBetCommon(bet, false, false, "eye_blek", Bets.BetIsNotClosed, betViewModel);

            AssertNotClosedNotEditableBetCommon(bet, betViewModel);
        }
Exemplo n.º 12
0
 private void AssertClosedMyBet(Bet bet, BetViewModel betViewModel)
 {
     AssertClosedMyBattleBet(bet, betViewModel);
     //ToDo: Add battle-related properties validation
 }
Exemplo n.º 13
0
        private void AssertClosedMyBattleBet(Bet bet, BetViewModel betViewModel)
        {
            AssertVisibleBetCommon(bet, true, true, betViewModel);

            AssertClosedBetCommon(bet, true, betViewModel);
        }
Exemplo n.º 14
0
        private void AssertOpenedMyBattleBet(Bet bet, BetViewModel betViewModel)
        {
            AssertVisibleBetCommon(bet, false, true, betViewModel);

            AssertNotClosedEditableBetCommon(bet, betViewModel);
        }