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 } }
public ManagerPair GetStrategyTradeManagerPair(Guid strategyId) { lock (_locker) { var sleepService = new SleepService(); var apiClientFactory = new ApiClientFactory(); var runnerService = new RunnerService(apiClientFactory); var orderPlacer = new OrderPlacer(apiClientFactory); var stakeCalculator = new ClosingStakeCalculator(); var openingStakeProviderFactory = new OpeningStakeProviderFactory(); var test = new List <string>() { "255f49e7-28e7-4f2b-acb9-34a2898866f4", "5331775e-fc1f-46c5-b665-f3d478b7d09f", "984950bb-210e-4e4b-b76c-cf668fe40a6a" }; if (test.Contains(strategyId.ToString())) { return(new ManagerPair(new TestOpeningOrderManager(), new TestClosingOrderManager())); } var orderPriceFinder = new OrderPriceFinder(openingStakeProviderFactory); return(new ManagerPair(new OpeningOrderManager(orderPlacer, runnerService, sleepService, orderPriceFinder), new ClosingOrderManager(sleepService, runnerService, orderPlacer, stakeCalculator))); } }
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)))); }
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"))); }
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> >())); }
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)); }
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)); }
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)); }
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)); }