Пример #1
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();
        }))
        {
        }
Пример #2
0
        public InterceptUnitOfWork(List <InterceptLayer <TArg, TResult> > layers, LogicOfTo <TArg, TResult> functionToIntercept, TArg arg)
        {
            Condition.Requires(layers).IsNotNull();
            Condition.Requires(functionToIntercept).IsNotNull();

            //if no logger is provided use an in memory store
            this.Logger = StoreLogger.New(NamedNaturalInMemoryStore.New("intercept log"));

            this.Layers = layers;
            this.FunctionToIntercept = functionToIntercept;
            this.Arg = arg;
        }
Пример #3
0
        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();
        }))
        {
        }
Пример #4
0
 public static IStore BuildMockStore()
 {
     return(NamedNaturalInMemoryStore.New("test store"));
 }