[Nugsoft-commits] nugsoft/nUGSoft.Entities.Tests EventTests.cs,1.2,1.3
Brought to you by:
javery,
jimholmesoh
|
From: Jim H. <jim...@us...> - 2005-11-29 03:37:12
|
Update of /cvsroot/nugsoft/nugsoft/nUGSoft.Entities.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2079/nUGSoft.Entities.Tests Modified Files: EventTests.cs Log Message: Fixed init of IList members, fixed Initialize() to work with new unique constraints in DB (don't die if an entity is extant), cleaned up [TearDown] so all entities are deleted. Index: EventTests.cs =================================================================== RCS file: /cvsroot/nugsoft/nugsoft/nUGSoft.Entities.Tests/EventTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EventTests.cs 14 Nov 2005 03:15:13 -0000 1.2 --- EventTests.cs 29 Nov 2005 03:37:02 -0000 1.3 *************** *** 20,26 **** public EventTests() { ! } /// <summary> /// Initialize() is called once during test execution before --- 20,28 ---- public EventTests() { ! } + #region Fixture Infrastructure + /// <summary> /// Initialize() is called once during test execution before *************** *** 32,43 **** try { ! _event = new Event(); ! _event.Date = DateTime.Now; ! _event.IsGroupMeeting = false; ! _event.Topic = "Test Topic"; ! _event.Speaker = "Test Speaker"; ! _event.Description = "Test"; ! _event.Location = new Location(); ! _event.Location.Id = 1; _event.Save(); --- 34,83 ---- try { ! Person creator = TestFactory.CreateDefaultMember(); ! ! try ! { ! creator.Save(); ! } ! catch (NHibernate.ADOException ax) ! { ! //Violation of Unique Key is OK, die if other cause ! string msg = ax.InnerException.Message; ! if (!msg.Contains("Violation of UNIQUE KEY")) ! { ! Assert.Fail("Unexpected Inner Exception: " + msg); ! } ! else ! { ! //grab entity from db to load proper ID value ! creator = (Person)Person.FindSingle<Person>( ! "from Person pers where pers.FName = 'First'"); ! } ! } ! ! _event = TestFactory.CreateDefaultEvent(); ! Location loc = TestFactory.CreateDefaultLocation(); ! try ! { ! loc.Save(); ! } ! catch (NHibernate.ADOException ax) ! { ! //Violation of Unique Key is OK, die if other cause ! string msg = ax.InnerException.Message; ! if (!msg.Contains("Violation of UNIQUE KEY")) ! { ! Assert.Fail("Unexpected Inner Exception: " + msg); ! } ! else ! { ! //grab entity from db to load proper ID value ! loc = (Location)Location.FindSingle<Location>( ! "from Location loc where loc.Name = 'Location'"); ! } ! } ! ! _event.Location = loc; ! _event.PersonEventCreatorID = creator; _event.Save(); *************** *** 49,52 **** --- 89,118 ---- } + [TearDown] + public void DeleteEventTest() + { + Event evt = (Event)Event.Get<Event>(_event.Id); + int creatorID = evt.PersonEventCreatorID.Id; + int locationID = evt.Location.Id; + + if (evt != null) + { + evt.Delete(); + evt = (Event)EntityBase.Get<Event>(_event.Id); + Assert.IsNull(evt, "Entity was not deleted"); + } + Person creator = (Person)Person.Get<Person>(creatorID); + if (creator != null) + { + creator.Delete(); + } + Location loc = (Location) Location.Get<Location>(locationID); + if (loc != null) + { + loc.Delete(); + } + } + + #endregion [Test] *************** *** 61,64 **** --- 127,132 ---- } + #region Validation Tests + [Test] [ExpectedException(typeof(ValidationException))] *************** *** 89,105 **** ! ! ! ! [TearDown] ! public void DeleteEventTest() { ! Event evt = (Event)Event.Get<Event>(_event.Id); ! evt.Delete(); ! ! evt = (Event)Event.Get<Event>(_event.Id); ! Assert.IsNull(evt, "Entity was not deleted"); } } --- 157,177 ---- + #endregion ! /// <summary> ! /// Checks that adding a item to Persons of a default entity works properly. ! /// </summary> ! /// <remarks>Initially failed because IList members weren't init'd.</remarks> ! [Test] ! public void AddNewPersonItemToDefaultEvent() { ! //create a new persontype ! Event evt = new Event(); ! Person geek = new Person(); ! geek.FName = "Geek"; ! evt.Persons.Add(geek); ! Person check = evt.Persons[0] as Person; ! Assert.AreEqual(geek.FName, check.FName, "Check failed"); } } |