예제 #1
0
        public void WriteToFileTest()
        {
            // Arrange
            var changedItems = new List<ILoggable>();

            var customer = new Customer(1)
            {
                FirstName = "John",
                LastName = "Lennon",
                EmailAddress = "*****@*****.**",
                AddressList = null
            };

            var product = new Product()
            {
                ProductName = "Guitar",
                CurrentPrice = 399.99M,
                ProductDescription = "Gibson Les Paul"
            };

            changedItems.Add(customer as ILoggable);
            changedItems.Add(product as ILoggable);


            // Act
            LoggingService.WriteToFile(changedItems);

            // Assert
            // Nothing to assert in this case.
        }
예제 #2
0
        public void WriteToFileTest()
        {
            //--Arrange
            var changedItems = new List<ILoggable>();
            var customer = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName = "Frodo",
                LastName = "Baggins",
                AddressList = null
            };
            changedItems.Add(customer as ILoggable);

            var product = new Product(2)
            {
                ProductName = "Rake",
                ProductDescription = "Garden Rake with Steel handle",
                CurrentPrice = 6M
            };
            changedItems.Add(product as ILoggable);

            //--Act
            LoggingService.WriteToFile(changedItems);

            //--Assert
            //Nothing to assert
        }
예제 #3
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            var customer = new Customer();

            var result = customer.CalculatePercentOfGoalSteps(this.txtTowardsGoal.Text,
                this.txtStepsToday.Text);

            lblResult.Text = "You reached " + result + "% of your goal!!!";
        }
        public void RetrieveExistingWithAddress()
        {
            //-- Arrange
            var customerRepositorty = new CustomerRepository();
            var expected = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName = "Frodo",
                LastName = "Baggins",
                AddressList = new List<Address>()
                    {
                        new Address()
                        {
                            AddressType = 1,
                            StreetLine1 = "Bag End",
                            StreetLine2 = "Bagshot row",
                            City = "Hobbiton",
                            State = "Shire",
                            Country = "Middle Earth",
                            PostalCode = "144"
                        },
                        new Address()
                        {
                            AddressType = 2,
                            StreetLine1 = "Green Dragon",
                            City = "Bywater",
                            State = "Shire",
                            Country = "Middle Earth",
                            PostalCode = "146"
                        }
                    }
            };
            

            //-- Act
            var actual = customerRepositorty.Retrieve(1);

            //-- Assert
            Assert.AreEqual(expected.CustomerId, actual.CustomerId);
            Assert.AreEqual(expected.EmailAddress, actual.EmailAddress);
            Assert.AreEqual(expected.FirstName, actual.FirstName);
            Assert.AreEqual(expected.LastName, actual.LastName);

            for (int i = 0; i < 1; i++)
            {
                Assert.AreEqual(expected.AddressList[i].AddressType, actual.AddressList[i].AddressType);
                Assert.AreEqual(expected.AddressList[i].StreetLine1, actual.AddressList[i].StreetLine1);
                Assert.AreEqual(expected.AddressList[i].City, actual.AddressList[i].City);
                Assert.AreEqual(expected.AddressList[i].State, actual.AddressList[i].State);
                Assert.AreEqual(expected.AddressList[i].Country, actual.AddressList[i].Country);
                Assert.AreEqual(expected.AddressList[i].PostalCode, actual.AddressList[i].PostalCode);
            }

        }
 public void Add(Customer customer)
 {
     //-- If this is a new customer, create the customer record –
     //Determine whether the customer is an existing customer.
     //If not, validate entered customer information
     //If not valid, notify the user.
     //If valid,
     //Open a connection
     //Set stored procedure parameters with the customer data
     //Call the save stored procedure.
 }
        public void CalculatePercentOfGoalStepsTestGoalIsNull()
        {
            // -- Arrange
            var customer = new Customer();
            string goalSteps = null;
            string actualSteps = "2000";

            // -- Actual
            var actual = customer.CalculatePercentOfGoalSteps(goalSteps, actualSteps);

            // -- Assert
        }
예제 #7
0
        public void FullNameLastNameEmpty()
        {
            //-- Arrange
            Customer customer = new Customer();
            customer.FirstName = "Bilbo";
            string expected = "Bilbo";

            //-- Act
            string actual = customer.FullName;

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
예제 #8
0
        public void ObjectTypeTest()
        {
            //-- Arrange
            var c1 = new Customer();
            c1.FirstName = "Bilbo";

            //-- Act
            var c2 = c1;
            c2.FirstName = "Frodo";

            //-- Assert
            Assert.AreEqual("Frodo", c1.FirstName);
        }
        public void PlaceOrderTestNullOrder()
        {
            // -- Arrange
            var orderController = new OrderController();
            var customer = new Customer() { EmailAddress = "*****@*****.**" };
            Order order = null;
            var payment = new Payment() { PaymentType = 1 };

            // -- Actual
            OperationResult op = orderController.PlaceOrder(customer, order, payment, allowSplitOrders: true,
                emailReceipt: true);

            // -- Assertion
        }
예제 #10
0
        public CustomerModel CreateCustomerModel(Customer cust)
        {
            CustomerModel model = new CustomerModel()
            {
                CustomerId = cust.CustomerId,
                CustomerType = cust.CustomerType.ToString(),
                EmailAddress = cust.EmailAddress,
                FirstName = cust.FirstName,
                LastName = cust.LastName,
                InvoiceList = cust.InvoiceList.Select(c => c.InvoiceId.ToString()).ToList()
            };

            return model;
        }
예제 #11
0
        public void ValidateValid()
        {
            //--Arrange
            var c1 = new Customer();
            c1.LastName = "Baggins";
            cus
            var c2 = new Customer();
            Customer.InstanceCount += 1;
            var c3 = new Customer();
            Customer.InstanceCount += 1;

            //-ACT
            //-Assert
        }
예제 #12
0
        public void InstanceCountTest()
        {
            //--Arrange
            var c1 = new Customer();
            Customer.InstanceCount +=1;
            var c2 = new Customer();
            Customer.InstanceCount +=1;
            var c3 = new Customer();
            Customer.InstanceCount +=1;

            //-ACT
            //-Assert
            Assert.AreEqual(3, Customer.InstanceCount);
        }
예제 #13
0
        public void CalculatePercentOfGoalStepsTestValidActualIsZero()
        {
            //-- Arrange
            var customer = new Customer();
            string goalSteps = "5000";
            string actualSteps = "0";
            decimal expected = 0M;

            //-- Act
            var actual = customer.CalculatePercentOfGoalSteps(goalSteps, actualSteps);

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
예제 #14
0
        public void FullNameTestValid()
        {
            //-- Arrange
            Customer customer = new Customer();
            customer.FirstName = "Bilbo";
            customer.LastName = "Baggins";

            string expected = "Baggins, Bilbo";

            //-- Act
            string actual = customer.FullName;

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
        public void PlaceOrderTest()
        {
            // -- Arrange
            var orderController = new OrderController();
            var customer = new Customer() { EmailAddress = "*****@*****.**" };
            var order = new Order();
            var payment = new Payment() { PaymentType = 1 };

            // -- Actual
            OperationResult op = orderController.PlaceOrder(customer, order, payment, allowSplitOrders: true,
                emailReceipt: true);

            // -- Assertion
            Assert.AreEqual(true, op.Success);
            Assert.AreEqual(0, op.MessageList.Count);
        }
        /// <summary>
        /// Retrieve one customer.
        /// </summary>
        public Customer Retrieve(int customerId)
        {
            // Create the instance of the Customer class
            Customer customer = new Customer(customerId);

            // Code that retrieves the defined customer

            // Temporary hard coded values to return 
            // a populated customer
            if (customerId == 1)
            {
                customer.EmailAddress = "*****@*****.**";
                customer.FirstName = "Frodo";
                customer.LastName = "Baggins";
            }
            return customer;
        }
 public bool Save(Customer customer)
 {
     // Code that saves the defined customer
     var success = true;
     if (customer.HasChanges && customer.IsValid)
     {
         if (customer.IsNew)
         {
             //Call an insert function for a new customer
         }
         else
         {
             //Call an update function
         }
     }
     return success;
 }
        /// <summary>
        /// Saves the current customer.
        /// </summary>
        /// <returns></returns>
        public bool Save(Customer customer)
        {
            var success = true;

            if (customer.HasChanges && customer.IsValid)
            {
                if (customer.IsNew)
                {
                    // Call an Insert Stored Procedure

                }
                else
                {
                    // Call an Update Stored Procedure
                }
            }
            return success;
        }
예제 #19
0
파일: OrderWin.cs 프로젝트: Tharnid/Caamas
        private void PlaceOrder()
        {
            var allowSplitOrders = true;
            var emailReceipt = true;

            var customer = new Customer();
            // Populate the customer instance

            var order = new Order();
            // Populate the order instance

            var payment = new Payment();
            // Populate the payment info from the UI

            var orderController = new OrderController();
            orderController.PlaceOrder(customer, order, payment,
                allowSplitOrders: false, emailReceipt: true); // allowSplitOrders: false, emailReceipt: true
        }
        public void CreateTest()
        {
            // Arrange
            Customer expected = new Customer
            {
                CustomerId = 0,
                LastName = null,
                FirstName = null
            };

            // Act
            Customer actual = Customer.Create();

            // Assert
            Assert.AreEqual(expected.CustomerId, actual.CustomerId);
            Assert.AreEqual(expected.LastName, actual.LastName);
            Assert.AreEqual(expected.FirstName, actual.FirstName);
        }
        public void CreateTest()
        {
            // Set up
            // Perform the operation
            Customer actual = Customer.Create();

            // Validate
            Customer expected = new Customer
            {
                CustomerId = 0,
                LastName = null,
                FirstName = null
            };

            Assert.AreEqual(expected.CustomerId, actual.CustomerId);
            Assert.AreEqual(expected.LastName, actual.LastName);
            Assert.AreEqual(expected.FirstName, actual.FirstName);
        }
예제 #22
0
        private void CalculateButton_Click(object sender, EventArgs e)
        {
            var customer = new Customer();

            try
            {
                var result = customer.CalculatePercentOfGoalSteps(GoalTextBox.Text, StepsTextBox.Text);
                ResultLabel.Text = "You reached " + result + "% of your goal!";
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("Your entry was not valid: " + ex.Message);
                ResultLabel.Text = string.Empty;

                // Don't want to have the exception thrown out, else it will still be handled by global exception handler
                //throw;
            }
        }
        public OperationResult PlaceOrder(Customer customer, Order order, Payment payment, bool allowSplitOrders, bool emailReceipt)
        {
            // This program makes assertions that certain functions are running (as functions below)
            // These will throw a warning during debuging if an assertion isn't true
            Debug.Assert(customerRepository != null, "Missing customer repository instance N***A");
            Debug.Assert(orderRepository != null, "Missing order repository instance");
            Debug.Assert(inventoryRepository != null, "Missing inventory repository instance");
            Debug.Assert(emailLibrary != null, "Missing email library instance");

            if (customer == null) throw new ArgumentNullException("Customer instance is null");
            if (order == null) throw new ArgumentNullException("Order instance is null");
            if (payment == null) throw new ArgumentNullException("Payment instance is null");

            var op = new OperationResult();

            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment();

            if (emailReceipt)
            {
                var result = customer.ValidateEmail();
                if (result.Success)
                {
                    customerRepository.Update();

                    emailLibrary.SendEmail(customer.EmailAddress, "Here is your receipt");
                }
                else
                {
                    // log the messages
                    if (result.MessageList.Any())
                    {
                        op.AddMessage(result.MessageList[0]);
                    }
                }
            }
            return op;
        }
예제 #24
0
        public void StaticTest()
        {
            //--Arrange
            var c1 = new Customer();
            c1.FirstName = "Bilbo";
            Customer.InstanceCount += 1;

            var c2 = new Customer();
            c2.FirstName = "Frodo";
            Customer.InstanceCount += 1;

            var c3 = new Customer();
            c3.FirstName = "Rosie";
            Customer.InstanceCount += 1;

            //--Act
            //--Assert
            Assert.AreEqual(Customer.InstanceCount, 3);
        }
        public void CalculatePercentOfGoalStepsTestGoalIsNotNumeric()
        {
            // -- Arrange
            var customer = new Customer();
            string goalSteps = "one";
            string actualSteps = "2000";

            // -- Actual
            try
            {
                var actual = customer.CalculatePercentOfGoalSteps(goalSteps, actualSteps);
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Goal must be numeric", ex.Message);
                throw;
            }
            // -- Assert
        }
        public Customer Retrieve(int customerId)
        {
            // Create the instance of the Customer Class
            // customerId is a reference to the one in the Customer class
            // the reference points to the "private set" method
            Customer customer = new Customer(customerId);

            // Create an address list for that customer
            // since RetrieveByCustomerId is an IEnumeral, use .ToList() to convert to list item
            customer.AddressList = addressRepository.RetrieveByCustomerId(customerId).ToList();

            // Temporary hard coded values to return a populated customer
            if (customerId == 1)
            {
                customer.EmailAddress = "*****@*****.**";
                customer.FirstName = "Frodo";
                customer.LastName = "Baggins";
            }
            return customer;
        }
        public void RetrieveExisting()
        {
            //--Arrange
            var customerRepository = new CustomerRepository();

            var expected = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName = "Frodo",
                LastName = "Baggins"
            };

            //--Act
            var actual = customerRepository.Retrieve(1);

            //--Asset
            Assert.AreEqual(expected.EmailAddress, actual.EmailAddress);
            Assert.AreEqual(expected.FirstName, actual.FirstName);
            Assert.AreEqual(expected.LastName, actual.LastName);
            Assert.AreEqual(expected.CustomerId, actual.CustomerId);
        }
        public void PlaceOrder(Customer customer,
                                Order order,
                                Payment payment,
                                bool allowSplitOrders, bool emailReceipt)
        {
            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment();

            if (emailReceipt)
            {
                customer.ValidateEmail();
                customerRepository.Update();

                emailLibrary.SendEmail(customer.EmailAddress, "Here are your receipt!");
            }
        }
예제 #29
0
        public void PlaceOrder(Customer customer,
                                Order order,
                                Payment payment,
                                bool allowSplitOrders, bool emailReceipt)  // put objects in order put flags(bool values) at the end
        {
            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment(payment);

            if (emailReceipt)
            {
                customer.ValidateEmail();
                customerRepository.Update();

                emailLibrary.SendEmail(customer.EmailAddress,
                                        "Here is your receipt");
            }
        }
예제 #30
0
        public void ValidateMissingLastName()
        {
            //--Arrange
            var customer = new Customer();
            customer.EmailAddress = "*****@*****.**";

            var expected = false;

            //--Act
            var actual = customer.Validate();

            //-Assert
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Saves the current customer
        /// </summary>
        /// <returns></returns>
        public bool Save(Customer customer)
        {
            // code that saves the passed in customer

            return(true);
        }