Пример #1
0
        public static decimal ProcessOrder(IEnumerable <string> order, ValidationResults validationResults)
        {
            var menu          = MenuData.GetMenu();
            var totalCost     = 0.0M;
            var serviceCharge = ServiceCharge.None;

            foreach (var item in order)
            {
                if (!string.IsNullOrEmpty(item) && menu.Items.Any(x => x.Name == item))
                {
                    var menuItem = menu.Items
                                   .Where(x => x.Name == item)
                                   .FirstOrDefault();

                    totalCost += menuItem.Cost;

                    var itemServiceCharge = GetItemServiceCharge(menuItem);

                    if (itemServiceCharge > serviceCharge)
                    {
                        serviceCharge = itemServiceCharge;
                    }
                }
                else
                {
                    AddInvalidItemMessage(item, validationResults);
                }
            }

            return(!validationResults.AnyErrorOrInvalid()
                    ? GetTotalWithServiceCharge(totalCost, serviceCharge)
                    : 0.0M);
        }
        public void ProcessOrder_AllItems_Success()
        {
            // Arrange
            var order = new[] { "Cola", "Coffee", "Cheese Sandwich", "Steak Sandwich" };

            // Act
            var result = MenuService.ProcessOrder(order, validationResults);

            // Assert
            Assert.AreEqual(9.60M, result);
            Assert.IsFalse(validationResults.AnyErrorOrInvalid());
        }
Пример #3
0
        public ActionResult SearchName(string name)
        {
            var validationResults = new ValidationResultList();
            var success           = false;
            var view = default(string);

            if (ValidateName(name, validationResults))
            {
                var viewModel = GitHubService.SearchByName(name, validationResults);

                if (!ValidationResults.AnyErrorOrInvalid(validationResults))
                {
                    success = true;
                    view    = RazorViewToString.RenderRazorViewToString(this, "~/Views/Results/_results.cshtml", viewModel);
                }
            }

            return(Json(new
            {
                success,
                view,
                validationResults
            }));
        }