Ejemplo n.º 1
0
        public void PlaceBet_ShouldFillAllRequiredFieldsEven()
        {
            // Arrange
            User user = new User("Test", repo.CreateUserDAL(), repo.CreateBetDAL())
            {
                Id = 50
            };
            IBet bet = new EvenUnevenBet(true)
            {
                Stake = 200
            };

            using (TransactionScope scope = new TransactionScope())
            {
                // Act
                user.MakeBet(bet);

                var savedBet = repo.CreateBetDAL().GetCurrentBet(user.Id);

                // Assert
                Assert.Equal(bet.Stake, savedBet.Stake);
                Assert.Equal(bet.Odd, savedBet.Odd);
                // Cast this to int because that's the value you would get from the database.
                Assert.Equal(bet.GetBetSpecificInfo()["IsEven"], savedBet.GetBetSpecificInfo()["Even"]);
            }
        }
Ejemplo n.º 2
0
        private IBet MakeBetObject(IBetDTO dto)
        {
            var  info   = dto.GetBetSpecificInfo();
            IBet output = null;

            if (info.TryGetValue("Color", out object temp))
            {
                if (temp != null)
                {
                    int color = (int)temp;
                    output = new ColorBet((IPocketColor)color)
                    {
                        Id    = dto.Id,
                        Stake = dto.Stake,
                    };
                }
            }
            else if (info.TryGetValue("FirstNumber", out object temp3) && info.TryGetValue("SecondNumber", out object temp4))
            {
                if (temp3 != null && temp4 != null)
                {
                    int firstNumber  = (int)temp3;
                    int secondNumber = (int)temp4;
                    output = new NeighbourBet((IPocketNumber)firstNumber, (IPocketNumber)secondNumber)
                    {
                        Id    = dto.Id,
                        Stake = dto.Stake,
                    };
                }
            }
            else if (info.TryGetValue("Number", out object temp5))
            {
                if (temp5 != null)
                {
                    int number = (int)temp;
                    output = new SingleNumberBet((IPocketNumber)number)
                    {
                        Id    = dto.Id,
                        Stake = dto.Stake,
                    };
                }
            }
            else if (info.TryGetValue("IsEven", out object temp2))
            {
                if (temp2 != null)
                {
                    bool isEven = (bool)temp;
                    output = new EvenUnevenBet(isEven)
                    {
                        Id    = dto.Id,
                        Stake = dto.Stake,
                    };
                }
            }

            return(output);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a dto object of the specified bet
        /// Checks which bet type it is and maps this to dto object.
        /// </summary>
        /// <param name="bet"></param>
        /// <returns></returns>
        private IBetDTO MakeBetDTO(IBet bet)
        {
            var     info   = bet.GetBetSpecificInfo();
            IBetDTO output = null;

            if (bet.Type == BetType.Color)
            {
                if (info.TryGetValue("Color", out object temp))
                {
                    int color = (int)temp;
                    output = new ColorBet((IPocketColor)color)
                    {
                        Id    = bet.Id,
                        Stake = bet.Stake,
                    };
                }
            }
            else if (bet.Type == BetType.EvenUneven)
            {
                if (info.TryGetValue("IsEven", out object temp))
                {
                    bool isEven = (bool)temp;
                    output = new EvenUnevenBet(isEven)
                    {
                        Id    = bet.Id,
                        Stake = bet.Stake,
                    };
                }
            }
            else if (bet.Type == BetType.Neighbour)
            {
                if (info.TryGetValue("FirstNumber", out object temp) && info.TryGetValue("SecondNumber", out object temp2))
                {
                    int firstNumber  = (int)temp;
                    int secondNumber = (int)temp2;
                    output = new NeighbourBet((IPocketNumber)firstNumber, (IPocketNumber)secondNumber)
                    {
                        Id    = bet.Id,
                        Stake = bet.Stake,
                    };
                }
            }
            else if (bet.Type == BetType.Single)
            {
                if (info.TryGetValue("Number", out object temp))
                {
                    int number = (int)temp;
                    output = new SingleNumberBet((IPocketNumber)number)
                    {
                        Id    = bet.Id,
                        Stake = bet.Stake,
                    };
                }
            }
            return(output);
        }
Ejemplo n.º 4
0
        private IBet MakeBetObject(IBetDTO bet)
        {
            var  info   = bet.GetBetSpecificInfo();
            IBet output = null;

            if (info.TryGetValue("Color", out object tempcolor))
            {
                int color = (int)tempcolor;
                output = new ColorBet((IPocketColor)color)
                {
                    Id    = bet.Id,
                    Stake = bet.Stake,
                };
            }

            else if (info.TryGetValue("IsEven", out object tempEven))
            {
                bool isEven = (bool)tempEven;
                output = new EvenUnevenBet(isEven)
                {
                    Id    = bet.Id,
                    Stake = bet.Stake,
                };
            }

            else if (info.TryGetValue("FirstNumber", out object first) && info.TryGetValue("SecondNumber", out object second))
            {
                int firstNumber  = (int)first;
                int secondNumber = (int)second;
                output = new NeighbourBet((IPocketNumber)firstNumber, (IPocketNumber)secondNumber)
                {
                    Id    = bet.Id,
                    Stake = bet.Stake,
                };
            }

            else if (info.TryGetValue("Number", out object tempNumber))
            {
                int number = (int)tempNumber;
                output = new SingleNumberBet((IPocketNumber)number)
                {
                    Id    = bet.Id,
                    Stake = bet.Stake,
                };
            }

            return(output);
        }