public void CollectionMemento()
        {
            mocks.ViewDataContainer.Object.ViewData["Services"] = NakedObjectsFramework.GetServices();

            INakedObject service = NakedObjectsFramework.ServicesManager.GetService("ClaimRepository");
            IActionSpec  action  = service.Spec.GetObjectActions().Single(a => a.Id == "FindMyClaims");

            INakedObject[] parms = new[] { null, "" }.Select(o => NakedObjectsFramework.NakedObjectManager.CreateAdapter(o, null, null)).ToArray();

            var cm = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);
            var claims = (IEnumerable)cm.RecoverCollection().Object;

            Assert.AreEqual(5, claims.Cast <object>().Count());
            Assert.AreEqual(cm, cm.RecoverCollection().Oid);
        }
Ejemplo n.º 2
0
        private static void RecoverCollection(IEnumerable <TestDomainObject> originalCollection, CollectionMemento memento, INakedObjectManager manager)
        {
            var recoveredCollection = memento.RecoverCollection().GetAsEnumerable(manager).Select(AdapterUtils.GetDomainObject <TestDomainObject>);
            var oc = originalCollection.ToList();
            var rc = recoveredCollection.ToList();

            Assert.IsTrue(oc.SequenceEqual(rc), "recovered collection not same as original");
        }
        public void CollectionMementoToStringWithObject()
        {
            mocks.ViewDataContainer.Object.ViewData["Services"] = NakedObjectsFramework.GetServices();

            var          status  = NakedObjectsFramework.Persistor.Instances <ClaimStatus>().First();
            INakedObject service = NakedObjectsFramework.ServicesManager.GetService("ClaimRepository");
            IActionSpec  action  = service.Spec.GetObjectActions().Single(a => a.Id == "FindMyClaims");

            INakedObject[] parms = new object[] { status, "" }.Select(o => NakedObjectsFramework.NakedObjectManager.CreateAdapter(o, null, null)).ToArray();

            var cm = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);

            string[] strings = cm.ToEncodedStrings();
            var      cm2     = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, strings);
            var      claims  = (IEnumerable)cm2.RecoverCollection().Object;

            Assert.AreEqual(2, claims.Cast <object>().Count());
            Assert.AreEqual(cm2, cm2.RecoverCollection().Oid);
        }
        public void TestActionNoParmsWithSelected()
        {
            TestDomainObject    target     = NakedObjectsFramework.Persistor.Instances <TestDomainObject>().Single(i => i.Id == 1);
            INakedObjectAdapter targetNo   = NakedObjectsFramework.NakedObjectManager.CreateAdapter(target, null, null);
            IActionSpec         actionSpec = targetNo.Spec.GetActions().Single(a => a.Id == "Action1");

            var memento = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, targetNo, actionSpec, new INakedObjectAdapter[] {});

            var selectedMemento = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, memento, new object[] { target });

            RoundTrip(selectedMemento);
            IEnumerable <TestDomainObject> recoveredCollection = selectedMemento.RecoverCollection().GetAsEnumerable(NakedObjectsFramework.NakedObjectManager).Select(AdapterUtils.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");
        }
 private static INakedObject RestoreCollection(CollectionMemento memento)
 {
     return(memento.RecoverCollection());
 }