Пример #1
0
        private void Validate()
        {
            var validation = new CustomerValidation().Validate(this);

            if (!validation.IsValid)
                Error = validation.Errors.Select(c => c.ErrorMessage).ToList();
        }
Пример #2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = new DialogResult();
                if (cbComfirmDelete.Checked == true)
                {
                    dialogResult = MessageBox.Show("Do you want to delete this record?", "Confirm Record Deletion", MessageBoxButtons.YesNo);
                }

                if (dialogResult == DialogResult.No)
                {
                    //Close dialogResult
                }
                else
                {
                    Customer customer = customerVM.GetDisplayCustomer();
                    CustomerValidation.DeleteCustomer(customer);
                    customerVM.Customers            = CustomerRepository.GetCustomer();
                    dataGridViewCustomer.DataSource = customerVM.Customers;
                }
            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        private CustomerEntity ValidateCustomerEntity(string custName)
        {
            CustomerValidation customerValidation = new CustomerValidation(new PharmacySystemDataAccess.Repository.RepositoryFactory.RepositoryFactory <CustomerEntity>(), ConnString);
            var customerName = custName.Split(' ');

            return(customerValidation.CheckDoesTheCustomerExist(customerName[0], customerName[1]).CustomerEntity);
        }
Пример #4
0
 public void ValidateFirstNameTestExpectedTrue()
 {
     Assert.IsTrue(CustomerValidation.ValidateFirstName("Name"));
     Assert.IsTrue(CustomerValidation.ValidateFirstName("Name Name"));
     Assert.IsTrue(CustomerValidation.ValidateFirstName("Name N"));
     Assert.IsTrue(CustomerValidation.ValidateFirstName("Namenamenamenmanamenamenamenma"));
     Assert.IsTrue(CustomerValidation.ValidateFirstName("Namenamenamenmanamenamenamen"));
 }
Пример #5
0
 public double GenerateBill(CustomerValidation ob, int custid, int quantity, double price)
 {
     if (ob.CheckValid(custid))
     {
         return(quantity * price);
     }
     return(0);
 }
Пример #6
0
 public void ValidateBrandNameTestExpectedTrue()
 {
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Toyota"));
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Ford"));
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Mercedes"));
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Ferrari"));
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Testname"));
     Assert.IsTrue(CustomerValidation.ValidateBrandName("Test"));
 }
        public async Task <Dictionary <string, string> > PostCustomerVerification(CustomerValidation customerValidation)
        {
            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string> ("TerminalId", TerminalId)
            };
            var billsResponse = await Interswitch.Send(Uris.customerVerificationUrl, Constants.POST, customerValidation, hashMap : parameters, token : Token, environment : Environment);

            return(billsResponse);
        }
        public (bool isValid, IEnumerable <ValidationResult> errors) Validate()
        {
            var validator = new CustomerValidation();
            var result    = validator.Validate(this);

            if (result.IsValid)
            {
                return(true, null);
            }
            return(false, result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName })));
        }
Пример #9
0
        private void LicensePlateTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox textBox = sender as TextBox;

            try {
                CustomerValidation.ValidateLicensePlateName(textBox.Text);
                ResetLabelContent(LicensePlateErrLabel);
            } catch (InvalidLicensePlateException ex) {
                ShowErrorMessage(LicensePlateErrLabel, ex.Message);
            }
        }
Пример #10
0
        public void GetCustomerById_Should_Fail_When_InputNegativeInteger()
        {
            //Arrange
            var customerId = -2;
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerId(customerId);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #11
0
        public void GetCustomerByEmail_Should_Success_When_InputRightFormatEmail()
        {
            //Arrange
            var customerEmail = "*****@*****.**";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerEmail(customerEmail);

            //Assert
            Assert.True(string.IsNullOrEmpty(result));
        }
Пример #12
0
        public void GetCustomerByEmail_Should_Fail_When_InputWorngFotmatEmail()
        {
            //Arrange
            var customerEmail = "asfgvzxc.com";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerEmail(customerEmail);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #13
0
        public void GetCustomerById_Should_Success_When_InputPositiveInteger()
        {
            //Arrange
            var customerId = 5;
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerId(customerId);

            //Assert
            Assert.True(string.IsNullOrEmpty(result));
        }
Пример #14
0
 public void ValidateBrandNameTestThrowInvalidBrandNameException()
 {
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName(""));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName(" "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("bran d "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("brand Name "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("Branda   "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("Brand Name D "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("Name3** "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("//Name$ "));
     Assert.ThrowsException <InvalidBrandNameException>(() => CustomerValidation.ValidateBrandName("Namesdgvsdfgsdfghenmsadasdasdasd"));
 }
Пример #15
0
 public void ValidateLastNameTestThrowInvalidLastNameException()
 {
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName(""));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName(" "));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("name"));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("name Name"));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("Name "));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("NameD "));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("Name3 "));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("Name$ "));
     Assert.ThrowsException <InvalidLastNameException>(() => CustomerValidation.ValidateLastName("Namenamenamenmanamenamenamenmaa"));
 }
Пример #16
0
        public static CustomerDetailViewModel GetInstance()
        {
            if (Instance == null)
            {
                CustomerRepository customerRepository = new CustomerRepository();
                MessagerLogger     messageLogger      = new MessagerLogger();
                CustomerValidation customerValidation = new CustomerValidation(messageLogger);
                Instance = new CustomerDetailViewModel(customerRepository, customerValidation, messageLogger);
            }

            return(Instance);
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                Customer customer = customerVM.GetDisplayedCustomer();
                int      rowsAffected;
                bool     success;

                if (!isNew)
                {
                    rowsAffected = CustomerValidation.UpdateCustomer(customer, out success);
                }
                else
                {
                    rowsAffected = CustomerValidation.NewCustomer(customer, out success);
                }

                if (rowsAffected > 0)
                {
                    customerVM.Customers           = CustomerInfoRepository.GetAllCustomers();
                    listBoxCustomers.DataSource    = customerVM.Customers;
                    listBoxCustomers.DisplayMember = "CustomerCode";
                }

                // Validation for ErrorProviders
                if (!success)
                {
                    ErrorList errors = CustomerValidation.Errors;

                    errorProvider.SetError(textBoxCompanyCode, errors.CompanyCodeErrorMessage);
                    errorProvider.SetError(textBoxName, errors.CompanyNameErrorMessage);
                    errorProvider.SetError(textBoxFirstAddress, errors.FirstAddressErrorMessage);
                    errorProvider.SetError(textBoxProvince, errors.ProvinceErrorMessage);
                    errorProvider.SetError(textBoxPostalCode, errors.PostalCodeErrorMessage);
                    errorProvider.SetError(textBoxYTDSales, errors.YTDSalesErrorMessage);
                }
                else
                {
                    isNew = false;
                    errorProvider.SetError(textBoxCompanyCode, string.Empty);
                    errorProvider.SetError(textBoxName, string.Empty);
                    errorProvider.SetError(textBoxFirstAddress, string.Empty);
                    errorProvider.SetError(textBoxProvince, string.Empty);
                    errorProvider.SetError(textBoxPostalCode, string.Empty);
                    errorProvider.SetError(textBoxYTDSales, string.Empty);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #18
0
        public void GetCustomerByIdAndEmail_Should_Success_When_InputPositiveInteger_RightFormatEmail()
        {
            //Arrange
            var customerId    = 10;
            var customerEmail = "*****@*****.**";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerIdAndEmail(customerId, customerEmail);

            //Assert
            Assert.True(string.IsNullOrEmpty(result));
        }
Пример #19
0
        public void GetCustomerByIdAndEmail_Should_Fail_When_InputNegativeInteger_WrongFormatEmail()
        {
            //Arrange
            var customerId    = -52;
            var customerEmail = "musicaly central";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerIdAndEmail(customerId, customerEmail);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #20
0
        public void GetCustomerByIdAndEmail_Should_Fail_When_InputNegativeInteger_EmptyEmail()
        {
            //Arrange
            var customerId    = -64;
            var customerEmail = string.Empty;
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerIdAndEmail(customerId, customerEmail);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #21
0
        public void GetCustomerByIdAndEmail_Should_Fail_When_InputZeroNumber_WorngFotmatEmail()
        {
            //Arrange
            var customerId    = 0;
            var customerEmail = "b_basketb.com";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerIdAndEmail(customerId, customerEmail);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #22
0
        public void GetCustomerByIdAndEmail_Should_Fail_When_InputPositiveInteger_WorngFotmatEmail()
        {
            //Arrange
            var customerId    = 6;
            var customerEmail = "rosesyJes.com";
            //Act
            var validationService = new CustomerValidation();
            var result            = validationService.ValidationCustomerIdAndEmail(customerId, customerEmail);

            //Assert
            Assert.False(string.IsNullOrEmpty(result));
        }
Пример #23
0
        public void Customer_with_empty_market_gets_default_value()
        {
            CustomerValidation customerValidation = new CustomerValidation();

            var newCustomer = new Customer() {
                // Salesperson didn't enter the CustomerMarket
                CustomerMarket = String.Empty,
            };

            bool isValidCustomer = customerValidation.ValidateCustomer(newCustomer);

            newCustomer.CustomerMarket.Should().Be("Default");
        }
Пример #24
0
        public void Customer_with_empty_market_gets_default_value()
        {
            CustomerValidation customerValidation = new CustomerValidation();

            var newCustomer = new Customer()
            {
                // Salesperson didn't enter the CustomerMarket
                CustomerMarket = String.Empty,
            };

            bool isValidCustomer = customerValidation.ValidateCustomer(newCustomer);

            newCustomer.CustomerMarket.Should().Be("Default");
        }
Пример #25
0
 public void ValidateCarTypeTestExpectedTrue()
 {
     Assert.IsTrue(CustomerValidation.ValidateCarType("Fiesta S5"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Mondeo"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Falcon"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Mustang"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("EcoSport"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Escape"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Everest"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Escape 5"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Everest 44"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Esc 5"));
     Assert.IsTrue(CustomerValidation.ValidateCarType("Ev 14"));
 }
Пример #26
0
 public void ValidateLicensePlateNameTestThrowInvalidLicensePlateException()
 {
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName(""));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName(" "));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SDD1111"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("1111AAA"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SDAD111"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SSA1132"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("11111"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SSSSS"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SD11AS11"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SSA1132"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("1"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("SSSSSDFS"));
     Assert.ThrowsException <InvalidLicensePlateException>(() => CustomerValidation.ValidateLicensePlateName("!+%+"));
 }
Пример #27
0
 public void ValidateCarTypeTestInvalidCarTypeException()
 {
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType(""));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType(" "));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("SDD1111%"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("111A--AA"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("SDA!!D111"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType(" SS                         A32 "));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType(" Ty..pe 2 "));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("Bog 4*8 48"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("_wse_()we_we"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("_wse_we_we.9"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("_wse7we._we"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("we?"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("|w|"));
     Assert.ThrowsException <InvalidCarTypeException>(() => CustomerValidation.ValidateCarType("asd@@as"));
 }
Пример #28
0
 public void ValidateFirstNameTestThrowInvalidFirstNameException()
 {
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName(""));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName(" "));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("name"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("name Name"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name name"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("NaMe"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("NaMe Na"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("NamME Name"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name2 Name"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name2 Name F"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name NameD"));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name "));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Name@ "));
     Assert.ThrowsException <InvalidFirstNameException>(() => CustomerValidation.ValidateFirstName("Namenamenamenmanamenamenamenmaa"));
 }
Пример #29
0
 public void ValidateLicensePlateNameTestExpectedTrue()
 {
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("WWW111"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("KLK231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("QWE231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("FRD231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SDD123"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SDW123"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SDC431"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("WUW111"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("ULK231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("QWU231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("FRF231"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SSD123"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SWW123"));
     Assert.IsTrue(CustomerValidation.ValidateLicensePlateName("SDE431"));
 }
        public void Customer_Validate_isNotValid()
        {
            // Arrange
            var expectedIsValid = false;
            var customer        = new CustomerViewModel()
            {
                CustomerID = Guid.NewGuid(),
                Name       = "Tiago",
                Email      = "tiago_tanphotmail.com",
            };

            // Act
            var customerValidation = new CustomerValidation();
            var validationResult   = customerValidation.Validate(customer);

            // Assert
            Assert.Equal(expectedIsValid, validationResult.IsValid);
        }
Пример #31
0
        public void WrongName()
        {
            var customer = new CustomerDetails
            {
                Name    = "pe",
                Address = "Something",
                City    = "Zurich",
                Country = new Country
                {
                    Name = "Swiss"
                },
                Zip   = "3434",
                Phone = "079 620 00 35",
                Email = "*****@*****.**"
            };

            Assert.IsFalse(CustomerValidation.ValidateCustomer(customer));
        }
Пример #32
0
        public void Customer_with_empty_market_gets_default_value_1()
        {
            var mockCrmDbContext = new Mock<ICrmDbContext>();
            var customerValidation = new CustomerValidation();

            string actualCustomerMarket = string.Empty;
            mockCrmDbContext.Setup(x => x.Customers.Add(It.IsAny<Customer>()))
                // Spy on CustomerMarket submitted to DB
                .Callback((Customer c) => actualCustomerMarket = c.CustomerMarket);

            var newCustomer = new Customer() {
                // Salesperson didn't enter the CustomerMarket
                CustomerMarket = String.Empty,
            };

            CustomerManagement crm = new CustomerManagement(mockCrmDbContext.Object, customerValidation);
            crm.AddNewCustomer(newCustomer);

            // Verify CustomerMarket = "Default"
            actualCustomerMarket.Should().Be("Default");
        }