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); }
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); }
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); }
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); }
public async Task SetReferenceToNullFromOpposite2Test() { 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" }; new XReferencesY(x, y); s.AcceptChanges(); } var rel = x.GetRelationships <XReferencesY>().FirstOrDefault(); using (var s = store.BeginSession()) { y.X = null; // TODO Since it's an embedded relationship and y is the opposite, y is deleted. Is it the wright behavior ??? s.AcceptChanges(); } Assert.Equal(x.YRelation, null); Assert.Equal(x.GetRelationships <XReferencesY>().Count(), 0); using (var s = store.BeginSession()) { y = new YClass(dm) { Name = "1" }; new XReferencesY(x, y); s.AcceptChanges(); } rel = x.GetRelationships <XReferencesY>().FirstOrDefault(); using (var s = store.BeginSession()) { x.YRelation = null; s.AcceptChanges(); } Assert.Equal(x.YRelation, null); Assert.Equal(((IModelElement)y).Status, ModelElementStatus.Disposed); Assert.Equal(x.GetRelationships <XReferencesY>().Count(), 0); }
public async Task SetReferenceTest() { 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(); } Assert.Equal(x.YRelation, y); Assert.Equal(x.YRelation.X, x); Assert.Equal(y.X, x); var rel = x.GetRelationships <XReferencesY>().FirstOrDefault(); Assert.Equal(rel.Start, x); Assert.Equal(rel.End, y); using (var s = store.BeginSession()) { y = new YClass(dm) { Name = "2" }; x.YRelation = y; s.AcceptChanges(); } Assert.Equal(x.YRelation, y); Assert.Equal(x.YRelation.X, x); Assert.Equal(x.GetRelationships <XReferencesY>().Count(), 1); rel = x.GetRelationships <XReferencesY>().FirstOrDefault(); Assert.Equal(rel.Start, x); Assert.Equal(rel.End, y); }
public async Task ReferenceInRelationshipTest() { var store = await StoreBuilder.New().CreateAsync(); var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync(); var dm = await store.DomainModels.New().CreateAsync("Test"); XReferencesY rel = null; using (var s = store.BeginSession()) { var start = new XExtendsBaseClass(dm); var end = new YClass(dm); rel = new XReferencesY(start, end); rel.YRelation = end; s.AcceptChanges(); } Assert.NotNull(rel); Assert.NotNull(rel.YRelation); }
public async Task RelationshipConstraintTest() { var store = await StoreBuilder.New().CreateAsync(); var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync(); var domain = await store.DomainModels.New().CreateAsync("Test"); schema.Definition.XReferencesY.AddImplicitConstraint(r => r.Weight > 0, "error").Register(); Assert.Throws <SessionException>( () => { XReferencesY rel = null; using (var s = store.BeginSession()) { var start = new XExtendsBaseClass(domain); var end = new YClass(domain); rel = new XReferencesY(start, end); rel.YRelation = end; s.AcceptChanges(); } }); }