Ejemplo n.º 1
0
        public CustomerControl()
        {
            InitializeComponent();
            //this.gvCustomers.ContextMenuStrip = this.GridViewMenu;
            Settings setting = new Settings();

            try
            {
                CustomerParser newParser = new CustomerParser();

                dataModel = new CustomerModel(
                                    this.gvCustomers,
                                    setting.DB_HOST,
                                    setting.DB_PORT,
                                    setting.DB_NAME,
                                    setting.DB_USER,
                                    setting.DB_PASS,
                                    "Sales.Customers",
                                    newParser);
                //dataModel = new CustomerModel(this.gvCustomers, ".\\SQL2008", setting.DB_PORT, setting.DB_NAME, setting.DB_USER, setting.DB_PASS, "HR.Customers", newParser);

                newParser.DataModel = dataModel;
                this.cbCountry.Items.Clear();
                this.cbCountry.Items.AddRange(CustomerModel.GetCountries().ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this._initModel();
        }
Ejemplo n.º 2
0
        public CustomerControl(string host, int port, string dbname, string username,
            string password, string table_name, CustomerParser parser)
        {
            this.InitializeComponent();

            CustomerParser newParser = new CustomerParser();
            try
            {
                dataModel = new CustomerModel(
                                    this.gvCustomers,
                                    host,
                                    port,
                                    dbname,
                                    username,
                                    password,
                                    "Sales.Customers",
                                    newParser);
                newParser.DataModel = dataModel;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this._initModel();
        }
Ejemplo n.º 3
0
        public void ParsingCsvWithInvalidNumberParameters()
        {
            const string filePath = FILE_PATH_BASE + "customerIncorrectNumberParameters.csv";

            IList <Customer> actualCustomers = new CustomerParser(filePath).Parse();

            Assert.Equal(1, actualCustomers.Count);

            var expectedCustomers = new[]
            {
                new Customer {
                    Id = 1001, FirstName = "Valid", LastName = "Line", Status = CustomerStatus.Premium
                }
            };

            for (var index = 0; index < actualCustomers.Count; index++)
            {
                var actualCustomer   = actualCustomers[index];
                var expectedCustomer = expectedCustomers[index];
                Assert.Equal(expectedCustomer.Id, actualCustomer.Id);
                Assert.Equal(expectedCustomer.FirstName, actualCustomer.FirstName);
                Assert.Equal(expectedCustomer.LastName, actualCustomer.LastName);
                Assert.Equal(expectedCustomer.Status, actualCustomer.Status);
            }
        }
Ejemplo n.º 4
0
        public void can_ignore_customer()
        {
            var lines     = new[] { "CustomerA|-|-|-" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Empty(customers);
        }
Ejemplo n.º 5
0
        public void can_parse_all_preferences()
        {
            var lines     = new[] { "CustomerA|1,3,15|wednesday|true" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.IsType <EveryDayPreference>(customer.MasterPreference);
            foreach (var preference in customer.DaySpecificPreferences)
            {
                if (preference is DayOfTheWeekPreference)
                {
                    Assert.True(preference.IsToSendOn(new DateTimeOffset(2021, 4, 14, 0, 0, 0, TimeSpan.Zero)));
                    Assert.False(preference.IsToSendOn(new DateTimeOffset(2021, 4, 15, 0, 0, 0, TimeSpan.Zero)));
                }
                else
                {
                    Assert.True(preference.IsToSendOn(new DateTimeOffset(2021, 4, 1, 0, 0, 0, TimeSpan.Zero)));
                    Assert.True(preference.IsToSendOn(new DateTimeOffset(2021, 4, 3, 0, 0, 0, TimeSpan.Zero)));
                    Assert.True(preference.IsToSendOn(new DateTimeOffset(2021, 4, 15, 0, 0, 0, TimeSpan.Zero)));
                    Assert.False(preference.IsToSendOn(new DateTimeOffset(2021, 4, 18, 0, 0, 0, TimeSpan.Zero)));
                }
            }
        }
Ejemplo n.º 6
0
        public void ParsingEmptyFileReturnsEmptyList()
        {
            const string filePath = FILE_PATH_BASE + "empty.csv";

            var actualCustomers = new CustomerParser(filePath).Parse();

            Assert.Equal(0, actualCustomers.Count);
        }
Ejemplo n.º 7
0
        public void can_parse_customer_name()
        {
            var lines     = new[] { "CustomerA|1,15,23|-|-" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
        }
Ejemplo n.º 8
0
        public SalesAnalises()
        {
            saleParser     = new SaleParser();
            vendorParser   = new VendorParser();
            customerParser = new CustomerParser();
            salesContext   = new SalesContext();

            vendorRepository   = new VendorRepository(salesContext);
            customerRepository = new CustomerRepository(salesContext);
            saleRepository     = new SaleRepository(salesContext);
        }
Ejemplo n.º 9
0
        public void can_parse_master_preference(string option, Type preferenceType)
        {
            var lines     = new[] { $"CustomerA|-|-|{option}" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.IsType(preferenceType, customer.MasterPreference);
        }
Ejemplo n.º 10
0
        public void can_ignore_master_preference(string wrongMasterPreference)
        {
            var lines     = new[] { $"CustomerA|1,3,27|wednesday,friday|{wrongMasterPreference}" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.Null(customer.MasterPreference);
        }
Ejemplo n.º 11
0
        public void can_ignore_day_of_the_month_preference(string wrongDay)
        {
            var lines     = new[] { $"CustomerA|{wrongDay}|wednesday|false" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.DoesNotContain(
                customer.DaySpecificPreferences,
                preference => preference.GetType() == typeof(DayOfTheMonthPreference));
        }
Ejemplo n.º 12
0
        public AppCalculator()
        {
            FileLogger log        = new FileLogger(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
            var        connection = new SQLiteConnection(Path.Combine(
                                                             Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "usersdata.db"));
            IDataRepository sqlExpress   = new HistoryRepository();
            Item            data         = new Item();
            IContext        context      = new Context();
            IAudit          audit        = new Audit_Input();
            ICustomerParser exp_evaluate = new CustomerParser(context);
            var             ide          = new CalcFacade(data, sqlExpress, audit, exp_evaluate, context, connection, log);

            IDE = ide;
        }
Ejemplo n.º 13
0
        public void CanParseSimpleFile()
        {
            const string filePath = FILE_PATH_BASE + "customers.csv";

            var actualCustomers = new CustomerParser(filePath).Parse();

            Assert.Equal(8, actualCustomers.Count);

            var expectedCustomers = new[]
            {
                new Customer {
                    Id = 1001, FirstName = "Mary", LastName = "Smith", Status = CustomerStatus.Premium
                },
                new Customer {
                    Id = 1002, FirstName = "John", LastName = "Jones", Status = CustomerStatus.Regular
                },
                new Customer {
                    Id = 1003, FirstName = "William", LastName = "Williams", Status = CustomerStatus.Premium
                },
                new Customer {
                    Id = 1004, FirstName = "Anna", LastName = "Taylor", Status = CustomerStatus.Regular
                },
                new Customer {
                    Id = 1005, FirstName = "Dave", LastName = "Davies", Status = CustomerStatus.Regular
                },
                new Customer {
                    Id = 1006, FirstName = "Susan", LastName = "Evans", Status = CustomerStatus.Regular
                },
                new Customer {
                    Id = 1007, FirstName = "Thomas", LastName = "Jameson", Status = CustomerStatus.Regular
                },
                new Customer {
                    Id = 1008, FirstName = "Arthur", LastName = "Richards-Chamberlain", Status = CustomerStatus.Premium
                }
            };

            for (var index = 0; index < actualCustomers.Count; index++)
            {
                var actualCustomer   = actualCustomers[index];
                var expectedCustomer = expectedCustomers[index];
                Assert.Equal(expectedCustomer.Id, actualCustomer.Id);
                Assert.Equal(expectedCustomer.FirstName, actualCustomer.FirstName);
                Assert.Equal(expectedCustomer.LastName, actualCustomer.LastName);
                Assert.Equal(expectedCustomer.Status, actualCustomer.Status);
            }
        }
Ejemplo n.º 14
0
        public void can_parse_days_of_the_week_preference()
        {
            var lines     = new[] { "CustomerA|-|wednesday,friday|-" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.Single(customer.DaySpecificPreferences);
            var dayOfTheWeekPreference = customer.DaySpecificPreferences[0];

            Assert.IsType <DayOfTheWeekPreference>(dayOfTheWeekPreference);
            Assert.True(dayOfTheWeekPreference.IsToSendOn(new DateTimeOffset(2021, 4, 28, 0, 0, 0, TimeSpan.Zero)));
            Assert.True(dayOfTheWeekPreference.IsToSendOn(new DateTimeOffset(2021, 4, 30, 0, 0, 0, TimeSpan.Zero)));
            Assert.False(dayOfTheWeekPreference.IsToSendOn(new DateTimeOffset(2021, 4, 29, 0, 0, 0, TimeSpan.Zero)));
        }
Ejemplo n.º 15
0
        public void can_parse_days_of_the_month_preference()
        {
            var lines     = new[] { "CustomerA|1,15,23|-|-" };
            var customers = new CustomerParser(lines).Customers;

            Assert.Single(customers);
            var customer = customers[0];

            Assert.Equal("customera", customer.Name);
            Assert.Single(customer.DaySpecificPreferences);
            var dayOfTheMonthPreference = customer.DaySpecificPreferences[0];

            Assert.IsType <DayOfTheMonthPreference>(dayOfTheMonthPreference);
            Assert.True(dayOfTheMonthPreference.IsToSendOn(new DateTimeOffset(2021, 4, 1, 0, 0, 0, TimeSpan.Zero)));
            Assert.True(dayOfTheMonthPreference.IsToSendOn(new DateTimeOffset(2021, 4, 15, 0, 0, 0, TimeSpan.Zero)));
            Assert.True(dayOfTheMonthPreference.IsToSendOn(new DateTimeOffset(2021, 4, 23, 0, 0, 0, TimeSpan.Zero)));
            Assert.False(dayOfTheMonthPreference.IsToSendOn(new DateTimeOffset(2021, 4, 5, 0, 0, 0, TimeSpan.Zero)));
        }
Ejemplo n.º 16
0
        static int Main(string[] args)
        {
            Console.WriteLine("*** Hello, thank you for using the most amazing contact preferences application ***");

            var argumentParser = GetArgumentParser(args);

            if (argumentParser == null)
            {
                return(1);
            }

            IEnumerable outputToPrint;

            try
            {
                var lines     = File.ReadAllLines(argumentParser.FilePath);
                var customers = new CustomerParser(lines).Customers;

                outputToPrint =
                    new OutputBuilder(
                        DateTimeOffset.UtcNow,
                        customers,
                        90)
                    .Build();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Oops something went wrong:");
                Console.WriteLine($"=> {exception.Message}");
                return(1);
            }

            Console.WriteLine("Here is the list of customers to send preferences, grouped by day:");
            foreach (var output in outputToPrint)
            {
                Console.WriteLine($"=> {output}");
            }

            return(0);
        }
Ejemplo n.º 17
0
 protected void loadData()
 {
     string currentFilter ;
     if (IsPostBack == false)
     {
         Session["cust_filter"] = "";
         currentFilter = "";
     }
     else
         currentFilter = (string)Session["cust_filter"];
     //this.scriptLb.Text = currentFilter;
     CustomerParser newParser = new CustomerParser();
     this.dataModel = new CustomerModel(this.gvCustomers, @".\SQL2008",
          1433, "TSQLFundamentals2008","sa", "123456", "Sales.Customers", newParser);
     newParser.DataModel = this.dataModel;
     try
     {
         this.dataModel.resetControl(currentFilter);
     }
     catch(Exception ex)
     {
         Session["current_error"] = ex.Message;
         Response.Redirect("serverError.aspx");
     }
 }