Beispiel #1
0
        public void RunApplication_with_with_purchase_command()
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var testPurchaseCommand = "order 1.25 1 1".Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var cut = new RunApplication();

            cut.Purchase(testPurchaseCommand, new VendingMachineService());

            output.ToString().Should().Be(Purchase_Item_Success_Message());
        }
Beispiel #2
0
        public void TestGetDailyActivity()
        {
            RunApplication    runApplication    = new RunApplication();
            AllData_db        allData_db        = new AllData_db();
            CommandParameters commandParameters = new CommandParameters();

            commandParameters.StartDate = "2018-01-13";
            commandParameters.EndDate   = "2018-01-10";

            List <Activity> dailyActivity = allData_db.GetDailyActivity(commandParameters);

            Assert.IsNotNull(dailyActivity);
        }
        public void FourReturnsNewPencil(string userInput)
        {
            var paper                 = new Paper();
            var pencil                = new Pencil();
            var pencilDrawer          = new Stack <IWritingUtensil>();
            var eraseHelper           = new EraseHelper(paper);
            var editHelper            = new EditHelper(paper, pencil);
            var writeAndSharpenHelper = new WriteAndSharpenHelper(paper, pencil);
            var sut = new RunApplication(paper, pencil, pencilDrawer, eraseHelper, editHelper, writeAndSharpenHelper);

            var result = sut.ValidateUserActionRequest(userInput);

            Assert.True(result == UserActionSelection.newPencil);
        }
Beispiel #4
0
        public void RunApplication_with_command_press_2()
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var testInputQuit = new StringReader("2");

            Console.SetIn(testInputQuit);

            var cut = new RunApplication();

            cut.Run();

            output.ToString().Should().Contain("Invalid command. Please try again.");
        }
Beispiel #5
0
        public void RunApplication_with_command_press_Inv_or_1(string command)
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var testInputInv = new StringReader(command);

            Console.SetIn(testInputInv);

            var cut = new RunApplication();

            cut.Run();

            output.ToString().Should().Contain(ExpectedHeaderText_With_Inv_Command());
        }
Beispiel #6
0
        public void RunApplication_with_command_press_x()
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var testInputQuit = new StringReader("x");

            Console.SetIn(testInputQuit);

            var cut = new RunApplication();

            cut.Run();

            output.ToString().Should().Be(ExpectedHeaderText_With_X_Command());
        }
 /// <summary>
 /// Adds a new order to the database
 /// </summary>
 internal void AddNewOrder()
 {
     /// using block to call idisposable properly
     using (var db = new DataBaseContext())
     {
         try
         {/// adds new order to the database then saves the changes tells the user that the order has been placed
             db.Add(NewOrder.CurOrder);
             db.SaveChanges();
             Console.WriteLine("Your Order has been placed, please pick up at your preferred store");
         }
         catch (Exception e)
         {
             Console.WriteLine("Something went wrong with placing the order", e);
         }
     }
     // runs the app again
     RunApplication.RunApp();
 }
        public void Worker()
        {
            try {
                var setupUpdateServer = new SetupUpdateServer(_configurationManager);
                setupUpdateServer.Subscribe(this);
                using (var webServer = setupUpdateServer.Execute()) {
                    setupUpdateServer.Dispose();

                    var connectToUpdateServer = new ConnectToUpdateServer(webServer);
                    connectToUpdateServer.Subscribe(this);
                    using (var connection = connectToUpdateServer.Execute()) {
                        connectToUpdateServer.Dispose();

                        var getUpdateInfo = new GetUpdateInfo(connection, _configurationManager);
                        getUpdateInfo.Subscribe(this);
                        var updateInfo = getUpdateInfo.Execute();
                        getUpdateInfo.Dispose();

                        var checkIfUpdateAvailable = new CheckIfUpdateAvailable(_targetConfig,
                                                                                updateInfo);
                        checkIfUpdateAvailable.Subscribe(this);
                        if (checkIfUpdateAvailable.Execute()) {
                            var createTemporaryFolder = new CreateTemporaryFolder();
                            createTemporaryFolder.Subscribe(this);
                            string temporaryFolder = createTemporaryFolder.Execute();
                            createTemporaryFolder.Dispose();

                            var downloadDistributive = new DownloadDistributive(webServer,
                                                                                updateInfo,
                                                                                temporaryFolder);
                            downloadDistributive.Subscribe(this);
                            string archivedDistributive = downloadDistributive.Execute();
                            downloadDistributive.Dispose();

                            var extractDistributive = new ExtractDistributive(archivedDistributive,
                                                                              temporaryFolder);
                            extractDistributive.Subscribe(this);
                            string distributive = extractDistributive.Execute();
                            extractDistributive.Dispose();

                            var killTargetProcess = new KillTargetProcess(_targetConfig);
                            killTargetProcess.Subscribe(this);
                            killTargetProcess.Execute();
                            killTargetProcess.Dispose();

                            var installNewVersion = new InstallNewVersion(distributive);
                            installNewVersion.Subscribe(this);
                            installNewVersion.Execute();
                            installNewVersion.Dispose();

                            //var restoreCredentials = new RestoreCredentials(_configurationManager);
                            //restoreCredentials.Subscribe(this);
                            //restoreCredentials.Execute();
                            //restoreCredentials.Dispose();

                            var deleteDatabase = new DeleteDatabase(_targetConfig,
                                                                    _configurationManager);
                            deleteDatabase.Subscribe(this);
                            deleteDatabase.Execute();
                            deleteDatabase.Dispose();

                            var runApplication = new RunApplication(_targetConfig);
                            runApplication.Subscribe(this);
                            runApplication.Execute();
                            runApplication.Dispose();

                            var deleteTemporaryFolder = new DeleteTemporaryFolder(temporaryFolder);
                            deleteTemporaryFolder.Execute();
                        }
                        else {
                            InvokeUpdateNotNeeded();
                        }
                        checkIfUpdateAvailable.Dispose();
                    }
                }
                InvokeUpdateComplete();
            }
            catch (Exception exception) {
                Log.Error(exception);
                InvokeUpdateFailed();
            }
        }
 static void Main()
 {
     #region Feilds and Properties
     /// Declare variables to use throughout main method
     AccessOrders    orderAcc  = new AccessOrders();
     AccessCustomer  accessCus = new AccessCustomer();
     InventoryAccess invAcc    = new InventoryAccess();
     #endregion
     // call the run application to start the program
     RunApplication.RunApp();
     #region Check whether to add customer to database or to lookup existing
     //chacks if the custumer exists if not add customer to database, if not add customer
     if (RunApplication.CusExists == false)
     {
         accessCus.AddCusToDataBase();
     }
     // if customer exists
     else if (RunApplication.CusExists == true)
     {
         do
         {
             /// set runs the look up customer from database until the
             /// customer is not null
             GetCustLookupInfo.GetCustID();
             Console.WriteLine("Looking for customer");
             if (GetCustLookupInfo.CustIDHolder != null)
             {
                 accessCus.LookUpCustFromDB();
             }
         }while (accessCus.ExistingCustomer == null);
     }
     #endregion
     #region new order
     /// checks if newOrder is set to true if so access the store inventory in order
     /// to use that inventory in a new order, run a new order method to place a new order
     if (RunApplication.NOrder)
     {
         Console.WriteLine("Accessing store Inventory");
         invAcc.GetStoreInventory();
         NewOrder.NewOrderSetup();
         invAcc.ChangeStoreInventory();
         orderAcc.AddNewOrder();
     }
     #endregion
     /// if the cust is not trying to add a new order access previous orders
     else
     {
         #region Access Previous Orders
         /// check if the user has requested to look up previous orders
         /// access previous orders and run the get orders store/ or get orders customer depending on
         /// which bools are true
         orderAcc.AccessPreviousOrders();
         if (RunApplication.Cust == true)
         {
             orderAcc.cust.GetOrders();
         }
         else if (RunApplication.StoreInfo == true)
         {
             orderAcc.store.GetOrders();
         }
     }
     #endregion
 }