public async Task getTrolleyTotalSample4()
        {
            decimal      expected       = 6.296458940268143M;
            TrolleyModel trolleyModel   = JsonConvert.DeserializeObject <TrolleyModel>(File.ReadAllText(@"Mock\\Trolley\\TrolleyRequest-Sample4.json"));
            var          trolleyService = new TrolleyService();
            var          result         = await trolleyService.GetTrollyTotal(trolleyModel, _token);

            Assert.Equal(expected, result);
        }
예제 #2
0
        public async Task Calculate_GivenATrolley_ReturnTrolleyTotal()
        {
            // arrange
            decimal            expected = 20;
            Mock <ITrolleyAPI> mock     = new Mock <ITrolleyAPI>();

            mock.Setup(a => a.Calculate(It.IsAny <string>(), It.IsAny <Trolley>())).ReturnsAsync(expected);
            var sut = new TrolleyService(mock.Object);

            // act
            var actual = await sut.CalculateTotal("test", new Trolley());

            // assert
            Assert.Equal(expected, actual, 0);
        }
        public async Task GetLowestTotal()
        {
            Trolley trolley = new Trolley
            {
                Products = new List <ProductInfo>
                {
                    new ProductInfo
                    {
                        Name  = "test1",
                        Price = 10
                    }
                },
                Specials = new List <SpecialItem>
                {
                    new SpecialItem
                    {
                        Quantities = new List <ProductItem>
                        {
                            new ProductItem
                            {
                                Name     = "test1",
                                Quantity = 2
                            }
                        },
                        Total = 2
                    }
                },
                Quantities = new List <ProductItem>
                {
                    new ProductItem
                    {
                        Name     = "test1",
                        Quantity = 3
                    }
                }
            };

            Mock <ILogger <TrolleyService> > loggerMock = new Mock <ILogger <TrolleyService> >();
            TrolleyService service = new TrolleyService(GetAppSettings(), loggerMock.Object);

            double total = await service.GetLowestTotal(trolley);

            Assert.Equal(12.0, total);
        }