Ejemplo n.º 1
0
        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 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");
        }
 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");
 }
Ejemplo n.º 4
0
        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);
        }