I believe you're running into this issue because you're mocking a concrete class. Can you take your repository class, extract an interface from it, and mock that. Doing it this way will allow you to set up return values or expectations. Since your repository class implements the interface at runtime your code should work well.
In summation I believe what you're seeing is a side effect of mocking a concrete class, in this case a concrete class that has NHibernate specific information. Does that make sense or help? On Fri, Mar 27, 2009 at 9:14 AM, Nev <[email protected]> wrote: > > Well my test is something like: > > using(_mocks.Record()) > { > docRepository.Expect(d=>d.Add(null)).IgnoreArguments(); > logRepository.Expect(l=>l.Add(null).IgnoreArguements(); > } > > using(_mocks.Playback()) > { > var result = CreateNewDoc(); > Assert.IsNotNull(result); > } > > > With CreateNewDoc being the code listed initially and returning the > created doc object. However when I do this I get an error stating that > the DocumentId on the doc object cannot be 0. Yet normally that Id > would be returned by the repository after it was saved in the DB. I am > wondering how I could mock that same behavior so that the doc object's > DocumentID gets filled in the mock add method just as it would in the > real code. > On Mar 26, 8:07 pm, Tim Barcz <[email protected]> wrote: > > Anything testing we're here to help with! Can you provide your current > test > > so we can try it out and make some recommendations? > > > > Tim > > > > On Thu, Mar 26, 2009 at 5:14 PM, Nev <[email protected]> wrote: > > > > > Well I was asking how I would mock the code so that it would update > > > the property correctly. Or is it something that needs to be done in > > > NHibernate? > > > > > On Mar 26, 4:20 pm, Christiaan Baes <[email protected]> wrote: > > > > I think you should try the nhibernate mailinglist. I don't see what > this > > > > has to do with Rhino mocks. > > > > > > Nev schreef: > > > > > > > I have a problem with the saving of objects in the NHibernate > session > > > > > since it does not seem to update the Id column value. > > > > > > > I have the following mapping: > > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > > > > assembly="Vge.DocumentService.Model" > > > > > namespace="Vge.DocumentService.Model" > > > > > auto-import="false"> > > > > > <class name="Document" table="Document"> > > > > > <id name="DocumentId" type="Int32" column="DocumentId" unsaved- > > > > > value="0"> > > > > > <generator class="identity"></generator> > > > > > </id> > > > > > <property name="DocumentLookupId" column="DocumentLookupId" > > > > > type="Int32"></property> > > > > > <property name="DocumentTypeId" column="DocumentTypeId" > > > > > type="Int32"></property> > > > > > <property name="Filename" column="Filename" type="String"></ > > > > > property> > > > > > <property name="Description" column="Description" > type="String"></ > > > > > property> > > > > > <many-to-one column="DocumentTypeId" name="DocumentTypeSource" > > > > > class="DocumentType" /> > > > > > <many-to-one column="DocumentLookupId" class="DocumentLookup" > > > > > name="DocumentLookupSource" cascade="save-update" /> > > > > > </class> > > > > > <class name="DocumentLog" table="DocumentLog"> > > > > > <id name="DocumentLogId" column="DocumentLogId" type="Int32" > > > > > unsaved-value="0"> > > > > > <generator class="identity"></generator> > > > > > </id> > > > > > <property name="DocumentActionId" column="DocumentActionId" > > > > > type="Int32"></property> > > > > > <property name="DocumentId" column="DocumentId" type="Int32"></ > > > > > property> > > > > > <property name="Username" column="Username" type="String"></ > > > > > property> > > > > > <property name="LogDate" column="LogDate" type="DateTime"></ > > > > > property> > > > > > </class> > > > > > </hibernate-mapping> > > > > > > > Now I am calling something like the following in my mock: > > > > > > > var doc = new Document { > > > > > DocumentLookupId = 1, > > > > > DocumentTypeId = 1, > > > > > Filename = "testfile.txt", > > > > > Description = "A test file", > > > > > }; > > > > > > > docRepository.Add(doc); > > > > > > > var log = new DocumentLog { > > > > > DocumentActionId = 1, > > > > > DocumentId = doc.DocumentId, > > > > > Username = "TestUser", > > > > > LogDate = DateTime.Now > > > > > }; > > > > > > > However I am getting an error that the DocumentId is not allowed to > be > > > > > null in the var log statement. Now the document repository is the > Data > > > > > layer and calls the session so technically after the add is called > the > > > > > session would have been flushed so that the document would have > > > > > obtained its new id from the DB but there is no way that I know of > to > > > > > mock that so that the documentid is populated in this test. Any > input > > > > > would be appreciated. > > > > > > > Thanks, > > > > > > > Nev > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/RhinoMocks?hl=en -~----------~----~----~----~------~----~------~--~---
