コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: BetController.cs プロジェクト: plubon/dotNet
 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();
 }
コード例 #3
0
ファイル: CreateTests.cs プロジェクト: ASE-Project-4/Web
        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();
        }
コード例 #4
0
ファイル: UnitOfWork.cs プロジェクト: ASE-Project-4/Web
 public UnitOfWork(Context context)
 {
     _context = context;
     Bet      = new BetRepository(_context);
     Lobby    = new LobbyRepository(_context);
     User     = new UserRepository(_context);
     Outcome  = new OutcomeRepository(_context);
 }
コード例 #5
0
        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)));
        }
コード例 #6
0
        public MarketServiceTests()
        {
            var eventRepo  = new EventRepository();
            var marketRepo = new MarketRepository();
            var betRepo    = new BetRepository();

            MarketService = new MarketService(marketRepo, new BetService(betRepo, eventRepo, marketRepo));
        }
コード例 #7
0
 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;
 }
コード例 #8
0
 /// <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);
 }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: ShowTests.cs プロジェクト: ASE-Project-4/Web
        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>());
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
ファイル: ShowTests.cs プロジェクト: ASE-Project-4/Web
        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));
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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());
        }
コード例 #21
0
 public BetService(BetRepository repository)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }
コード例 #22
0
 public List <Bet> GetAll()
 {
     return(BetRepository.GetAll());
 }
コード例 #23
0
 public List <Bet> GetAllByMarketId(string marketId)
 {
     return(BetRepository.GetAllByMarketId(marketId));
 }
コード例 #24
0
ファイル: BetBll.cs プロジェクト: Jair333771/Roulette
 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;
 }
コード例 #25
0
 public Bet GetById(string betId)
 {
     return(BetRepository.GetById(betId));
 }
コード例 #26
0
 public Bet UpdateBet(Bet existingBet)
 {
     return(BetRepository.Update(existingBet));
 }
コード例 #27
0
 public Bet CreateBet(Bet newBet)
 {
     //validate new market
     validateNewBet(newBet);
     return(BetRepository.Create(newBet));
 }
コード例 #28
0
 public void DeleteBet(string betId)
 {
     BetRepository.Delete(betId);
 }
コード例 #29
0
 public UnitOfWorkSqlServerRepository(SqlConnection context, SqlTransaction transaction)
 {
     RouletteRepository = new RouletteRepository(context, transaction);
     BetRepository      = new BetRepository(context, transaction);
     ClientRepository   = new ClientRepository(context, transaction);
 }
コード例 #30
0
 public void CreateTableTest()
 {
     var repo = new BetRepository(new Deserializer());
 }