Exemple #1
0
        public void WhenGettingAnInvalidBookItShouldThrow()
        {
            // Arrange
            var fakeHandler = new TestDelegatingHandler <Customer>(HttpStatusCode.NotFound);
            var fakeServer  = new HttpServer(new HttpConfiguration(), fakeHandler);
            var service     = new CustomerBetService(new HttpClient(fakeServer));

            // Act
            var result = service.GetCustomers();

            // Assert
            Assert.Fail();
        }
        public void GetBets_Should_Throw_Exception_If_Status_Not_Ok()
        {
            var client = new Mock <ICustomerBetClient>();

            client.Setup(t => t.GetAsync("api/GetBets?code=code123&name=user123"))
            .ReturnsAsync(GenerateResponse <IEnumerable <BetDto> >(null, HttpStatusCode.NotFound));

            var target = new CustomerBetService(client.Object, _settings.Object);

            var ex = Assert.ThrowsAsync <Exception>(() => target.GetBetsAsync());

            Assert.That(ex.Message, Is.EqualTo("Failed to get the bets"));
        }
        public async Task GetCustomers_Can_Get_All_Customers()
        {
            var client = new Mock <ICustomerBetClient>();

            client.Setup(t => t.GetAsync("api/GetCustomers?code=code123&name=user123"))
            .ReturnsAsync(GenerateResponse <IEnumerable <CustomerDto> >(new[]
            {
                new CustomerDto {
                    Id = 1, Name = "Bob"
                },
                new CustomerDto {
                    Id = 2, Name = "Rodger"
                },
            }, HttpStatusCode.OK));

            var target = new CustomerBetService(client.Object, _settings.Object);
            var result = (await target.GetCustomersAsync()).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Name, Is.EqualTo("Bob"));
            Assert.That(result[1].Name, Is.EqualTo("Rodger"));
        }
Exemple #4
0
        public void WhenGettingAllCustomersTheyShouldBeReturned()
        {
            // Arrange
            var customers = new[] {
                new Customer {
                    Id = 1, Name = "Customer 1"
                },
                new Customer {
                    Id = 2, Name = "Customer 2"
                }
            };

            var fakehandler = new TestDelegatingHandler <Customer[]>(customers);
            var fakeServer  = new HttpServer(new HttpConfiguration(), fakehandler);
            var service     = new CustomerBetService(new HttpClient(fakeServer));

            // Act
            var result = service.GetCustomers();

            // Assert
            Assert.AreEqual(2, result.Count);
        }
        public async Task GetBet_Can_Get_All_Bets()
        {
            var client = new Mock <ICustomerBetClient>();

            client.Setup(t => t.GetAsync("api/GetBets?code=code123&name=user123"))
            .ReturnsAsync(GenerateResponse <IEnumerable <BetDto> >(new[]
            {
                new BetDto {
                    RaceId = 100
                },
                new BetDto {
                    RaceId = 200
                },
            }, HttpStatusCode.OK));


            var target = new CustomerBetService(client.Object, _settings.Object);
            var result = (await target.GetBetsAsync()).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].RaceId, Is.EqualTo(100));
            Assert.That(result[1].RaceId, Is.EqualTo(200));
        }
Exemple #6
0
        public PagedResult <CustomerBetVM> CustomerBets(BetTableSortBy sortBy, bool isAscending)
        {
            var service   = new CustomerBetService(new HttpClient());
            var customers = service.GetCustomers();
            var bets      = service.GetBets();

            var result = customers
                         .Join(bets, cust => cust.Id, bet => bet.CustomerId,
                               (cust, bet) => new CustomerBetVM()
            {
                CustomerName = cust.Name,
                RaceNumber   = bet.RaceId,
                ReturnStake  = bet.ReturnStake,
                Won          = bet.Won
            })
                         .OrderBy(sortBy.ToString(), isAscending).ToList();

            return(new PagedResult <CustomerBetVM>
            {
                Data = result,
                TotalCount = result.Count()
            });
        }
Exemple #7
0
        public void WhenGettingAllBetsTheyShouldBeReturned()
        {
            // Arrange
            var bets = new[] {
                new Bet {
                    CustomerId = 1, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = true
                },
                new Bet {
                    CustomerId = 2, RaceId = 1, HorseId = 5, ReturnStake = 200.0m, Won = false
                },
                new Bet {
                    CustomerId = 3, RaceId = 1, HorseId = 3, ReturnStake = 400.0m, Won = true
                },
                new Bet {
                    CustomerId = 4, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = false
                },
                new Bet {
                    CustomerId = 5, RaceId = 1, HorseId = 1, ReturnStake = 500.0m, Won = false
                },
                new Bet {
                    CustomerId = 6, RaceId = 1, HorseId = 5, ReturnStake = 2100.0m, Won = true
                },
                new Bet {
                    CustomerId = 7, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = false
                },
            };
            var fakehandler = new TestDelegatingHandler <Bet[]>(bets);
            var fakeServer  = new HttpServer(new HttpConfiguration(), fakehandler);
            var service     = new CustomerBetService(new HttpClient(fakeServer));

            // Act
            var result = service.GetBets();

            // Assert
            Assert.AreEqual(7, result.Count);
        }