コード例 #1
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public StoreOfTest()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var store = x.IsOf <BaseThing>();

            BaseThing thing1 = new BaseThing()
            {
                Data = "data", Id = "thing1"
            };
            DerivedThing thing2 = new DerivedThing()
            {
                Data = "data", Data1 = "data1", Id = "thing2"
            };
            DerivedDerivedThing thing3 = new DerivedDerivedThing()
            {
                Data = "data", Data1 = "data1", Data2 = "data2", Id = "thing3"
            };
            var thing4 = AsId <string> .New("asId1");

            store.SaveItem(thing1);
            store.SaveItem(thing2);
            store.SaveItem(thing3);

            Assert.Throws <InvalidOperationException>(() =>
            {
                store.SaveItem(thing4);
            });

            store.DeleteItems(thing1.GetStoredObjectId(), thing2.GetStoredObjectId(), thing3.GetStoredObjectId());
        }))
        {
        }
コード例 #2
0
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var thing = AsId <string> .New("asId1");
            var soid  = thing.GetStoredObjectId();

            var store = x.BasicAudit(NamedNaturalInMemoryStore.New("auditstore").IsOf <StoredItemAuditPoint>());

            //do some stuff..all of this should be tracked
            store.SaveItem(thing);
            var auditItems = store.AuditStore.GetAll();
            Assert.True(auditItems[0].Mode == StoredItemAccessMode.Save && auditItems[0].ObjRef.Equals(soid));

            var clone  = store.Get <AsId <string> >("asId1");
            auditItems = store.AuditStore.GetAll();
            Assert.True(auditItems[1].Mode == StoredItemAccessMode.Read && auditItems[1].ObjRef.Equals(soid));

            var list   = store.SearchOf <AsId <string> >(LogicOfTo <AsId <string>, bool> .New((o) => { return(o.Id.Equals("asId1")); }));
            auditItems = store.AuditStore.GetAll();
            Assert.True(auditItems[2].Mode == StoredItemAccessMode.Read && auditItems[2].ObjRef.Equals(soid));

            var list2  = store.GetAll();
            auditItems = store.AuditStore.GetAll();
            Assert.True(auditItems[3].Mode == StoredItemAccessMode.Read && auditItems[3].ObjRef.Equals(soid));

            store.DeleteItem(soid);

            auditItems = store.AuditStore.GetAll();
            Assert.True(auditItems[4].Mode == StoredItemAccessMode.Delete && auditItems[4].ObjRef.Equals(soid));

            store.Dispose();
        }))
        {
        }
コード例 #3
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var store = x.HasFactory(LogicOfTo <IStoredObjectId, IHasId> .New((soId) =>
            {
                //the factory produces AsId<string> only
                if (soId.ObjectType.Equals(typeof(AsId <string>)))
                {
                    return(AsId <string> .New(soId.ObjectId.ToString()));
                }

                return(null);
            }));


            //pull from the store, which is empty.  it should factory the item up
            var item = store.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            //delete it
            store.DeleteItem(item.GetStoredObjectId());

            item = store.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            //cleanup
            store.Dispose();
        }))
        {
        }
コード例 #4
0
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var store = x.Intercepting(FileLoggerUtil.GetFileLogger("storeinttest.txt"));

            //build a commit interception that:
            //decorates the arg by appending the character A to the id
            //validates the arg by checking for the A
            store.CommitOperationIntercept.AddNextIntercept("intercept1",
                                                            (o) =>
            {
                CommitBag newBag = new CommitBag();
                var oldBag       = o;

                oldBag.ItemsToSave.WithEach(saveItem =>
                {
                    if (saveItem is AsId <string> )
                    {
                        var newItem = AsId <string> .New(saveItem.Id.ToString() + "A");
                        newBag.MarkItemSaved(newItem);
                    }
                });
                return(newBag);
            }, (o) =>
            {
                var oldBag = o;
                oldBag.ItemsToSave.WithEach(saveItem =>
                {
                    if (saveItem is AsId <string> )
                    {
                        var id = saveItem.Id.ToString();
                        Assert.True(id.EndsWith("A"));
                    }
                });
            }, null, null, null);

            var thing = AsId <string> .New("asId1");
            store.SaveItem(thing);

            //pull from the store, which is empty.  it should factory the item up
            var clone = store.Get <AsId <string> >("asId1A");
            Assert.True(clone != null);

            //TODO: test all intercepts, not just Commit

            store.Dispose();
        }))
        {
        }
コード例 #5
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var thing = AsId <string> .New("asId1");
            var soid  = thing.GetStoredObjectId();

            //build cache that polls every 5 seconds and always expires whatever is in it
            var store = x.Caching(NamedNaturalInMemoryStore.New("caching store").Evicting(NamedNaturalInMemoryStore.New("eviction condition store"), LogicOfTo <IHasId, IExpirable> .New((o) =>
            {
                return(NaturalTrueExpirable.New());   //.DecorateWithDateExpirable(DateTime.Now.AddSeconds(5000));
            }), 1000));
            var isEvicted = false;
            store.CachingStore.ItemEvicted += delegate(object sender, EventArgOf <Tuple <IHasId, IExpirable> > e)
            {
                isEvicted = true;
            };
            //save
            store.SaveItem(thing);
            Thread.Sleep(6000);
            //now pull from the store, itself (not the caching store) and it will repopulate the cache
            var item = store.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            //explicitly check the cache
            item = store.CachingStore.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            //wait 5 seconds, and check cache again
            Thread.Sleep(6000);
            item = store.CachingStore.Get <AsId <string> >("asId1");
            Assert.True(item == null);

            //now pull from the store, itself (not the caching store) and it will repopulate the cache
            item = store.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            item = store.CachingStore.Get <AsId <string> >("asId1");
            Assert.True(item != null);

            //cleanup
            store.Dispose();
        }))
        {
        }
コード例 #6
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();

            //create store that polls every 5 secs
            var store = x.Polls();
            store.SetBackgroundAction(LogicOf <IStore> .New((s) =>
            {
                //the poll action deletes all items in the store
                var items = s.GetAll();
                items.WithEach(item =>
                {
                    s.DeleteItem(item.GetStoredObjectId());
                });
            }), 5000);

            Thread.Sleep(6000);
            var thing = AsId <string> .New("asId1");
            store.SaveItem(thing);

            //pull from the store, which is empty.  it should factory the item up
            var clone = store.Get <AsId <string> >("asId1");
            Assert.True(clone != null);

            //wait 7 secs
            Thread.Sleep(7000);

            //now try to read it again - it should be gone
            clone = store.Get <AsId <string> >("asId1");
            Assert.True(clone == null);

            //try it again
            store.SaveItem(thing);

            //pull from the store, which is empty.  it should factory the item up
            clone = store.Get <AsId <string> >("asId1");
            Assert.True(clone != null);

            store.Dispose();
        })) { }
コード例 #7
0
 private DistributedId()
     : base(AsId <string> .New("distributedid").HasNewDateCreated().HasAutomaticGUID().HasLocalMachineName().HasLocalIP())
 {
 }
コード例 #8
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var thing = AsId <string> .New("asId1");
            var soid  = thing.GetStoredObjectId();

            //mask commit
            IStore store = x.NoCommit();

            Assert.Throws <InvalidOperationException>(() =>
            {
                store.SaveItem(thing);
            });

            //mask get
            store = x.NoGet();
            store.SaveItem(thing);

            Assert.Throws <InvalidOperationException>(() =>
            {
                store.Get <AsId <string> >("asId1");
            });

            //mask search
            store = x.NoSearch();
            store.SaveItem(thing);
            var itemCopy = store.Get <AsId <string> >("asId1");

            Assert.Throws <InvalidOperationException>(() =>
            {
                var list = store.SearchOf <AsId <string> >(LogicOfTo <AsId <string>, bool> .New((o) => { return(o.Id.Equals("asId1")); }));
            });

            //mask getall
            store = x.NoGetAll();
            store.SaveItem(thing);
            itemCopy = store.Get <AsId <string> >("asId1");

            Assert.Throws <InvalidOperationException>(() =>
            {
                var list = store.GetAll();
            });

            //mask all of them
            store = x.NoGetAll().NoCommit().NoGet().NoSearch();

            Assert.Throws <InvalidOperationException>(() =>
            {
                store.SaveItem(thing);
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                store.Get <AsId <string> >("asId1");
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                var list = store.SearchOf <AsId <string> >(LogicOfTo <AsId <string>, bool> .New((o) => { return(o.Id.Equals("asId1")); }));
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                var list = store.GetAll();
            });

            //cleanup
            x.DeleteItem(soid);
        }))
        {
        }
コード例 #9
0
ファイル: Tests.cs プロジェクト: Piirtaa/Decoratid
        public Test()
            : base(LogicOf <IStore> .New((x) =>
        {
            x.Clear();
            var thing         = AsId <string> .New("asId1");
            var filteredThing = AsId <string> .New("asId2_filtered");

            //1. test save events - don't save items with id's ending in "_filtered"
            var store = x.DecorateWithEvents(DebugLogger.New());

            store.CommitOperationIntercept.AddNextIntercept("intercept1", (o) =>
            {
                CommitBag newBag = new CommitBag();
                var oldBag       = o;
                oldBag.ItemsToSave.WithEach(saveItem =>
                {
                    string id = saveItem.Id.ToString();
                    if (id.EndsWith("_filtered"))
                    {
                        //don't add to new commitbag
                    }
                    else
                    {
                        newBag.MarkItemSaved(saveItem);
                    }
                });
                return(newBag);
            }
                                                            , null, null, null, null);

            //event flags
            bool saveFlag     = false;
            bool saveFiltFlag = false;
            store.ItemSaved  += (sender, e) =>
            {
                saveFlag = true;
            };
            store.ItemSavedFiltered += (sender, e) =>
            {
                saveFiltFlag = true;
            };

            store.SaveItem(thing);
            store.SaveItem(filteredThing);
            Assert.True(saveFiltFlag && saveFlag);
            store.Dispose();

            //2. test delete events - don't delete items with ids ending in "_filtered"
            store = x.DecorateWithEvents(DebugLogger.New());
            store.CommitOperationIntercept.AddNextIntercept("intercept1",
                                                            (o) =>
            {
                CommitBag newBag = new CommitBag();
                var oldBag       = o;

                oldBag.ItemsToDelete.WithEach(delItem =>
                {
                    string id = delItem.ObjectId.ToString();
                    if (id.EndsWith("_filtered"))
                    {
                        //don't add to new commitbag
                    }
                    else
                    {
                        newBag.MarkItemDeleted(delItem);
                    }
                });
                return(newBag);
            }, null, null, null, null);

            bool delFlag       = false;
            bool delFiltFlag   = false;
            store.ItemDeleted += (sender, e) =>
            {
                delFlag = true;
            };
            store.ItemDeletedFiltered += (sender, e) =>
            {
                delFiltFlag = true;
            };
            store.SaveItem(thing);
            store.SaveItem(filteredThing);
            store.DeleteItem(thing.GetStoredObjectId());
            store.DeleteItem(filteredThing.GetStoredObjectId());
            Assert.True(delFiltFlag && delFlag);
            store.Dispose();

            //3. test retrieve events - don't get items with ids ending in "_filtered"
            store = x.DecorateWithEvents(DebugLogger.New());

            //do get all first
            store.GetAllOperationIntercept.AddNextIntercept("intercept1", null, null, null,
                                                            (o) =>
            {
                List <IHasId> newList = new List <IHasId>();
                var oldList           = o;

                oldList.WithEach(item =>
                {
                    if (!item.Id.ToString().EndsWith("_filtered"))
                        newList.Add(item);
                });
                return(newList);
            }, null);
            bool retFlag         = false;
            bool retFiltFlag     = false;
            store.ItemRetrieved += (sender, e) =>
            {
                retFlag = true;
            };
            store.ItemRetrievedFiltered += (sender, e) =>
            {
                retFiltFlag = true;
            };

            store.SaveItem(thing);
            store.SaveItem(filteredThing);
            var items = store.GetAll();
            Assert.True(retFiltFlag && retFlag);

            //now test Search
            retFiltFlag = false;
            retFlag     = false;

            store.SearchOperationIntercept.AddNextIntercept("intercept2", null, null, null,
                                                            (o) =>
            {
                List <IHasId> newList = new List <IHasId>();
                var oldList           = o;

                oldList.WithEach(item =>
                {
                    if (!item.Id.ToString().EndsWith("_filtered"))
                        newList.Add(item);
                });
                return(newList);
            }, null);

            var filter     = LogicOfTo <AsId <string>, bool> .New((o) => { return(true); });
            var searchList = store.SearchOf <AsId <string> >(filter);
            Assert.True(retFiltFlag && retFlag);

            //now test get
            store.GetOperationIntercept.AddNextIntercept("intercept3", null, null, null,
                                                         (o) =>
            {
                IHasId newObj = null;
                IHasId oldObj = o;
                if (!oldObj.Id.ToString().EndsWith("_filtered"))
                    newObj = oldObj;
                return(newObj);
            }, null);

            retFiltFlag = false;
            retFlag     = false;
            store.Get(thing.GetStoredObjectId());
            store.Get(filteredThing.GetStoredObjectId());
            Assert.True(retFiltFlag && retFlag);
            store.Dispose();
        }))
        {
        }