private void PurchaseMethodBtn_Click(object sender, EventArgs e)
        {
            Notification status;
            Sms          purchaseSms;
            string       userPhoneNumber = this.userAccountTxtBox.Text;
            string       userSms         = this.smsTxtBox.Text;

            try

            {
                userPhoneNumber = systemParking.FormatPhoneNumber(userPhoneNumber);
                purchaseSms     = systemParking.FormatSmsForPurchase(userSms);
                status          = systemParking.ValidateSms(purchaseSms);
                status.AppendNotificationMessages(systemParking.ValidateExistingAccountForAccountTransaction(userPhoneNumber));

                if (!status.HasErrors())
                {
                    Account purchaseAccount = systemParking.GetAccountByPhoneNumber(userPhoneNumber);
                    status = systemParking.AddPurchase(new Purchase(purchaseSms, purchaseAccount));
                }
                this.outputErrorLbl.Text      = status.HasErrors()?$"Error: {status.Message()}":status.Message();
                this.outputErrorLbl.ForeColor = status.HasErrors()? Color.Red:Color.Green;
            }
            catch (InvalidOperationException ex)
            {
                this.outputErrorLbl.Text      = "Error: " + ex.Message;
                this.outputErrorLbl.ForeColor = Color.Red;
            }
        }
Exemple #2
0
        public void FormatSmsForPurchaseTest()
        {
            string smsMessage   = $"ABC 1234 120 14:00";
            Sms    sms          = system.FormatSmsForPurchase(smsMessage);
            Sms    smsToCompare = new Sms();

            smsToCompare.Plates       = "ABC1234";
            smsToCompare.Minutes      = "120";
            smsToCompare.StartingHour = DateTime.Parse("14:00");
            smsToCompare.EndingHour   = DateTime.Parse("16:00");
            Assert.AreEqual(sms, smsToCompare);
        }