Exemple #1
0
            public async Task InitializeAsync()
            {
                var partnerId = Guid.NewGuid();

                var(originalEvent, _) = EventBuilder.CreateEvent("Cool OG Event")
                                        .WithPartnerId(partnerId)
                                        .Build();

                using (var session = _factory.SessionFactory.CreateCommandSession())
                {
                    session.Execute(new InsertEventCommand(originalEvent));
                    session.Commit();
                }

                var(updatedEvent, updatedEventWriteModel) = EventBuilder.CreateEvent("Cool Updated Event")
                                                            .WithPartnerId(partnerId)
                                                            .WithEventId(originalEvent.EventId)
                                                            .Build();
                UpdatedEvent = updatedEvent;

                var httpContent = new ObjectContent <EventWriteModel>(updatedEventWriteModel, new JsonMediaTypeFormatter(), "application/json");

                Response = await _factory.HttpClient
                           .PutAsync($"/api/events/{originalEvent.EventId}", httpContent);
            }
            public async Task InitializeAsync()
            {
                var(@event, eventWriteModel) = EventBuilder.CreateEvent("Cool Event").Build();
                Event = @event;

                var httpContent = new ObjectContent <EventWriteModel>(eventWriteModel, new JsonMediaTypeFormatter(), "application/json");

                Response = await _factory.HttpClient
                           .PostAsync("/api/events", httpContent);
            }
Exemple #3
0
        public async Task ReturnsNoContentWhenUpdateSuccessful()
        {
            var(@event, eventWriteModel) = EventBuilder.CreateEvent("Cool Event").Build();

            _eventRepository
            .UpdateEventAsync(Arg.Is <Guid>(g => g == @event.EventId),
                              Arg.Is <EventWriteModel>(e => e == eventWriteModel))
            .Returns(true);

            var result = await _controller.Put(@event.EventId, eventWriteModel);

            result.Should().BeOfType <NoContentResult>();
        }
Exemple #4
0
        public async Task ReturnsOkWithEventWhenMatchingEventId()
        {
            var(@event, _) = EventBuilder.CreateEvent("Cool Event").Build();

            _eventRepository
            .GetEventByIdAsync(Arg.Is <Guid>(g => g == @event.EventId))
            .Returns(@event);

            var result = await _controller.Get(@event.EventId);

            result.Should().BeOfType <OkObjectResult>().Which.Value
            .Should().BeEquivalentTo(@event);
        }
            public async Task InitializeAsync()
            {
                var(@event, _) = EventBuilder.CreateEvent("Cool Removable Event").Build();

                using (var session = _factory.SessionFactory.CreateCommandSession())
                {
                    await session.ExecuteAsync(new InsertEventCommand(@event));

                    session.Commit();
                }

                Response = await _factory.HttpClient
                           .DeleteAsync($"/api/events/{@event.EventId}");
            }
Exemple #6
0
        public async Task ReturnsOkWithEventsWhenSomeEvents()
        {
            var(event1, _) = EventBuilder.CreateEvent("Cool Event").Build();
            var(event2, _) = EventBuilder.CreateEvent("Cooler Event").Build();
            var(event3, _) = EventBuilder.CreateEvent("Coolest Event").Build();

            _eventRepository
            .GetAllEventsAsync()
            .Returns(new[] { event1, event2, event3 });

            var result = await _controller.GetAll();

            result.Should().BeOfType <OkObjectResult>().Which.Value
            .Should().BeEquivalentTo(new[] {
                event1,
                event2,
                event3
            });
        }
Exemple #7
0
        public async Task ReturnsCreatedWhenModelStateValid()
        {
            var(@event, eventWriteModel) = EventBuilder.CreateEvent("Cool Event").Build();

            _eventRepository
            .SaveEventAsync(Arg.Is <EventWriteModel>(e => e == eventWriteModel))
            .Returns(@event);

            var result = await _controller.Post(eventWriteModel);

            result.Should().BeOfType <CreatedAtActionResult>().Which
            .Should().BeEquivalentTo(new
            {
                ActionName  = nameof(EventsController.Get),
                RouteValues = new RouteValueDictionary {
                    { "eventId", @event.EventId }
                },
                Value = @event
            });
        }
            public async Task InitializeAsync()
            {
                PartnerId      = Guid.NewGuid();
                var(event1, _) = EventBuilder.CreateEvent("Cool Event").WithPartnerId(PartnerId).Build();
                var(event2, _) = EventBuilder.CreateEvent("Cool Event").WithPartnerId(PartnerId).Build();
                Events         = new List <Event> {
                    event1, event2
                };

                using (var session = _factory.SessionFactory.CreateCommandSession())
                {
                    await session.ExecuteAsync(new InsertEventCommand(event1));

                    await session.ExecuteAsync(new InsertEventCommand(event2));

                    session.Commit();
                }

                Response = await _factory.HttpClient
                           .GetAsync($"/api/events/bypartner/{PartnerId}");
            }
Exemple #9
0
        public async Task ReturnsOkWithEventsWhenSomeEventsForPartner()
        {
            var partnerId = Guid.NewGuid();

            var(event1, _) = EventBuilder.CreateEvent("Cool Event").WithPartnerId(partnerId).Build();
            var(event2, _) = EventBuilder.CreateEvent("Cooler Event").WithPartnerId(partnerId).Build();
            var(event3, _) = EventBuilder.CreateEvent("Coolest Event").WithPartnerId(partnerId).Build();

            _eventRepository
            .GetAllEventsForPartnerAsync(Arg.Is <Guid>(g => g == partnerId))
            .Returns(new[] { event1, event2, event3 });

            var result = await _controller.GetAllForPartner(partnerId);

            result.Should().BeOfType <OkObjectResult>().Which.Value
            .Should().BeEquivalentTo(new[] {
                event1,
                event2,
                event3
            });
        }
Exemple #10
0
            public async Task InitializeAsync()
            {
                var(event1, _) = EventBuilder.CreateEvent("Cool Event").Build();
                var(event2, _) = EventBuilder.CreateEvent("Cooler Event").Build();
                var(event3, _) = EventBuilder.CreateEvent("Coolest Event").Build();
                Event1         = event1;
                Event2         = event2;
                Event3         = event3;

                using (var session = _factory.SessionFactory.CreateCommandSession())
                {
                    await session.ExecuteAsync(new InsertEventCommand(Event1));

                    await session.ExecuteAsync(new InsertEventCommand(Event2));

                    await session.ExecuteAsync(new InsertEventCommand(Event3));

                    session.Commit();
                }

                Response = await _factory.HttpClient
                           .GetAsync("/api/events/all");
            }
Exemple #11
0
        static void Main(string[] args)
        {
            var eventService = new EventService(new ProfitCalculatorService());

            var eventName = "Paddy Power Cup Final";

            Console.WriteLine($"CreatingEvent {eventName}");
            var bettingEvent = EventBuilder.CreateEvent(eventName, Sport.Football);

            var marketName = "Outright result in normal time";

            var market1 = EventBuilder.CreateMarket(marketName);

            bettingEvent.WithMarket(market1);

            var team1Win = EventBuilder.CreateSelection(11, 4, true, 1, 0);

            market1.WithSelection(team1Win);
            var team2Win = EventBuilder.CreateSelection(13, 5, true, 0, 1);

            market1.WithSelection(team2Win);
            var draw = EventBuilder.CreateSelection(4, 6, true, 0, 0);

            market1.WithSelection(draw);

            var marketName2 = "Correct Score";

            var market2 = EventBuilder.CreateMarket(marketName2);

            bettingEvent.WithMarket(market2);

            var team1W1X0 = EventBuilder.CreateSelection(4, 9, false, 1, 0);

            market2.WithSelection(team1W1X0);
            var team1W2X0 = EventBuilder.CreateSelection(11, 2, false, 2, 0);

            market2.WithSelection(team1W2X0);
            var team1W2X1 = EventBuilder.CreateSelection(22, 1, false, 2, 1);

            market2.WithSelection(team1W2X1);
            var team1W3X0 = EventBuilder.CreateSelection(55, 1, false, 3, 0);

            market2.WithSelection(team1W3X0);
            var team1W3X1 = EventBuilder.CreateSelection(255, 1, false, 3, 1);

            market2.WithSelection(team1W3X1);
            var draw0X0 = EventBuilder.CreateSelection(9, 2, false, 0, 0);

            market2.WithSelection(draw0X0);
            var draw1X1 = EventBuilder.CreateSelection(175, 1, false, 1, 1);

            market2.WithSelection(draw1X1);
            var draw2x2 = EventBuilder.CreateSelection(225, 1, false, 2, 2);

            market2.WithSelection(draw2x2);
            var team2W1X0 = EventBuilder.CreateSelection(12, 1, false, 0, 1);

            market2.WithSelection(team2W1X0);
            var team2W2x0 = EventBuilder.CreateSelection(9, 2, false, 0, 2);

            market2.WithSelection(team2W2x0);
            var team2W2X1 = EventBuilder.CreateSelection(17, 1, false, 1, 2);

            market2.WithSelection(team2W2X1);
            var team2W3X0 = EventBuilder.CreateSelection(16, 5, false, 0, 3);

            market2.WithSelection(team2W3X0);
            var team2W3X1 = EventBuilder.CreateSelection(14, 1, false, 1, 3);

            market2.WithSelection(team2W3X1);


            var eventName1 = "L Harte v C Ryan tennis match";

            Console.WriteLine($"CreatingEvent {eventName}");

            var tennisBettingEvent = EventBuilder.CreateEvent(eventName1, Sport.Tennis);

            var tennisMarketName = "Match Betting market";
            var tennisMarket1    = EventBuilder.CreateMarket(tennisMarketName);

            tennisBettingEvent.WithMarket(tennisMarket1);

            var play1Win = EventBuilder.CreateSelection(9, 4, true, 1, 0);

            tennisMarket1.WithSelection(play1Win);
            var play2Win = EventBuilder.CreateSelection(3, 10, true, 0, 1);

            tennisMarket1.WithSelection(play2Win);

            tennisMarketName = "To win Set 2 1 st game";
            var tennisMarket2 = EventBuilder.CreateMarket(tennisMarketName);

            tennisBettingEvent.WithMarket(tennisMarket2);

            var play1WinGame1 = EventBuilder.CreateSelection(4, 7, false, 1, 0).
                                WithTennisWinningConditions(1, true, true, 2);

            tennisMarket2.WithSelection(play1WinGame1);
            var play2WinGame1 = EventBuilder.CreateSelection(5, 4, false, 0, 1).
                                WithTennisWinningConditions(1, true, false, 2);

            tennisMarket2.WithSelection(play2WinGame1);


            Console.WriteLine($"Registering Bets");

            bettingEvent.WithBet(EventBuilder.CreateBet(4m, team1Win));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(5m, play2WinGame1));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(5m, play2Win));
            bettingEvent.WithBet(EventBuilder.CreateBet(2m, team1W3X1));
            bettingEvent.WithBet(EventBuilder.CreateBet(1m, team2W1X0));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(5m, play1WinGame1));
            bettingEvent.WithBet(EventBuilder.CreateBet(2m, team1W3X1));
            bettingEvent.WithBet(EventBuilder.CreateBet(1m, team2W2X1));
            bettingEvent.WithBet(EventBuilder.CreateBet(4m, draw));
            bettingEvent.WithBet(EventBuilder.CreateBet(2m, team1Win));
            bettingEvent.WithBet(EventBuilder.CreateBet(10m, team1W2X0));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(6m, play2Win));
            bettingEvent.WithBet(EventBuilder.CreateBet(1m, team2Win));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(0.5m, play1Win));
            bettingEvent.WithBet(EventBuilder.CreateBet(2m, team1W2X0));
            bettingEvent.WithBet(EventBuilder.CreateBet(1m, team2Win));
            tennisBettingEvent.WithBet(EventBuilder.CreateBet(1m, play1WinGame1));
            bettingEvent.WithBet(EventBuilder.CreateBet(11m, team1W1X0));

            Console.WriteLine($"Results:");

            Console.WriteLine($"Clonskeagh 2 - 1 Tallaght");
            Console.WriteLine($"C Ryan beats L Harte outright");
            Console.WriteLine($"L Harte wins Set 2 1 st game");

            bettingEvent.WithScoreResults(2, 1);
            tennisBettingEvent.WithScoreResults(0, 3);
            tennisBettingEvent.WithGame(2, 1, true);

            var total1 = 0m;
            var total2 = 0m;

            total1 = eventService.CalculateEventProfitAsync(bettingEvent).Result;

            total2 = eventService.CalculateEventProfitAsync(tennisBettingEvent).Result;


            Console.WriteLine($"Calculating profit:");
            Console.WriteLine(total1);
            Console.WriteLine(total2);

            Console.WriteLine($"Balance: {total1 + total2}");
            Console.ReadKey();
        }