コード例 #1
0
        public void GetCollectionNakedObjectFromId()
        {
            IList <Claim>       claims = NakedObjectsFramework.GetService <ClaimRepository>().FindMyClaims(null, "");
            INakedObjectAdapter no     = NakedObjectsFramework.NakedObjectManager.CreateAdapter(claims, null, null);

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

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

            var cm    = CollectionMementoHelper.TestMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);

            no.SetATransientOid(cm);

            string id = NakedObjectsFramework.GetObjectId(no);

            INakedObjectAdapter no2 = NakedObjectsFramework.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));
        }
コード例 #2
0
        public void AddCollection()
        {
            var claimRepo        = NakedObjectsFramework.GetServices().OfType <ClaimRepository>().FirstOrDefault();
            var claimRepoAdapter = NakedObjectsFramework.GetNakedObject(claimRepo);
            var claims           = claimRepo.AllClaims();
            var claimsAdapter    = NakedObjectsFramework.GetNakedObject(claims);
            var mockOid          = CollectionMementoHelper.TestMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, claimRepoAdapter, claimRepoAdapter.GetActionLeafNode("AllClaims"), new INakedObjectAdapter[] {});

            claimsAdapter.SetATransientOid(mockOid);

            var ca = Surface.GetObject(claimsAdapter.Object);

            mocks.HtmlHelper.ViewContext.HttpContext.Session.AddToCache(Surface, ca);
            Assert.IsTrue(((IEnumerable <object>)mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(Surface).First()).SequenceEqual(claims));
        }
コード例 #3
0
        public void CollectionMemento()
        {
            mocks.ViewDataContainer.Object.ViewData["Services"] = NakedObjectsFramework.GetServices();

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

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

            var cm = CollectionMementoHelper.TestMemento(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);
        }
コード例 #4
0
        public void CollectionMementoToStringWithObject()
        {
            mocks.ViewDataContainer.Object.ViewData["Services"] = NakedObjectsFramework.GetServices();

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

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

            var cm          = (IEncodedToStrings)CollectionMementoHelper.TestMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);

            string[] strings = cm.ToEncodedStrings();
            var      cm2    = CollectionMementoHelper.TestMemento(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);
        }