public CollectionMemento(CollectionMemento otherMemento, object[] selectedObjects) { IsPaged = otherMemento.IsPaged; IsNotQueryable = otherMemento.IsNotQueryable; Target = otherMemento.Target; Action = otherMemento.Action; Parameters = otherMemento.Parameters; SelectedObjects = selectedObjects; }
public void CollectionMemento() { var mocks = new ContextMocks(controller); mocks.ViewDataContainer.Object.ViewData["Services"] = FrameworkHelper.GetServices(); INakedObject service = NakedObjectsContext.ObjectPersistor.GetService("ClaimRepository"); INakedObjectAction action = service.Specification.GetObjectActions().Where(a => a.Id == "Find").SelectMany(a => a.Actions).Single(a => a.Id == "FindMyClaims"); INakedObject[] parms = new[] { null, "" }.Select(PersistorUtils.CreateAdapter).ToArray(); var cm = new CollectionMemento(service, action, parms); var claims = (IEnumerable)cm.RecoverCollection().Object; Assert.AreEqual(5, claims.Cast<object>().Count()); Assert.AreEqual(cm, cm.RecoverCollection().Oid); }
public void ObjectForQueryable() { var mocks = new ContextMocks(controller); IQueryable<Claim> claims = NakedObjectsContext.ObjectPersistor.Instances<Claim>().Take(2); mocks.ViewDataContainer.Object.ViewData[IdHelper.PagingData] = new Dictionary<string, int> { {IdHelper.PagingCurrentPage, 1}, {IdHelper.PagingPageSize, 2}, {IdHelper.PagingTotal, 2} }; var claimAdapter = PersistorUtils.CreateAdapter(claims.First()); var adapter = PersistorUtils.CreateAdapter(claims); var mockOid = new CollectionMemento(claimAdapter, claimAdapter.GetActionLeafNode("ApproveItems"), new INakedObject[] { }); adapter.SetATransientOid(mockOid); string s = mocks.HtmlHelper.Object(claims).ToString(); CheckResults("ObjectForQueryable", s); }
[Test, Ignore] // temp ignore pending proper tests public void AddCollection() { var mocks = new ContextMocks(controller); mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices(); var claim = NakedObjectsContext.ObjectPersistor.CreateInstance(NakedObjectsContext.Reflector.LoadSpecification(typeof(Claim))).GetDomainObject<Claim>(); var claims = new List<Claim> {claim}; var claimAdapter = FrameworkHelper.GetNakedObject(claim); var claimsAdapter = FrameworkHelper.GetNakedObject(claims); var mockOid = new CollectionMemento(claimAdapter, claimAdapter.GetActionLeafNode("ApproveItems"), new INakedObject[] { }); claimsAdapter.SetATransientOid(mockOid); mocks.HtmlHelper.ViewContext.HttpContext.Session.AddToCache(claimsAdapter); Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects().Contains(claims)); Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects().Count() == 1); }
private void RoundTrip(CollectionMemento memento) { string[] strings1 = memento.ToEncodedStrings(); var newMemento = new CollectionMemento(strings1); string[] strings2 = newMemento.ToEncodedStrings(); Assert.IsTrue(strings1.SequenceEqual(strings2), "memento failed roundtrip"); var copyMemento = new CollectionMemento(memento, new object[] {}); string[] strings3 = copyMemento.ToEncodedStrings(); Assert.IsTrue(strings1.SequenceEqual(strings3), "memento failed copy"); }
public void TestActionValueParmString() { TestDomainObject target = NakedObjectsContext.ObjectPersistor.Instances<TestDomainObject>().Single(i => i.Id == 1); INakedObject targetNo = PersistorUtils.CreateAdapter(target); INakedObjectAction action = targetNo.Specification.GetObjectActions().Single(a => a.Id == "Action6"); var memento = new CollectionMemento(targetNo, action, new[] {PersistorUtils.CreateAdapter("1")}); RoundTrip(memento); RecoverCollection(target.Action6("1"), memento); }
public void TestActionObjectCollectionParmEmpty() { TestDomainObject target = NakedObjectsContext.ObjectPersistor.Instances<TestDomainObject>().Single(i => i.Id == 1); INakedObject targetNo = PersistorUtils.CreateAdapter(target); INakedObjectAction action = targetNo.Specification.GetObjectActions().Single(a => a.Id == "Action5"); var rawParm = new List<TestDomainObject>(); INakedObject parm = PersistorUtils.CreateAdapter(rawParm); var memento = new CollectionMemento(targetNo, action, new[] {parm}); RoundTrip(memento); RecoverCollection(target.Action5(rawParm), memento); }
public void TestActionNoParmsWithSelected() { TestDomainObject target = NakedObjectsContext.ObjectPersistor.Instances<TestDomainObject>().Single(i => i.Id == 1); INakedObject targetNo = PersistorUtils.CreateAdapter(target); INakedObjectAction action = targetNo.Specification.GetObjectActions().Single(a => a.Id == "Action1"); var memento = new CollectionMemento(targetNo, action, new INakedObject[] {}); var selectedMemento = new CollectionMemento(memento, new[] {target}); RoundTrip(selectedMemento); IEnumerable<TestDomainObject> recoveredCollection = selectedMemento.RecoverCollection().GetAsEnumerable().Select(no => no.GetDomainObject<TestDomainObject>()); Assert.IsFalse(target.Action1().SequenceEqual(recoveredCollection), "recovered selected collection same as original"); IEnumerable<TestDomainObject> selectedCollection = target.Action1().Where(tdo => tdo.Id == target.Id); Assert.IsTrue(selectedCollection.SequenceEqual(recoveredCollection), "recovered selected collection not same as original selected collection"); }
public void TestActionNoParmsTransient() { var targetNo = NakedObjectsContext.ObjectPersistor.CreateInstance(NakedObjectsContext.Reflector.LoadSpecification(typeof (TestDomainObject))); INakedObjectAction action = targetNo.Specification.GetObjectActions().Single(a => a.Id == "Action1"); var memento = new CollectionMemento(targetNo, action, new INakedObject[] { }); RoundTrip(memento); RecoverCollection(targetNo.GetDomainObject<TestDomainObject>().Action1(), memento); }
private void RecoverCollection(IEnumerable<TestDomainObject> originalCollection, CollectionMemento memento) { IEnumerable<TestDomainObject> recoveredCollection = memento.RecoverCollection().GetAsEnumerable().Select(no => no.GetDomainObject<TestDomainObject>()); Assert.IsTrue(originalCollection.SequenceEqual(recoveredCollection), "recovered collection not same as original"); }
public void GetCollectionNakedObjectFromId() { IList<Claim> claims = FrameworkHelper.GetService<ClaimRepository>().FindMyClaims(null, ""); INakedObject no = PersistorUtils.CreateAdapter(claims); INakedObject service = NakedObjectsContext.ObjectPersistor.GetService("ClaimRepository"); INakedObjectAction action = service.Specification.GetObjectActions().Where(a => a.Id == "Find").SelectMany(a => a.Actions).Where(a => a.Id == "FindMyClaims").Single(); INakedObject[] parms = new[] {null, ""}.Select(PersistorUtils.CreateAdapter).ToArray(); var cm = new CollectionMemento(service, action, parms); no.SetATransientOid(cm); string id = FrameworkHelper.GetObjectId(no); INakedObject no2 = FrameworkHelper.GetNakedObjectFromId(id); List<Claim> claims2 = no2.GetDomainObject<IEnumerable<Claim>>().ToList(); Assert.AreEqual(claims.Count(), claims2.Count()); int index = 0; Dictionary<Claim, Claim> dict = claims.ToDictionary(x => x, y => claims2.Skip(index++).First()); dict.ForEach(kvp => Assert.AreSame(kvp.Key, kvp.Value)); }
public void CollectionMementoToStringWithObject() { var mocks = new ContextMocks(controller); mocks.ViewDataContainer.Object.ViewData["Services"] = FrameworkHelper.GetServices(); object status = NakedObjectsContext.ObjectPersistor.Instances(typeof(ClaimStatus)).Cast<object>().First(); INakedObject service = NakedObjectsContext.ObjectPersistor.GetService("ClaimRepository"); INakedObjectAction action = service.Specification.GetObjectActions().Where(a => a.Id == "Find").SelectMany(a => a.Actions).Single(a => a.Id == "FindMyClaims"); INakedObject[] parms = new[] { status, "" }.Select(PersistorUtils.CreateAdapter).ToArray(); var cm = new CollectionMemento(service, action, parms); string[] strings = cm.ToEncodedStrings(); var cm2 = new CollectionMemento(strings); var claims = (IEnumerable)cm2.RecoverCollection().Object; Assert.AreEqual(2, claims.Cast<object>().Count()); Assert.AreEqual(cm2, cm2.RecoverCollection().Oid); }