コード例 #1
0
        public void CalculateTotalPriceCorrectly(string input, double expectedTotalPrice, string cultureInput, string testName)
        {
            //Arrange
            var consoleStringInput = ConsoleInputBuilder.Build(input);

            CultureSetter.SetCulture(cultureInput);

            var sut = new OrderPlacer(repository, resource); //sut = System under test.

            //Act
#pragma warning disable S1481                                              // Unused local variables should be removed
            using var consoleInput = new ConsoleInput(consoleStringInput); //Exceptions: Unused locally created resources in a using statement are not reported.
#pragma warning restore S1481                                              // Unused local variables should be removed
            using var consoleOutput = new ConsoleOutput();
            sut.PlaceOrder(OrderItemType.Food);
            sut.PlaceOrder(OrderItemType.Drink);
            sut.GetOrderedList();
            var totalPrice = sut.CalculateTotalPrice();

            //Assert
            totalPrice.Should().BeApproximately(expectedTotalPrice, 0.004); //Fluent assertions: https://app.pluralsight.com/library/courses/fluent-assertions-improving-unit-tests/table-of-contents
            using (ApprovalResults.ForScenario(testName))
            {
                Approvals.Verify(consoleOutput.GetOuput()); //Approval Tests: https://app.pluralsight.com/course-player?clipId=23302914-f8f9-4e93-94af-c9420fa8e031
            }
        }
コード例 #2
0
        public async Task ShouldCallGetDataPlaceInstruction()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await orderPlacer.PlaceOrder(orderWrapper);

            mockApiClient.Verify(x => x.GetData <JsonResponse <PlaceExecutionReport> >(It.IsAny <string>(), It.Is <Dictionary <string, object> >(y => VerifyDetails(y, orderWrapper))));
        }
コード例 #3
0
        public async Task ShouldCallGetDataWithMarketId()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await orderPlacer.PlaceOrder(orderWrapper);

            mockApiClient.Verify(x => x.GetData <JsonResponse <PlaceExecutionReport> >(It.IsAny <string>(), It.Is <Dictionary <string, object> >(y => y.ContainsKey("marketId") && y["marketId"].ToString() == "A")));
        }
コード例 #4
0
        public async Task ShouldCallGetDataWithPlaceOrderMethod()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await orderPlacer.PlaceOrder(orderWrapper);

            mockApiClient.Verify(x => x.GetData <JsonResponse <PlaceExecutionReport> >("SportsAPING/v1.0/placeOrders", It.IsAny <Dictionary <string, object> >()));
        }
コード例 #5
0
        public async Task ShouldThrowOrderNotPlaceableExceptionWhenOrderNotPlaceableResponse()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Error  = new TradePlacement.Models.Api.Exception(),
                Result = new PlaceExecutionReport()
                {
                    Status    = ExecutionReportStatus.FAILURE,
                    ErrorCode = ExecutionReportErrorCode.LOSS_LIMIT_EXCEEDED
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();
            var orderPlacer          = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await Assert.ThrowsExceptionAsync <OrderNotPlaceableException>(() => orderPlacer.PlaceOrder(orderWrapper));
        }
コード例 #6
0
        public async Task ShouldThrowInsufficientFundsExceptionWhenInsufficientFundsResponse()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                    Status    = ExecutionReportStatus.FAILURE,
                    ErrorCode = ExecutionReportErrorCode.INSUFFICIENT_FUNDS
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await Assert.ThrowsExceptionAsync <InsufficientFundsException>(() => orderPlacer.PlaceOrder(orderWrapper));
        }
コード例 #7
0
        public async Task ShouldThrowMarketSuspendedExceptionWhenMarketSuspendedResponse()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                    Status    = ExecutionReportStatus.FAILURE,
                    ErrorCode = ExecutionReportErrorCode.MARKET_SUSPENDED
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await Assert.ThrowsExceptionAsync <MarketSuspendedException>(() => orderPlacer.PlaceOrder(orderWrapper));
        }
コード例 #8
0
        public async Task ShouldThrowBetActionErrorWhenBetActionErrorResponse()
        {
            SetupApiClientResponse(new JsonResponse <PlaceExecutionReport>()
            {
                Result = new PlaceExecutionReport()
                {
                    Status    = ExecutionReportStatus.FAILURE,
                    ErrorCode = ExecutionReportErrorCode.BET_ACTION_ERROR
                }
            });

            var mockApiClientFactory = SetupApiClientFactory();

            var orderPlacer = new OrderPlacer(mockApiClientFactory.Object);

            var orderWrapper = GetOrderWrapper();
            await Assert.ThrowsExceptionAsync <OrderActionErrorException>(() => orderPlacer.PlaceOrder(orderWrapper));
        }