public async Task AcquireExclusive2Test()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var factory = new TaskFactory();

            var tasks = new Task[2];

            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = factory.StartNew(() =>
                {
                    using (var s = store.BeginSession(new SessionConfiguration {
                        IsolationLevel = SessionIsolationLevel.ReadCommitted
                    }))
                    {
                        s.AcquireLock(LockType.ExclusiveWait, "a");
                        Sleep(100);

                        s.AcceptChanges();
                    }
                });
            }

            Task.WaitAll(tasks);
#if TEST
            Assert.True(((LockManager)((IStore)store).LockManager).IsEmpty());
#endif
        }
        public async Task RollbackUpdateTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var provider = new TransactionalMemoryStore(domain);

            using (var s = store.BeginSession(new SessionConfiguration {
                IsolationLevel = SessionIsolationLevel.ReadCommitted
            }))
            {
                provider.AddNode(new Data("1", 10));
                s.AcceptChanges();
            }

            using (var s = store.BeginSession(new SessionConfiguration {
                IsolationLevel = SessionIsolationLevel.ReadCommitted
            }))
            {
                provider.UpdateNode(new Data("1", 20));
            }
            using (var s = store.BeginSession(new SessionConfiguration {
                IsolationLevel = SessionIsolationLevel.ReadCommitted
            }))
            {
                Assert.Equal(((Data)provider.GetNode(new Identity("test", "1"))).Value, 10);
                s.AcceptChanges();
            }
        }
Exemplo n.º 3
0
        public async Task DefineEnumPropertyTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test") as IUpdatableDomainModel;

            using (var s = store.BeginSession())
            {
                ISchemaElement metadata = schema.Definition.XExtendsBaseClass;
                var            e        = new Hyperstore.Modeling.Metadata.Primitives.EnumPrimitive(schema, typeof(ETest));
                var            prop     = metadata.DefineProperty <ETest>("enum");

                IModelElement a = new XExtendsBaseClass(domain);

                var pv = domain.GetPropertyValue(a.Id, prop);
                Assert.Equal(0, pv.CurrentVersion);
                Assert.Equal(ETest.A, pv.Value);

                domain.SetPropertyValue(a, prop, ETest.B);
                pv = domain.GetPropertyValue(a.Id, prop);
                Assert.NotEqual(0, pv.CurrentVersion);
                Assert.Equal(ETest.B, pv.Value);
                s.AcceptChanges();
            }
        }
Exemplo n.º 4
0
        public async Task EmbeddedRelationship()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <LibraryDefinition>().CreateAsync();

            var dm = await store.DomainModels.New().CreateAsync("Test");

            Library lib;
            Book    b;

            using (var s = store.BeginSession())
            {
                lib      = new Library(dm);
                lib.Name = "Library";

                b        = new Book(dm);
                b.Title  = "book";
                b.Copies = 1;

                lib.Books.Add(b);
                s.AcceptChanges();
            }

            using (var s = store.BeginSession())
            {
                lib.Books.Remove(b);
                s.AcceptChanges();
            }

            Assert.Null(dm.GetElement <Book>(((IModelElement)b).Id));
            Assert.Equal(0, lib.Books.Count());
        }
Exemplo n.º 5
0
        // [Fact]
        public async Task BenchWithConstraints()
        {
            long nb = 0;
            store = await StoreBuilder.New().CreateAsync();
            schema = await store.Schemas.New<TestDomainDefinition>().CreateAsync();
            var domain = await store.DomainModels.New().CreateAsync("Test");
            var sw = new Stopwatch();

            // Ajout de 100 contraintes
            var nbc = 100;
            for (int i = 0; i < nbc; i++)
                schema.Definition.XExtendsBaseClass.AddImplicitConstraint(
                    self =>
                        System.Threading.Interlocked.Increment(ref nb) > 0,
                    "OK");

            sw.Start();
            var mx = 10000;
            AddElement(domain, mx);
            UpdateElement(mx);
            ReadElement(mx);
            RemoveElement(mx);
            sw.Stop();

            Assert.Equal(mx * nbc * 2, nb); // Nbre de fois la contrainte est appelée (sur le add et le update)
            Assert.True(sw.ElapsedMilliseconds < 4000, String.Format("ElapsedTime = {0}", sw.ElapsedMilliseconds));
        }
Exemplo n.º 6
0
        public async Task UndoWithEnum()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var undoManager = new UndoManager(store);

            undoManager.RegisterDomain(domain);

            YClass y;

            using (var s = store.BeginSession())
            {
                y = new YClass(domain);
                s.AcceptChanges();
            }

            using (var s = store.BeginSession())
            {
                y.Direction = Model.Direction.West;
                s.AcceptChanges();
            }

            undoManager.Undo();
            Assert.Equal(Model.Direction.South, y.Direction);

            undoManager.Redo();
            Assert.Equal(Model.Direction.West, y.Direction);
        }
Exemplo n.º 7
0
        public async Task RegisterMany()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var r1 = store.Services;

            r1.Register <IService>(new Service());
            r1.Register <IService>(new Service());

            Assert.Equal(2, r1.ResolveAll <IService>().Count());
            Assert.Equal(2, r1.Resolve <IService>().Id);

            Assert.Equal(2, r1.ResolveAll <IService>().First().Id);
            Assert.Equal(1, r1.ResolveAll <IService>().Last().Id);

            var r2 = r1.NewScope();

            r2.Register <IService>(new Service());

            Assert.Equal(3, r2.ResolveAll <IService>().Count());
            Assert.Equal(3, r2.Resolve <IService>().Id);

            Assert.Equal(3, r2.ResolveAll <IService>().First().Id); // D'abord ceux de r2
            Assert.Equal(1, r2.ResolveAll <IService>().Last().Id);  // puis ceux de r1
            r2.Dispose();
            r1.Dispose();
        }
Exemplo n.º 8
0
        public async Task ImplicitConstraint()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            schema.Definition.XExtendsBaseClass.AddImplicitConstraint(self =>
                                                                      self.Name == "momo"
                                                                      , "Not null").Register();

            try
            {
                using (var s = domain.Store.BeginSession())
                {
                    var a = new XExtendsBaseClass(domain);
                    a.Name = "mama";
                    s.AcceptChanges();
                }

                throw new Exception("Inconclusive");
            }
            catch (SessionException ex)
            {
                Assert.True(ex.Messages.Count() == 1);
            }
        }
Exemplo n.º 9
0
        public async Task Extension_constraint_in_readonly_mode()
        {
            var store = await StoreBuilder.New().EnableScoping().CreateAsync();

            var schema = await store.Schemas.New <InitialDomainDefinition>().CreateAsync();

            var initial = await store.DomainModels.New().CreateAsync("D1");

            store.GetSchemaEntity <Category>().AddImplicitConstraint <Category>(c => c.Value < 10, "Invalid value");

            Category cat;

            using (var s = store.BeginSession())
            {
                cat       = new Category(initial);
                cat.Value = 1;
                s.AcceptChanges();
            }

            await schema.LoadSchemaExtension(new ExtensionsDomainDefinition(), SchemaConstraintExtensionMode.Replace);

            var extended = await initial.CreateScopeAsync("Ex1");

            CategoryEx catx;

            using (var s = store.BeginSession())
            {
                catx       = store.GetElement <CategoryEx>(((IModelElement)cat).Id);
                catx.Value = 10; // Pas d'erreur car la contrainte ne s'applique pas
                s.AcceptChanges();
            }
        }
Exemplo n.º 10
0
        public async Task RegisterByDomain()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var r1 = store.Services;

            r1.Register <IService>(services => new Service());

            Assert.Equal(1, r1.Resolve <IService>().Id);
            Assert.Equal(1, r1.Resolve <IService>().Id);
            Assert.Equal(1, r1.Resolve <IService>().Id);
            Assert.Equal(1, r1.Resolve <IService>().Id);

            var r2 = r1.NewScope();

            Assert.Equal(2, r2.Resolve <IService>().Id);
            Assert.Equal(2, r2.Resolve <IService>().Id);

            Assert.Equal(2, r2.Resolve <IService>().Id);
            Assert.Equal(2, r2.Resolve <IService>().Id);

            var r3 = r1.NewScope();

            Assert.Equal(3, r3.Resolve <IService>().Id);
            Assert.Equal(3, r3.Resolve <IService>().Id);

            Assert.Equal(3, r3.Resolve <IService>().Id);
            Assert.Equal(3, r3.Resolve <IService>().Id);
            r3.Dispose();
            r2.Dispose();
            r1.Dispose();
        }
Exemplo n.º 11
0
        public async Task Serialization()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <LibraryDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            Library lib;

            using (var session = store.BeginSession())
            {
                lib      = new Library(domain);
                lib.Name = "Lib1";
                for (int i = 0; i < 5; i++)
                {
                    var b = new Book(domain);
                    b.Title  = "Book \"book\" " + i.ToString();
                    b.Copies = i + 1;
                    lib.Books.Add(b);

                    var m = new Member(domain);
                    m.Name = "Book " + i.ToString();
                    lib.Members.Add(m);
                }
                session.AcceptChanges();
            }


            var text = Hyperstore.Modeling.Serialization.HyperstoreSerializer.Serialize(domain);

            Assert.Equal(11, domain.GetEntities().Count());
            Assert.Equal(10, domain.GetRelationships().Count());

            var store2 = await StoreBuilder.New().CreateAsync();

            await store2.Schemas.New <LibraryDefinition>().CreateAsync();

            var domain2 = await store2.DomainModels.New().CreateAsync("Test");

            using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(text)))
            {
                Hyperstore.Modeling.Serialization.XmlDeserializer.Deserialize(reader, domain2);
            }

            Assert.Equal(11, domain2.GetEntities().Count());
            Assert.Equal(10, domain2.GetRelationships().Count());

            foreach (var book2 in domain2.GetEntities <Book>())
            {
                var book = domain.GetEntity <Book>(((IModelElement)book2).Id);
                Assert.NotNull(book);
                Assert.Equal(book.Title, book2.Title);
                Assert.Equal(book.Copies, book2.Copies);
            }

            lib = domain2.GetEntities <Library>().FirstOrDefault();
            Assert.NotNull(lib);
            Assert.Equal(5, lib.Books.Count());
        }
Exemplo n.º 12
0
        public async Task JsonSerialization()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <LibraryDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            Library lib;

            using (var session = store.BeginSession())
            {
                lib      = new Library(domain);
                lib.Name = "Lib1";
                for (int i = 0; i < 1; i++)
                {
                    var b = new Book(domain);
                    b.Title  = "Book \"book\" " + i.ToString();
                    b.Copies = i + 1;
                    lib.Books.Add(b);

                    var m = new Member(domain);
                    m.Name = "Book " + i.ToString();
                    lib.Members.Add(m);
                }
                session.AcceptChanges();
            }

            var text = Hyperstore.Modeling.Serialization.HyperstoreSerializer.Serialize(domain, new SerializationSettings {
                Options = SerializationOptions.Json | SerializationOptions.CompressSchema
            });

            Assert.NotNull(text);
            Newtonsoft.Json.JsonConvert.DeserializeObject(text);
        }
Exemplo n.º 13
0
        public async Task AddInterceptorTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            int cx = 0;

            domain.Commands.RegisterInterceptor(new SharedInterceptor(() => { cx = 1; }), 1);

            using (var s = store.BeginSession())
            {
                s.Execute(new MyCommand(domain));
                s.AcceptChanges();
            }
            Assert.Equal(1, cx);
            domain.Commands.RegisterInterceptor(new MyInterceptor(() => { cx = 2; }));

            using (var s = store.BeginSession())
            {
                s.Execute(new MyCommand(domain));
                s.AcceptChanges();
            }

            Assert.Equal(2, cx);
        }
Exemplo n.º 14
0
        public async Task RemoveFromIndex()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var graph = domain.Resolve <IHyperGraph>() as Hyperstore.Modeling.HyperGraph.HyperGraph;
            MemoryIndexManager manager = graph.IndexManager as MemoryIndexManager;

            manager.CreateIndex(schema.Definition.XExtendsBaseClass, "index1", true, "Name");

            var index = manager.GetIndex("index1");
            var id    = new Identity("Test", "1");

            using (var session = store.BeginSession(new SessionConfiguration {
                Readonly = true
            }))
            {
                manager.AddToIndex(schema.Definition.XExtendsBaseClass, "index1", id, "momo");
                Assert.Equal(id, index.Get("momo"));
                manager.RemoveFromIndex(schema.Definition.XExtendsBaseClass, "index1", id, "momo");
                Assert.Null(index.Get("momo"));
            }
        }
Exemplo n.º 15
0
        public async Task CreateDefault()
        {
            var store = await StoreBuilder.New().CreateAsync();

            Assert.NotNull(store.Services.Resolve <IHyperstore>());
            store.Dispose();
        }
Exemplo n.º 16
0
        public async Task Contraint_Error_Notification()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            schema.Definition.XExtendsBaseClass.AddImplicitConstraint(self => self.Name != null, "Not null").Register();
            bool sawError = false;

            domain.Events.OnErrors.Subscribe(m => { sawError = true; });

            try
            {
                using (var s = domain.Store.BeginSession())
                {
                    var a = new XExtendsBaseClass(domain);
                    s.AcceptChanges();
                }

                throw new Exception("Inconclusive");
            }
            catch (SessionException ex)
            {
                Assert.True(ex.Messages.Count() == 1);
            }
            Assert.Equal(true, sawError);
        }
Exemplo n.º 17
0
        public async Task AddInTransaction()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            domain.Indexes.CreateIndex(schema.Definition.XExtendsBaseClass, "index1", true, "Name");
            var index = domain.Indexes.GetIndex("index1");

            using (var s = domain.Store.BeginSession())
            {
                dynamic a = new DynamicModelEntity(domain, schema.Definition.XExtendsBaseClass);
                a.Name = "momo";
                s.AcceptChanges();
                // Est visible dans la transaction
                Assert.NotNull(domain.GetElement(index.Get("momo")));
            }

            using (var session = domain.Store.BeginSession(new SessionConfiguration {
                Readonly = true
            }))
            {
                Assert.NotNull(domain.GetElement(index.Get("momo")));
            }
        }
        public async Task CompareModels()
        {
            var store = await StoreBuilder.New().EnableScoping().Using <IIdGenerator>(r => new Hyperstore.Modeling.Domain.LongIdGenerator()).CreateAsync();

            await store.Schemas.New <LibraryDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            using (var session = store.BeginSession())
            {
                var lib = new Library(domain);
                lib.Name = "Lib1";
                for (int i = 0; i < 3; i++)
                {
                    var b = new Book(domain);
                    b.Title  = "Book \"book\" " + i.ToString();
                    b.Copies = i + 1;
                    lib.Books.Add(b);

                    var m = new Member(domain);
                    m.Name = "Book " + i.ToString();
                    lib.Members.Add(m);
                }
                session.AcceptChanges();
            }

            var domain2 = await domain.CreateScopeAsync("domain2");

            Library lib2 = null;

            using (var session = store.BeginSession())
            {
                lib2 = domain2.GetEntities <Library>().First();

                // Remove 1 book
                var book = lib2.Books.First();
                lib2.Books.Remove(book);

                // Add 2 books
                var b = new Book(domain2);
                b.Title  = "New book 1";
                b.Copies = 1;
                lib2.Books.Add(b);

                b        = new Book(domain2);
                b.Title  = "New book 2";
                b.Copies = 2;
                lib2.Books.Add(b);

                // Change one book property
                lib2.Books.Last().Title = "Updated book";

                session.AcceptChanges();
            }

            Assert.Equal(2, domain2.GetDeletedElements().Count());
            Assert.Equal(4, lib2.Books.Count());
            Assert.Equal(6, domain2.GetScopeElements().Count());     // Books : 2 created, 1 updated, Library : 1 updated (Books property), LibraryHasBooks : 2 created
            Assert.Equal(5, domain2.GetUpdatedProperties().Count()); // New Books * 2 + 1 in the extendee domain
        }
Exemplo n.º 19
0
        public async Task PropertyChangedOnSetReferenceTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var dm = await store.DomainModels.New().UsingIdGenerator(r => new LongIdGenerator()).CreateAsync("Test");

            XExtendsBaseClass x = null;
            YClass            y = null;

            var yrelationChanges   = 0;
            var allPropertychanges = 0;

            using (var s = store.BeginSession())
            {
                x = new XExtendsBaseClass(dm);
                s.AcceptChanges();
            }

            x.PropertyChanged += (sender, e) =>
            {
                allPropertychanges++;
                if (e.PropertyName == "YRelation")
                {
                    yrelationChanges++;
                }
            };

            using (var s = store.BeginSession())
            {
                y = new YClass(dm)
                {
                    Name = "1"
                };
                x.YRelation = y;
                s.AcceptChanges();
            }

            using (var s = store.BeginSession())
            {
                y = new YClass(dm)
                {
                    Name = "2"
                };
                x.YRelation = y;
                s.AcceptChanges();
            }

            var rel = x.GetRelationships <XReferencesY>().FirstOrDefault();

            using (var s = store.BeginSession())
            {
                x.YRelation = null;
                s.AcceptChanges();
            }

            Assert.Equal(3, yrelationChanges);
            Assert.Equal(3, allPropertychanges);
        }
Exemplo n.º 20
0
        public async Task AddElementTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var Graph = domain.Resolve <IHyperGraph>();
            var aid   = Id(1);

            using (var session = domain.Store.BeginSession())
            {
                Graph.CreateEntity(aid, store.PrimitivesSchema.SchemaEntitySchema);

                Assert.NotNull(Graph.GetElement(aid));
                session.AcceptChanges();
            }
            using (var session = domain.Store.BeginSession(new SessionConfiguration {
                Readonly = true
            }))
            {
                Assert.NotNull(Graph.GetElement(aid));
            }
        }
Exemplo n.º 21
0
        public async Task SetReferenceToNullFromOppositeTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var dm = await store.DomainModels.New().CreateAsync("Test");

            XExtendsBaseClass x = null;
            YClass            y = null;

            using (var s = store.BeginSession())
            {
                x = new XExtendsBaseClass(dm);
                y = new YClass(dm)
                {
                    Name = "1"
                };
                x.YRelation = y;
                s.AcceptChanges();
            }

            var rel = x.GetRelationships <XReferencesY>().FirstOrDefault();

            using (var s = store.BeginSession())
            {
                y.X = null;
                s.AcceptChanges();
            }

            Assert.Equal(x.YRelation, null);
            Assert.Equal(((IModelElement)y).Status, ModelElementStatus.Disposed);
            Assert.Equal(x.GetRelationships <XReferencesY>().Count(), 0);
        }
Exemplo n.º 22
0
        public async Task CalculatedPropertyTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var dm = await store.DomainModels.New().CreateAsync("Test");

            XExtendsBaseClass start = null;

            using (var s = store.BeginSession())
            {
                start = new XExtendsBaseClass(dm);
                Assert.Equal(0, start.CalculatedValue);
                s.AcceptChanges();
            }

            bool flag = false;

            start.PropertyChanged += (sender, e) => { if (e.PropertyName == "CalculatedValue")
                                                      {
                                                          flag = true;
                                                      }
            };

            using (var s = store.BeginSession())
            {
                start.Value = 10;
                s.AcceptChanges();
            }

            Assert.True(flag);
            Assert.Equal(50, start.CalculatedValue);
        }
Exemplo n.º 23
0
        public async Task DisposedTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().UsingIdGenerator(r => new Hyperstore.Modeling.Domain.LongIdGenerator()).CreateAsync("Test");

            XReferencesY rel = null;

            using (var session = store.BeginSession())
            {
                var lockX = session.AcquireLock(LockType.Shared, "X");
                // Upgrade lock type to Exclusive
                lockX = session.AcquireLock(LockType.Exclusive, "X");

                var lockY = session.AcquireLock(LockType.Exclusive, "Y");

                lockX.Dispose(); // Release lockX
            } // Release lockY

            using (var s = store.BeginSession())
            {
                var start  = new XExtendsBaseClass(domain);
                var start2 = new XExtendsBaseClass(domain);
                start.OthersX.Add(start2);
                var end = new YClass(domain);
                rel = new XReferencesY(start, end);
                s.AcceptChanges();
            }

            Assert.NotNull(rel);
        }
Exemplo n.º 24
0
        public async Task SerializableTransactionTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            Identity aid;
            dynamic  a;

            using (var s = store.BeginSession(new SessionConfiguration {
                IsolationLevel = SessionIsolationLevel.ReadCommitted
            }))
            {
                a       = new DynamicModelEntity(domain, schema.Definition.XExtendsBaseClass);
                aid     = a.Id;
                a.Value = 10;
                s.AcceptChanges();
            }

            var factory = new TaskFactory();
            var signal  = new System.Threading.ManualResetEventSlim();
            var signal2 = new System.Threading.ManualResetEventSlim();

            var t1 = factory.StartNew(() =>
            {
                using (var s = store.BeginSession(new SessionConfiguration {
                    IsolationLevel = SessionIsolationLevel.Serializable
                }))
                {
                    // Accès sur A pour ouvrir une transaction Serializable (la session ne fait rien). Ce n'est que qu'en on
                    // accède à la donnée que la transaction est crèèe
                    var x = a.Value; // Ou n'importe quoi
                    signal2.Set();
                    signal.Wait();
                    Assert.Equal(a.Value, 10); // On ne "voit" pas les modifications des autres transactions
                }
            });

            Sleep(50);

            var t2 = factory.StartNew(() =>
            {
                signal2.Wait();
                using (var s = store.BeginSession(new SessionConfiguration {
                    IsolationLevel = SessionIsolationLevel.ReadCommitted
                }))
                {
                    a.Value = 11;
                    s.AcceptChanges();
                }
                signal.Set();
            });

            Task.WaitAll(t1, t2);
        }
Exemplo n.º 25
0
        public async Task SchemaEvents()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var def    = new MySchemaDefinition();
            var schema = await store.Schemas.New(def).CreateAsync();

            Assert.True(def.IsSchemaLoaded);
        }
Exemplo n.º 26
0
        public async Task ReadPhantomTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            Identity aid;
            dynamic  a;

            // Création d'une valeur
            using (var s = store.BeginSession(new SessionConfiguration {
                IsolationLevel = SessionIsolationLevel.ReadCommitted
            }))
            {
                a       = new DynamicModelEntity(domain, schema.Definition.XExtendsBaseClass);
                aid     = a.Id;
                a.Value = 10;
                s.AcceptChanges();
            }

            var factory = new TaskFactory();
            var signal  = new System.Threading.ManualResetEventSlim();
            var signal2 = new System.Threading.ManualResetEventSlim();

            var t1 = factory.StartNew(() =>
            {
                // Cette transaction démarre avant l'autre mais elle va pouvoir 'voir' ses modifs commités
                using (var s = store.BeginSession(new SessionConfiguration {
                    IsolationLevel = SessionIsolationLevel.ReadCommitted
                }))
                {
                    signal2.Set();
                    signal.Wait();             // On attend le commit de l'autre
                    Assert.Equal(11, a.Value); // On "voit" dèja que la valeur a été modifiée
                }
            });

            Sleep(50);

            var t2 = factory.StartNew(() =>
            {
                signal2.Wait(); // On s'assure de démarrer aprés l'autre transaction
                using (var s = store.BeginSession(new SessionConfiguration {
                    IsolationLevel = SessionIsolationLevel.ReadCommitted
                }))
                {
                    a.Value = 11;
                    s.AcceptChanges();
                }
                signal.Set();
            });

            Task.WaitAll(t1, t2);
        }
Exemplo n.º 27
0
        public async Task DoubleTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var          dt = 10.2;
            IDomainModel dm = await store.DomainModels.New().CreateAsync("Test");

            Assert.Equal(dt, (Double)store.PrimitivesSchema.DoubleSchema.Deserialize(new SerializationContext(store.PrimitivesSchema.DoubleSchema, store.PrimitivesSchema.DoubleSchema.Serialize(dt))));
            Assert.Null(store.PrimitivesSchema.DoubleSchema.Serialize(null));
        }
Exemplo n.º 28
0
        public async Task TimeSpanTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var          dt = DateTime.Now.TimeOfDay;
            IDomainModel dm = await store.DomainModels.New().CreateAsync("Test");

            Assert.Equal((TimeSpan)store.PrimitivesSchema.TimeSpanSchema.Deserialize(new SerializationContext(store.PrimitivesSchema.TimeSpanSchema, store.PrimitivesSchema.TimeSpanSchema.Serialize(dt))), dt);
            Assert.Null(store.PrimitivesSchema.TimeSpanSchema.Serialize(null));
        }
Exemplo n.º 29
0
        public async Task FloatTest()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var          dt = 10.2;
            IDomainModel dm = await store.DomainModels.New().CreateAsync("Test");

            Assert.True((Single)store.PrimitivesSchema.SingleSchema.Deserialize(new SerializationContext(store.PrimitivesSchema.SingleSchema, store.PrimitivesSchema.SingleSchema.Serialize(dt))) - dt < 0.01);
            Assert.Null(store.PrimitivesSchema.SingleSchema.Serialize(null));
        }
Exemplo n.º 30
0
 public async Task UnknowMetadata_raises_exception()
 {
     await Assert.ThrowsAsync <MetadataNotFoundException>(async() =>
     {
         var store    = await StoreBuilder.New().CreateAsync();
         var schema   = await store.Schemas.New <TestDomainDefinition>().CreateAsync();
         var domain   = await store.DomainModels.New().CreateAsync("Test");
         var metadata = schema.GetSchemaInfo("Z");
     });
 }