示例#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
            }
        }
        public void WriteOrderableItems(List <OrderItem> orderableItems, string cultureInput, string testName)
        {
            //Arrange
            CultureSetter.SetCulture(cultureInput);
            using var consoleOutput = new ConsoleOutput();

            //Act
            OrderPlacerHelper.WriteOrderableItems(orderableItems, resource);

            //Assert
            using (ApprovalResults.ForScenario(testName))
            {
                Approvals.Verify(consoleOutput.GetOuput());
            }
        }