Hey Patrick,

I spent 2 days to find the solution  for this problem and you resolved
within 10  minutes.
Thanks a lot.


On Sep 9, 6:59 pm, Patrick Steele <[email protected]> wrote:
> var argTree = _crosschargeRepository.GetArgumentsForCallsMadeOn(r =>
> r.SaveOrUpdate(null));
>
> var entity = (LegalEntity) argTree[0][0];
>
> I might have messed up the format of the first call, but it returns a
> jagged array.
>
> argTree[0] is an object[] of the arguments passed on the first call to
> the method
> argTree[1] is an object[] of the arguments passed on the second call
> to the method
> etc...
>
> ---
> Patrick Steelehttp://weblogs.asp.net/psteele
>
>
>
>
>
>
>
> On Fri, Sep 9, 2011 at 9:35 AM, VG <[email protected]> wrote:
> > Hi,
>
> > I am having a problem verifying the entity object that has been passed
> > to IRepository's saveorupdate method.
> > Here is the code snippet I am working upon :
>
> > This is my Action  in controller , it contains more code but I am
> > putting only the concerned code :
>
> > [AcceptVerbs(HttpVerbs.Post)]
> >        [Transaction]
> >        public ActionResult EditContentFieldAnswer(int
> > symposiaEventId, int contentId, int contentFieldAnswerGroupId,
> > EventRegistrationPageInfo pageInfo) {
> > if (!string.IsNullOrEmpty(pageInfo.IsCrossCharge)) { //Create the
> > crosscharge record for this user.
> >                try {
> >                    var legalEntity =
> > pageInfo.LegalEntityToCrossCharge;
> >                    legalEntity = string.IsNullOrEmpty(legalEntity) ?
> > "000" : legalEntity; //Default to 000
> >                    var costCenterToCrossCredit =
> > pageInfo.CostCenterToCredit;
> >                    var crosscharge =
> > _crosschargeQueries.GetCrosschargeForUser(symposiaEventId,
>
> > _sessionUserService.CurrentUser.
>
> > UserId);
> >                    if (crosscharge != null) { // This could be null
> > if the user was registered for the event then the presenter turned
> > crosscharging on
> >                        crosscharge.LegalEntityToCredit = legalEntity;
> >                        crosscharge.CostCenterToCredit =
> > costCenterToCrossCredit;
> >                        using
> > (_crosschargeRepository.DbContext.BeginTransaction()) {
>
> > _crosschargeRepository.SaveOrUpdate(crosscharge);
>
> > _crosschargeRepository.DbContext.CommitTransaction();
> >                        }
> >                    }
>
> >                } catch {
> >                    message = "A problem was encountered preventing
> > the crosscharge from being created.";
>
> > _crosschargeRepository.DbContext.RollbackTransaction();
> >                }
> >            }
> > }
>
> > This is my mock object :
>
> >  public static ICrosschargeQueries CreateMockCrossChargeQueries()
> >        {
> >            var mockedRepository =
> > MockRepository.GenerateMock<ICrosschargeQueries>();
> >            mockedRepository.Expect(mr => mr.GetCrosschargeForUser(1,
> > 1)).IgnoreArguments().Return(new Crosscharge());
> >            return mockedRepository;
> >        }
>
> > This is my Unit Test :
>
> > [Test]
> >        public void
> > CanEditContentFieldAnswerWhenLegalEntityToCrossChargeIsNull()
> >        {
> >            var pageInfo =
> > CreateTransientEventRegistrationPageInfoWithLegalEntityToCrossChargeSetNull();
> >            var result = _controller.EditContentFieldAnswer(1, 1, 0,
> > pageInfo).AssertViewRendered();
>
> >            Assert.IsNotNull(result);
>
> > Assert.IsInstanceOf<ContentFieldAnswerFormViewModel>(result.ViewData.Model);
> >            _crosschargeRepository.AssertWasCalled(x =>
> > x.SaveOrUpdate(null),y=>y.IgnoreArguments());
> >        }
>
> > This is my Transient Object for "EventRegistrationPageInfo"
>
> >  public static EventRegistrationPageInfo
> > CreateTransientEventRegistrationPageInfoWithLegalEntityToCrossChargeSetNull()
> >        {
> >            var eventRegistrationPageInfo = new
> > EventRegistrationPageInfo
> >            {
> >                CrossChargeId = "TestCrossChargeId",
> >                IsCrossCharge = "true",
> >                LegalEntityToCrossCharge = null,
> >                SymposiaEventRegistrationId = "TestId",
> >                IsRegistration = "true",
> >                CostCenterToCredit = "TestCostCenterToCredit"
> >            };
> >            return eventRegistrationPageInfo;
> >        }
>
> > If you look at the action code , just under the try block code I have
> > this line of code
> > legalEntity = string.IsNullOrEmpty(legalEntity) ? "000" :
> > legalEntity; //Default to 000
>
> > Which checks whether LegalEntityToCrossCharge  property is null or
> > not, if its null the legalEntity property of CrossCharge is updated
> > "000" otherwise its assigned the value that was there in
> > EventRegistrationPageInfo object's LegalEntityToCrossCharge  property.
>
> > My concern is While unit testing I can verify whether saveorupdate was
> > called or not using this line of code
> >  _crosschargeRepository.AssertWasCalled(x =>
> > x.SaveOrUpdate(null),y=>y.IgnoreArguments());
> > but how do I get the values of crosscharge entity that has been
> > saved .I had passed LegalEntityToCrossCharge  as null which allows
> > legalEntity property to be updated to "000", I need to verify this in
> > my unit test.
> > How can I do this?
>
> > --
> > 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 
> > athttp://groups.google.com/group/rhinomocks?hl=en.

-- 
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.

Reply via email to