public void testStoreManager()
        {
            try {
                //week 3
                //IManagerSvc ics = factory.getManagerSvc();

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

                // First let's store the Inventory
                Assert.True(ics.storeManager(m));

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

                // Update Manager
                m.lastName = "Smith";
                Assert.True(ics.storeManager(m));

                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteManager(m.id));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testStoreManager: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #2
0
        public void testInvalidManager()
        {
            try {
                Manager m = new Manager();

                Assert.False(m.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidManager: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #3
0
        public void testValidateManager()
        {
            try {
                Manager m = new Manager();
                m.id = 1;
                m.firstName = "Jim";
                m.lastName = "Bloom";

                Assert.True(m.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testValidateManager: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        /// <summary>
        /// This method stores a manager.
        /// </summary>
        /// <param name="m">The manager object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeManager(Manager m)
        {
            dLog.Info("Entering method storeManager | ID: " + m.id);
            Stream output = null;
            Boolean result = false;

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

            return result;
        }