Ejemplo n.º 1
0
        public async Task GetCustomerBetsTest()
        {
            // Arrange
            Mock <ICustomerBetsService> mockCustomerBetsService = new Mock <ICustomerBetsService>();

            CustomerBet[] customerBets = new CustomerBet[]
            {
                new CustomerBet
                {
                    Customer = new Customer
                    {
                        Id   = 1,
                        Name = "Rob"
                    },
                    Bets = new List <Bet>
                    {
                        new Bet {
                            CustomerId = 1, HorseId = 11, RaceId = 1, Stake = 100
                        },
                        new Bet {
                            CustomerId = 1, HorseId = 21, RaceId = 2, Stake = 150
                        },
                        new Bet {
                            CustomerId = 1, HorseId = 32, RaceId = 3, Stake = 200
                        }
                    }
                },
                new CustomerBet
                {
                    Customer = new Customer
                    {
                        Id   = 2,
                        Name = "Lachlan"
                    },
                    Bets = new List <Bet>
                    {
                        new Bet {
                            CustomerId = 2, HorseId = 21, RaceId = 1, Stake = 100
                        },
                        new Bet {
                            CustomerId = 2, HorseId = 22, RaceId = 2, Stake = 150
                        },
                        new Bet {
                            CustomerId = 2, HorseId = 31, RaceId = 3, Stake = 200
                        },
                        new Bet {
                            CustomerId = 2, HorseId = 55, RaceId = 5, Stake = 300
                        }
                    }
                }
            };

            mockCustomerBetsService.Setup(q => q.CalculateCustomerBetsAsync()).Returns(Task.FromResult(customerBets));

            CustomerBetsController controller = new CustomerBetsController(mockCustomerBetsService.Object);

            // Act
            CustomerBet[] result = await controller.Get();

            // Assert
            string expected = JsonConvert.SerializeObject(customerBets);
            string actual   = JsonConvert.SerializeObject(result);

            Assert.Equal(expected, actual);
        }
        public async Task ShouldReturnCustomerBets()
        {
            // Arrange
            var mockCustomerBetsCalculator = new Mock <ICustomerBetsCalculator>();
            var sampleData = new List <CustomerBet>
            {
                new CustomerBet
                {
                    Customer = new Customer
                    {
                        Id   = 1,
                        Name = "John"
                    },
                    Bets = new List <Bet>
                    {
                        new Bet {
                            CustomerId = 1, ReturnStake = 100, Won = false
                        },
                        new Bet {
                            CustomerId = 1, ReturnStake = 300, Won = true
                        },
                        new Bet {
                            CustomerId = 1, ReturnStake = 200, Won = false
                        }
                    }
                },
                new CustomerBet
                {
                    Customer = new Customer
                    {
                        Id   = 2,
                        Name = "Mike"
                    },
                    Bets = new List <Bet>
                    {
                        new Bet {
                            CustomerId = 2, ReturnStake = 400, Won = true
                        },
                        new Bet {
                            CustomerId = 2, ReturnStake = 500, Won = true
                        },
                        new Bet {
                            CustomerId = 2, ReturnStake = 600, Won = false
                        }
                    }
                }
            };

            mockCustomerBetsCalculator.Setup(x => x.CalculateCustomerBetsAsync()).Returns(Task.FromResult(sampleData));

            var controller = new CustomerBetsController(mockCustomerBetsCalculator.Object);

            // Act
            var result = await controller.Get();

            // Assert
            var expectedSerialized = JsonConvert.SerializeObject(sampleData);
            var resultSerialized   = JsonConvert.SerializeObject(result);

            Assert.Equal(expectedSerialized, resultSerialized);
        }