예제 #1
0
        public void AddContactWithComment()
        {
            IUnitOfWork uow = facade.GetUnitOfWork();

            int numberOfObjectWritten = 0;

            Contact c = new Contact() { idnum = "9000", contact = "Whole Foods Market", atten = "Bullwinkle Moose", phone = "618 281 7313" };

            Assert.True(c.NoErrors);

            Ccomment cc = new Ccomment() { Comment = "I like Whole Foods Market", Date = DateTime.Now };
            Ccomment cc2 = new Ccomment() { Comment = "Whole Foods Market has great products!", Date = DateTime.Now };

            Assert.True(cc.NoErrors);

            c.Ccomments.Add(cc);
            c.Ccomments.Add(cc2);

            if (c.NoErrors)
            {
                try
                {
                    uow.ContactRepo.Insert(c);

                    uow.Commit();
                }
                catch (DbEntityValidationException e)
                {
                    CommonTests.CheckDbEntityValidationException(e);
                }
                catch (Exception)
                {
                    //Console.WriteLine("caught exception: {0}", e.Message.ToString());
                }
                finally
                {
                    numberOfObjectWritten = uow.NumberOfObjectsWritten;

                    facade.ReturnUnitOfWork();

                    Assert.AreEqual(3, numberOfObjectWritten);
                }
            }
            else
            {
                facade.ReturnUnitOfWork();

                Assert.Fail("Failed to add object to db");
            }
        }
예제 #2
0
        public void AddContactToUnitTestDb()
        {
            IUnitOfWork uow = facade.GetUnitOfWork();

            int numberOfObjectWritten = 0;

            Contact cont = new Contact() { idnum = "9000", company = "Whole Foods Market", contact = "Bullwinkle Moose", phone = "618 281 7313" };

            if(cont.NoErrors)
            {
                try
                {
                    uow.ContactRepo.Insert(cont);

                    uow.Commit();
                }
                catch(DbEntityValidationException e)
                {
                    CommonTests.CheckDbEntityValidationException(e);
                }
                catch(Exception)
                {
                    //Console.WriteLine("caught exception: {0}", e.Message.ToString());
                }
                finally
                {
                    numberOfObjectWritten = uow.NumberOfObjectsWritten;

                    facade.ReturnUnitOfWork();

                    Assert.AreEqual(1, numberOfObjectWritten);
                }
            }
            else
            {
                facade.ReturnUnitOfWork();

                Assert.Fail("Failed to add contact to db");
            }
        }
 protected void Setup()
 {
     contact = new Contact();
     entityType = typeof(Contact);
 }