Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //load the Products
            var products = new ProductLoader().LoadProducts();

            //take the arguments and put them through the validator to make sure they are all valid items
            IInputValidator validator = new InputValidator(products);

            if (!validator.ValidateInput(args))
            {
                //TODO: could return which of the inputs were invalid
                Console.WriteLine("Invalid input received.");
                return;
            }
            //pass the newly validated products into the checkout to determine the subtotal
            var checkout = new Checkout(validator.GetValidatedProducts());

            Console.WriteLine($"Subtotal: {string.Format("{0:C}", checkout.DetermineSubtotal())}");
            //load the special offers
            var specialOffers = new SpecialOfferLoader(DateTime.Today.AddDays(3)).LoadCurrentOffers();

            checkout.ProcessSpecialOffers(specialOffers);
            if (checkout.GetSpecialOffers().Any())
            {
                foreach (Product offer in checkout.GetSpecialOffers())
                {
                    Console.WriteLine($"{ offer.ProductName}: {string.Format("{0:C}", offer.Price)}");
                }
            }
            else
            {
                Console.WriteLine("(No offers available)");
            }
            Console.WriteLine($"Total: {string.Format("{0:C}", checkout.DetermineTotal())}");
        }
Ejemplo n.º 2
0
        public void CheckNumberOfProductsLoaded()
        {
            var loader   = new ProductLoader();
            var products = loader.LoadProducts();

            Assert.AreEqual <int>(4, products.Count);
        }
Ejemplo n.º 3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            var seedData = ProductLoader.GetProductsFromFile();

            foreach (var product in seedData)
            {
                modelBuilder.Entity <Product>().HasData(new Product
                {
                    ProductId       = product.ProductId,
                    ProductName     = product.ProductName,
                    Energy          = product.Energy,
                    Fat             = product.Fat,
                    Carbohydrates   = product.Carbohydrates,
                    Protein         = product.Protein,
                    Salt            = product.Salt,
                    Fiber           = product.Fiber,
                    Sugar           = product.Sugar,
                    Quantity        = product.Quantity,
                    PortionQuantity = product.PortionQuantity,
                    PortionUnit     = product.PortionUnit,
                    IsFavorite      = product.IsFavorite
                });
            }
        }
Ejemplo n.º 4
0
        public bool LoadFromFile(string taskDataFile)
        {
            if (!LoadXmlFile(taskDataFile))
            {
                return(false);
            }

            if (!VerifyIsoVersion())
            {
                return(false);
            }

            LinkedIds    = LinkListLoader.Load(this);
            Units        = UnitLoader.Load(this);
            Customers    = CustomerLoader.Load(this);
            Farms        = FarmLoader.Load(this);
            Crops        = CropLoader.Load(this);
            Fields       = FieldLoader.Load(this);
            Products     = ProductLoader.Load(this);
            ProductMixes = ProductMixLoader.Load(this);
            Workers      = WorkerLoader.Load(this);
            Comments     = CommentLoader.Load(this);
            Tasks        = TaskLoader.Load(this);

            RasterPrescriptions = PrescriptionLoader.Load(this);
            Machines            = DeviceLoader.Load(this);

            return(true);
        }
Ejemplo n.º 5
0
        public void ProductLoaderReturnsAllProducts(Product product)
        {
            var loader   = new ProductLoader();
            var products = loader.GetProducts();

            Assert.Contains(product, products.ToList());
        }
Ejemplo n.º 6
0
 public ProductList GetProducts()
 {
     if (productList == null)
     {
         productList = ProductLoader.LoadProducts(GetProductTypes(), GetBrands());
     }
     return(productList);
 }
Ejemplo n.º 7
0
        public void VendingMachine_ListFill_Test()
        {
            //Arrange
            List <VendingItem> fromFile = new List <VendingItem>();

            fromFile = ProductLoader.Loader();

            List <VendingItem> listItems = new List <VendingItem>();
            VendingItem        item1     = new VendingItem("A1", "Potato Crisps", (decimal)3.05, "Chip");
            VendingItem        item2     = new VendingItem("A2", "Stackers", (decimal)1.45, "Chip");
            VendingItem        item3     = new VendingItem("A3", "Grain Waves", (decimal)2.75, "Chip");
            VendingItem        item4     = new VendingItem("A4", "Cloud Popcorn", (decimal)3.65, "Chip");
            VendingItem        item5     = new VendingItem("B1", "Moonpie", (decimal)1.80, "Candy");
            VendingItem        item6     = new VendingItem("B2", "Cowtales", (decimal)1.50, "Candy");
            VendingItem        item7     = new VendingItem("B3", "Wonka Bar", (decimal)1.50, "Candy");
            VendingItem        item8     = new VendingItem("B4", "Crunchie", (decimal)1.75, "Candy");
            VendingItem        item9     = new VendingItem("C1", "Cola", (decimal)1.25, "Drink");
            VendingItem        item10    = new VendingItem("C2", "Dr. Salt", (decimal)1.50, "Drink");
            VendingItem        item11    = new VendingItem("C3", "Mountain Melter", (decimal)1.50, "Drink");
            VendingItem        item12    = new VendingItem("C4", "Heavy", (decimal)1.50, "Drink");
            VendingItem        item13    = new VendingItem("D1", "U-Chews", (decimal)0.85, "Gum");
            VendingItem        item14    = new VendingItem("D2", "Little League Chew", (decimal)0.95, "Gum");
            VendingItem        item15    = new VendingItem("D3", "Chiclets", (decimal)0.75, "Gum");
            VendingItem        item16    = new VendingItem("D4", "Triplemint", (decimal)0.75, "Gum");

            listItems.Add(item1);
            listItems.Add(item2);
            listItems.Add(item3);
            listItems.Add(item4);
            listItems.Add(item5);
            listItems.Add(item6);
            listItems.Add(item7);
            listItems.Add(item8);
            listItems.Add(item9);
            listItems.Add(item10);
            listItems.Add(item11);
            listItems.Add(item12);
            listItems.Add(item13);
            listItems.Add(item14);
            listItems.Add(item15);
            listItems.Add(item16);
            //Act

            //Assert
            CollectionAssert.AreEqual(listItems, fromFile, "Lists are not the same.");
        }
Ejemplo n.º 8
0
        public async void ProductLoaderLoadHtmlPageAsString()
        {
            // Arrange
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            ProductLoader loader     = new ProductLoader();
            string        url        = "https://www.prodj.com.ua/studio-monitors/brand:monkey-banana/";
            string        startsWith = "<!DOCTYPE html>";
            string        endsWith   = "</html>";

            // Act
            string result = await loader.LoadAsync(url);


            // Assert
            Assert.NotNull(result);

            Assert.IsType <string>(result);
            Assert.EndsWith(endsWith, result);
            Assert.StartsWith(startsWith, result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Builds a set of tasks to perform the load.
        /// </summary>
        /// <returns>A sequence of tasks to execute.</returns>
        private static IEnumerable <ITask> BuildTasks()
        {
            List <ITask> tasks = new List <ITask>();

            var targetFactory = Program.connectionFactories["target"];

            if (Program.Options.FullLoad)
            {
                // Clean out the database.
                var cleanTask = new SequentialTask(
                    "Clean Target Database",
                    new ExecuteSqlTask("Truncate Facts", targetFactory, SqlQueries.TruncateFactsSql),
                    new ExecuteSqlTask("Delete dimension data", targetFactory, SqlQueries.DeleteDimensionData));

                tasks.Add(cleanTask);
            }

            var dimensionTasks = new List <ITask>();

            if (Program.Options.FullLoad)
            {
                var currencyLoader = new CurrencyLoader(targetFactory);
                dimensionTasks.Add(currencyLoader.Build());

                var dateLoader = new DateLoader(targetFactory);
                dimensionTasks.Add(dateLoader.Build());

                var productLoader = new ProductLoader(targetFactory);
                Program.Disposables.Add(productLoader);
                dimensionTasks.Add(productLoader.Build());
            }

            tasks.Add(new ParallelTask("Load Dimensions", dimensionTasks));

            return(tasks);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var productLoader  = new ProductLoader();
            var inputValidator = new InputValidator(productLoader);

            Console.WriteLine("Please enter the products to calculate as CSV (i.e. 'Milk,Bread,Butter':");
            var input = Console.ReadLine().Split(',');

            if (!inputValidator.ValidateInput(input))
            {
                //TODO: could return which of the inputs were invalid
                Console.WriteLine("Invalid input received.");
                Console.ReadKey();
                return;
            }
            //load the specialOffers and pass to the checkout to determine savings
            var specialOfferLoader = new SpecialOfferLoader();
            var checkout           = new Checkout(inputValidator.GetValidatedProducts());

            checkout.ProcessSpecialOffers(specialOfferLoader.LoadCurrentOffers());

            Console.Write($"These products come to £{checkout.DetermineTotal().ToString("0.00")}");
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            var loader = new ProductLoader();

            try
            {
                Console.WindowWidth = 150;
                bool terminate = false;
                while (terminate == false)
                {
                    Console.Clear();
                    Console.WriteLine("Welcome to VirtusFit application.");
                    Console.WriteLine("----------------------------------");
                    Console.WriteLine("Available options:");
                    Console.WriteLine("1. Display full list of products.");
                    Console.WriteLine("2. Search for products.");
                    Console.WriteLine("3. Add new product.");
                    Console.WriteLine("4. Edit product.");
                    Console.WriteLine("5. Prepare diet plan.");
                    Console.WriteLine("6. Close application.");
                    Console.WriteLine("----------------------------------");
                    Console.WriteLine("Please choose your action:");
                    string userChoice = (Console.ReadLine());
                    if (userChoice != "1" && userChoice != "2" && userChoice != "3" && userChoice != "4" && userChoice != "5" && userChoice != "6")
                    {
                        Console.WriteLine("Incorrect input");
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                    }
                    else
                    {
                        int _userChoice = int.Parse(userChoice);
                        switch (_userChoice)
                        {
                        case 1:
                            DisplayProductList.DisplayList(ListOfProducts);
                            break;

                        case 2:
                            SearchProductConsoleInterface newSearch = new SearchProductConsoleInterface();
                            newSearch.SearchProductInterface(ListOfProducts);
                            break;

                        case 3:
                            AddProductFromConsole();
                            break;

                        case 4:
                            DisplayProductList.DisplayList(ListOfProducts);
                            EditDataFromConsoleInterface testInterface = new EditDataFromConsoleInterface();
                            testInterface.EditProductInterface();
                            break;

                        case 5:
                            Console.WriteLine("There will be a super cool diet planner");
                            Console.WriteLine();
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                            break;

                        case 6:
                            terminate = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error occured: {e.Message} \nPress any key.");
                Console.ReadKey();
            }
        }
Ejemplo n.º 12
0
 public ProductLoaderWarmUpProvider(ProductLoader productLoader, ILogger logger, IOptions <LoaderProperties> props)
 {
     _productLoader = productLoader;
     _props         = props.Value;
     _logger        = logger;
 }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var client = _httpClientFactory.CreateClient();
                    var action = CreateAction(user.UserName, UserAccountActionType.AccountCreated);
                    await client.PostAsync("https://localhost:5001/VirtusFit/user",
                                           new StringContent(JsonSerializer.Serialize(action), Encoding.UTF8, "application/json"));

                    var accountStatus = CreateAction(user.UserName, UserAccountActionType.UserUnlocked);
                    await client.PostAsync("https://localhost:5001/VirtusFit/user",
                                           new StringContent(JsonSerializer.Serialize(accountStatus), Encoding.UTF8, "application/json"));

                    var passwordStatus = CreateAction(user.UserName, UserAccountActionType.PasswordChanged);
                    await client.PostAsync("https://localhost:5001/VirtusFit/user",
                                           new StringContent(JsonSerializer.Serialize(passwordStatus), Encoding.UTF8, "application/json"));

                    var seedData = ProductLoader.GetProductsFromFile();
                    foreach (var product in seedData)
                    {
                        _productRepository.InsertProduct(new Product
                        {
                            ProductNo       = product.ProductId,
                            ProductName     = product.ProductName,
                            Energy          = product.Energy,
                            Fat             = product.Fat,
                            Carbohydrates   = product.Carbohydrates,
                            Protein         = product.Protein,
                            Salt            = product.Salt,
                            Fiber           = product.Fiber,
                            Sugar           = product.Sugar,
                            Quantity        = product.Quantity,
                            PortionQuantity = product.PortionQuantity,
                            PortionUnit     = product.PortionUnit,
                            IsFavorite      = product.IsFavorite,
                            UserId          = user.Id
                        });
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }