public void TestQueueWithEmptyList( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(null); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); string sName = Guid.NewGuid( ).ToString( ); string sPhone = Guid.NewGuid( ).ToString( ); Data.Person dPerson = svc.Queue(sName, sPhone); Assert.IsNotNull(dPerson); Assert.AreEqual(sName, dPerson.Name); Assert.AreEqual(sPhone, dPerson.Phone); Assert.AreNotEqual(Guid.Empty, dPerson.Id); } }
public void TestDequeueWithEmptyList( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(null); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); svc.Dequeue(new Data.Person( ) { Id = Guid.NewGuid( ), Name = Guid.NewGuid( ).ToString( ), Phone = Guid.NewGuid( ).ToString( ) }); } }
public void TestDequeue( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(System.Xml.Linq.XElement.Parse("<Waitlist><Persons><Person Id=\"47a73298-d91c-4c94-80aa-d935c9b0873e\"><Name>50ffab1f-b894-4632-898d-2c6588856641</Name><Phone>5be558b7-2c57-4156-96e0-d2442bc41975</Phone></Person></Persons></Waitlist>")); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); svc.Dequeue(new Data.Person( ) { Id = new Guid("47a73298-d91c-4c94-80aa-d935c9b0873e"), Name = "50ffab1f-b894-4632-898d-2c6588856641", Phone = "5be558b7-2c57-4156-96e0-d2442bc41975" }); } }
public Data.Person Queue(string sName, string sPhone) { Data.Person dPerson = new Data.Person( ) { Id = Guid.NewGuid( ), Name = sName, Phone = sPhone }; // normally this logic would exist on the server side. if (string.IsNullOrEmpty(sName)) { throw new Exception.QueueException(Exception.QueueException.ResponseCodes.InvalidName); } else if (string.IsNullOrEmpty(sPhone)) { throw new Exception.QueueException(Exception.QueueException.ResponseCodes.InvalidPhone); } lock ( ms_oSync ) { System.Xml.Linq.XElement xWaitList = m_oXmlFilePersister.Load(mc_sStorageName) ?? new System.Xml.Linq.XElement("Waitlist"); System.Xml.Linq.XElement xPersons = GetPersons(xWaitList); if (xPersons.Elements("Person") .Select(xPerson => m_adpPersonFromXml.Adapt(xPerson)) .Any(dPersonSearch => dPersonSearch == dPerson)) { throw new Exception.QueueException(Exception.QueueException.ResponseCodes.PersonExists); } xPersons.Add(m_adpPersonToXml.Adapt(dPerson)); m_oXmlFilePersister.Save(mc_sStorageName, xWaitList); } return(dPerson); }