public void testCustomerSvc()
        {
            try {
                //week 3
                //ICustomerSvc ics = factory.getCustomerSvc();

                //week 4
                ICustomerSvc ics = (ICustomerSvc) factory.getService("ICustomerSvc");

                // First let's store the Customer
                Assert.True(ics.storeCustomer(c));

                // Then let's read it back in
                c = ics.getCustomer(c.id);
                Assert.True(c.validate());

                // Update customer
                c.emailAddress = "*****@*****.**";
                Assert.True(ics.storeCustomer(c));

                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteCustomer(c.id));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testStoreCustomer: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Ejemplo n.º 2
0
        public void testInvalidCustomer()
        {
            try {
                Customer c = new Customer();

                Assert.False(c.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidCustomer: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Ejemplo n.º 3
0
        public void testValidate()
        {
            try {
                Customer c = new Customer();
                c.id = 1;
                c.emailAddress = "*****@*****.**";
                c.firstName = "Jim";
                c.lastName = "Bloom";

                Assert.True(c.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testValidate: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        public void testInvalidGetCustomer()
        {
            try {
                //week 3
                //ICustomerSvc ics = factory.getCustomerSvc();

                //week 4
                ICustomerSvc ics = (ICustomerSvc) factory.getService("ICustomerSvc");
                c = ics.getCustomer(1234);

                if(c != null)
                    Assert.False(c.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidGetCustomer: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        /// <summary>
        /// This method stores a customer.
        /// </summary>
        /// <param name="c">The customer object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeCustomer(Customer c)
        {
            dLog.Info("Entering method storeCustomer | ID: " + c.id);
            Stream output = null;
            Boolean result = false;

            try
            {
                //ensure we were passed a valid object before attempting to write
                if (c.validate())
                {
                    output = File.Open("Customer_" + c.id + ".txt", FileMode.Create);
                    BinaryFormatter bFormatter = new BinaryFormatter();
                    bFormatter.Serialize(output, c);
                    result = true;
                }
            }
            catch (IOException e1)
            {
                dLog.Error("IOException in storeCustomer: " + e1.Message);
                result = false;
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeCustomer: " + e2.Message);
                result = false;
            }
            finally
            {
                //ensure that output is close regardless of the errors in try/catch
                if (output != null)
                {
                    output.Close();
                }
            }

            return result;
        }