public async Task GetAllTest() { var repo = new BetRepository(new Deserializer()); var lengthBefore = (await repo.GetAllAsync()).Count; var bet1 = new Bet { Id = Guid.NewGuid(), BetSize = 7, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome3" }; await repo.CreateAsync(bet1); Thread.Sleep(1000); var bet2 = new Bet { Id = Guid.NewGuid(), BetSize = 9, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome5" }; await repo.CreateAsync(bet2); Thread.Sleep(1000); var bet3 = new Bet { Id = Guid.NewGuid(), BetSize = 12, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome3" }; await repo.CreateAsync(bet3); var events = await repo.GetAllAsync(); Assert.AreEqual(lengthBefore + 3, events.Count); }
public IHttpActionResult Bet([FromBody]dynamic value) { var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault()); var mId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("matchId").FirstOrDefault()); var homeScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("homeScore").FirstOrDefault()); var awayScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("awayScore").FirstOrDefault()); var mRepo = new MatchRepository(); if (!mRepo.ContainsId(mId)) return NotFound(); var uRepo = new UserRepository(); if (!uRepo.ContainsId(uId)) return NotFound(); var brepo = new BetRepository(); if (brepo.ContainsBet(mId, uId)) { var b = brepo.GetByMatchAndUserIds(mId, uId); b.HomeTeamScore = homeScore; b.AwayTeamScore = awayScore; brepo.SaveOrUpdate(b); } else { var b = new Bet(); b.AwayTeamScore = awayScore; b.HomeTeamScore = homeScore; b.Match = mRepo.GetById(mId); b.User = uRepo.GetById(uId); brepo.SaveOrUpdate(b); } return Ok(); }
public void Create_CallsRepositoryAdd() { // Register a lobby with the mock. var lobby = new Lobby() { Bets = new List <Bet>() }; LobbyRepository.Get(Arg.Any <long>()).Returns(lobby); // Assert that we hit the repository. BetRepository.DidNotReceive().Add(Arg.Any <Bet>()); MyWork.DidNotReceive().Complete(); var viewModel = new CreateBetViewModel() { BuyIn = "0", Description = "Description", LobbyID = 0, StartDate = DateTime.Now.ToLongDateString(), StopDate = DateTime.Now.ToLongDateString(), Title = "Name" }; uut.Create(viewModel); Assert.That(uut.ModelState.IsValid); // Assert that we hit the repository. BetRepository.Received(1).Add(Arg.Any <Bet>()); MyWork.Received(1).Complete(); }
public UnitOfWork(Context context) { _context = context; Bet = new BetRepository(_context); Lobby = new LobbyRepository(_context); User = new UserRepository(_context); Outcome = new OutcomeRepository(_context); }
public MarketControllerTests() { var eventRepo = new EventRepository(); var marketRepo = new MarketRepository(); var betRepo = new BetRepository(); this.MarketController = new MarketController(new MarketService(marketRepo, new BetService(betRepo, eventRepo, marketRepo))); }
public MarketServiceTests() { var eventRepo = new EventRepository(); var marketRepo = new MarketRepository(); var betRepo = new BetRepository(); MarketService = new MarketService(marketRepo, new BetService(betRepo, eventRepo, marketRepo)); }
public RouletteBll(ResponseModel response, MessageListModel messageList, List <BetResponseModel> betResponseModelList, BetResponseModel betResponseModel, IRepository <Roulette> rouletteRepo, IRepository <Consumer> consumerRepo, BetRepository betRepo) : base(response, messageList) { this.betResponseModelList = betResponseModelList; this.betResponseModel = betResponseModel; this.rouletteRepo = rouletteRepo; this.consumerRepo = consumerRepo; this.betRepo = betRepo; }
/// <summary> /// Initializes the instance of the unit of work with context /// </summary> /// <param name="context"></param> public UnitOfWork(ApplicationDbContext context) { _context = context; ApplicationUserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context)); ApplicationRoleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context)); CarRepository = new CarRepository(context); LotRepository = new LotRepository(context); BetRepository = new BetRepository(context); Logger = new Logger(context); }
public async Task DeleteTest() { var repo = new BetRepository(new Deserializer()); var bet3 = new Bet { Id = Guid.NewGuid(), BetSize = 7, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome3" }; await repo.CreateAsync(bet3); await repo.DeleteAsync(bet3.Id); }
public EventControllerTests() { var eventRepo = new EventRepository(); var marketRepo = new MarketRepository(); var betRepo = new BetRepository(); var betService = new BetService(betRepo, eventRepo, marketRepo); var eventService = new EventService(eventRepo, new MarketService(marketRepo, betService)); EventController = new EventController(eventService); }
public async Task CreateTest() { var repo = new BetRepository(new Deserializer()); var bet1 = new Bet { Id = Guid.NewGuid(), BetSize = 4, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome" }; var createdEvent = await repo.CreateAsync(bet1); Assert.AreEqual(bet1.Id, createdEvent.Id); }
public async Task BetRepository_GetByIdWithDetailsAsync_ReturnsProperBetWithDetails() { var bet = GetTestBets().First(); var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(GetTestBets()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var result = await betRepo.GetByIdWithDetailsAsync(bet.Id); Assert.AreEqual(bet.Id, result.Id); Assert.AreEqual(bet.BetDate, result.BetDate); Assert.AreEqual(bet.Lot?.Id, result.Lot?.Id); }
public BetControllerTests() { var betRepo = new BetRepository(); var marketRepo = new MarketRepository(); EventRepository = new EventRepository(); var betService = new BetService(betRepo, EventRepository, marketRepo); var marketService = new MarketService(marketRepo, betService); var eventService = new EventService(EventRepository, marketService); MarketController = new MarketController(marketService); EventController = new EventController(eventService); BetController = new BetController(betService); }
public void Show_CallsRepositoryGet() { // Register a bet with the mock. var bet = new Bet(); BetRepository.Get(Arg.Any <long>()).Returns(bet); // Assert that we hit the repository. BetRepository.DidNotReceive().Get(Arg.Any <long>()); uut.Show(0); // Assert that we hit the repository. BetRepository.Received(1).Get(Arg.Any <long>()); }
public async Task UpdateTest() { var repo = new BetRepository(new Deserializer()); var bet1 = new Bet { Id = Guid.NewGuid(), BetSize = 5, UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), Outcome = "outcome2" }; await repo.CreateAsync(bet1); var bet2 = new Bet { Id = bet1.Id, BetSize = 7, UserId = bet1.UserId, EventId = bet1.EventId, Outcome = "outcome2" }; var updatedEvent = await repo.UpdateAsync(bet2); Assert.AreEqual(updatedEvent.Id, bet2.Id); }
public void BetRepository_FindAllWithDetails_ReturnsAllBetsWithDetails() { var bets = GetTestBets().ToList(); var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(bets.AsQueryable()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var result = betRepo.FindAllWithDetails().ToList(); Assert.AreEqual(bets.Count, result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(bets[i].Id, result[i].Id); Assert.AreEqual(bets[i].BetDate, result[i].BetDate); Assert.AreEqual(bets[i].Lot?.Id, result[i].Lot?.Id); } }
public void Show_WithInputId_CallsCorrectGet() { // Register a bet with the mock. var bet = new Bet(); BetRepository.Get(Arg.Any <long>()).Returns(bet); // Setup capture of the argument. long key = 0; BetRepository.Get(Arg.Do <long>(i => key = i)); long passedKey = 100; // Act. uut.Show(passedKey); // Assert that we passed the correct id. Assert.That(key, Is.EqualTo(passedKey)); }
public void BetRepository_Delete_DeletesBet() { var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(GetTestBets()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var bet = new Bet { Id = 1, BetDate = new DateTime(2020, 11, 04), LotId = 1 }; betRepo.Delete(bet); mockDbSet.Verify( m => m.Remove(It.Is <Bet>( l => l.Id == bet.Id && l.BetDate == bet.BetDate && l.LotId == bet.LotId)), Times.Once); }
public void BetRepository_Update_UpdatesBet() { var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(GetTestBets()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var bet = new Bet { Id = 1, BetDate = new DateTime(2020, 11, 15), LotId = 1, UserId = "1" }; betRepo.Update(bet); mockDbSet.Verify( m => m.Attach(It.Is <Bet>( l => l.Id == bet.Id && l.BetDate == bet.BetDate && l.LotId == bet.LotId)), Times.Once); }
public IHttpActionResult Bet([FromBody] dynamic value) { var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault()); var mId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("matchId").FirstOrDefault()); var homeScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("homeScore").FirstOrDefault()); var awayScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("awayScore").FirstOrDefault()); var mRepo = new MatchRepository(); if (!mRepo.ContainsId(mId)) { return(NotFound()); } var uRepo = new UserRepository(); if (!uRepo.ContainsId(uId)) { return(NotFound()); } var brepo = new BetRepository(); if (brepo.ContainsBet(mId, uId)) { var b = brepo.GetByMatchAndUserIds(mId, uId); b.HomeTeamScore = homeScore; b.AwayTeamScore = awayScore; brepo.SaveOrUpdate(b); } else { var b = new Bet(); b.AwayTeamScore = awayScore; b.HomeTeamScore = homeScore; b.Match = mRepo.GetById(mId); b.User = uRepo.GetById(uId); brepo.SaveOrUpdate(b); } return(Ok()); }
public BetService(BetRepository repository) { _repository = repository ?? throw new ArgumentNullException(nameof(repository)); }
public List <Bet> GetAll() { return(BetRepository.GetAll()); }
public List <Bet> GetAllByMarketId(string marketId) { return(BetRepository.GetAllByMarketId(marketId)); }
public BetBll(ResponseModel response, MessageListModel messageList, BetRepository betRepo, AppRepository <Consumer> consumerRepo, IRepository <Roulette> rouletteRepo) : base(response, messageList) { this.betRepo = betRepo; this.rouletteRepo = rouletteRepo; this.consumerRepo = consumerRepo; }
public Bet GetById(string betId) { return(BetRepository.GetById(betId)); }
public Bet UpdateBet(Bet existingBet) { return(BetRepository.Update(existingBet)); }
public Bet CreateBet(Bet newBet) { //validate new market validateNewBet(newBet); return(BetRepository.Create(newBet)); }
public void DeleteBet(string betId) { BetRepository.Delete(betId); }
public UnitOfWorkSqlServerRepository(SqlConnection context, SqlTransaction transaction) { RouletteRepository = new RouletteRepository(context, transaction); BetRepository = new BetRepository(context, transaction); ClientRepository = new ClientRepository(context, transaction); }
public void CreateTableTest() { var repo = new BetRepository(new Deserializer()); }