public BetResponseModel RunRoulette(Bet bet, Consumer user) { var response = new BetResponseModel(); try { var rnd = new Random(); int colorValue = 2, numberValue = 35; var numberResult = rnd.Next(0, 36); var result = MyRoulette.Where(z => z.Value == numberResult).FirstOrDefault(); if (result != null) { response.Number = bet.Number = result.Value; response.Color = bet.Color = result.Color; var text = "Has ganado!"; if (bet.MyBet.ToLower().Equals(response.Color)) { user.Money += (bet.Amount * colorValue); } if (bet.MyBet.Equals(response.Number.ToString())) { user.Money += (bet.Amount * numberValue); } if (!bet.MyBet.Equals(response.Number.ToString()) && !bet.MyBet.ToLower().Equals(response.Color)) { user.Money -= bet.Amount; text = "Has perdido!"; } response.Message.Add($"{text}, tu saldo actual es : {user.Money}"); consumerRepo.Update(user); betRepo.Add(bet); } else { response.Message.Add($"Ha ocurrido un error al realizar la ejecución, inténtalo nuevamente."); } } catch (Exception ex) { throw; } return(response); }
public void BetRepository_Add_AddsBet() { var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(GetTestBets()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var bet = new Bet { Id = 100, BetDate = new DateTime(2020, 11, 15), LotId = 1 }; betRepo.Add(bet); mockDbSet.Verify( m => m.Add(It.Is <Bet>( l => l.Id == bet.Id && l.BetDate == bet.BetDate && l.LotId == bet.LotId)), Times.Once); }