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 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 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 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 Initialize() { // Quickly create a new domain named 'test' with its schema MyModelDefinition var domain = await StoreBuilder.CreateDomain <LibraryDefinition>("lib"); // Allow to omit the domain argument when you create a domain element. domain.Store.DefaultSessionConfiguration.DefaultDomainModel = domain; // Instanciate a new Library within the domain (always in a session) var rnd = new Random(); using (var session = domain.Store.BeginSession()) { Library = new Library(); Library.Name = "My library"; for (int i = 1; i < 20; i++) { var b = new Book(); b.Title = "Book " + i.ToString(); b.Copies = 1 + rnd.Next(10); Library.Books.Add(b); var m = new Member(); m.Name = "Member " + i.ToString(); Library.Members.Add(m); } session.AcceptChanges(); } }
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 CreateDefault() { var store = await StoreBuilder.New().CreateAsync(); Assert.NotNull(store.Services.Resolve <IHyperstore>()); store.Dispose(); }
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(); }
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(); }
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()); }
public void Build_returns_new_store_instance() { var builder = new StoreBuilder <AppState>(new AppReducer()); var store = builder.Build(); Assert.NotNull(store); }
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()); }
internal IKTable <KR, VR> BuildWindow <KR, VR>( string functionName, StoreBuilder <TimestampedWindowStore <K, VR> > storeBuilder, IKStreamAggProcessorSupplier <K, KR, V, VR> aggregateSupplier, string queryableStoreName, ISerDes <KR> keySerdes, ISerDes <VR> valueSerdes) { // if repartition required TODO // ELSE StatefulProcessorNode <K, V, TimestampedWindowStore <K, VR> > statefulProcessorNode = new StatefulProcessorNode <K, V, TimestampedWindowStore <K, VR> >( functionName, new ProcessorParameters <K, V>(aggregateSupplier, functionName), storeBuilder); builder.AddGraphNode(node, statefulProcessorNode); return(new KTableGrouped <K, KR, V, VR>(functionName, keySerdes, valueSerdes, sourceNodes, queryableStoreName, aggregateSupplier, statefulProcessorNode, builder)); }
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 }
// [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)); }
public void GivenStore_WhenDefaultPaymentMethodIsSet_ThenPaymentMethodIsAddedToCollectionPaymentMethods() { this.Session.Commit(); var netherlands = new Countries(this.Session).CountryByIsoCode["NL"]; var euro = netherlands.Currency; var bank = new BankBuilder(this.Session).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.Session) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build()) .Build(); var store = new StoreBuilder(this.Session) .WithName("Organisation store") .WithDefaultCarrier(new Carriers(this.Session).Fedex) .WithDefaultShipmentMethod(new ShipmentMethods(this.Session).Ground) .WithDefaultCollectionMethod(ownBankAccount) .Build(); this.Session.Derive(); Assert.Single(store.CollectionMethods); Assert.Equal(ownBankAccount, store.CollectionMethods.First); }
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(); } }
public List <string> Execute() { IExtensibleLogger logger = GroupEscalationGetterDiagnosticsFrameFactory.Default.CreateLogger(this.groupSession.MailboxGuid, this.groupSession.OrganizationId); IMailboxAssociationPerformanceTracker mailboxAssociationPerformanceTracker = GroupEscalationGetterDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); List <string> result; using (GroupEscalationGetterDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "EscalationGetter", logger, mailboxAssociationPerformanceTracker)) { StoreBuilder storeBuilder = new StoreBuilder(this.groupSession, XSOFactory.Default, logger, this.groupSession.ClientInfoString); using (IAssociationStore associationStore = storeBuilder.Create(this.group, mailboxAssociationPerformanceTracker)) { IEnumerable <IPropertyBag> associationsByType = associationStore.GetAssociationsByType("IPM.MailboxAssociation.User", MailboxAssociationBaseSchema.ShouldEscalate, EscalationGetter.EscalateProperties); List <string> list = new List <string>(); foreach (IPropertyBag propertyBag in associationsByType) { string text = propertyBag[MailboxAssociationBaseSchema.LegacyDN] as string; if (text != null) { list.Add(text); } else { EscalationGetter.Tracer.TraceError <string>((long)this.GetHashCode(), "EscalationGetter.Execute: Missing LegacyDn for item with Id {0}.", propertyBag[ItemSchema.Id].ToString()); } bool valueOrDefault = associationStore.GetValueOrDefault <bool>(propertyBag, MailboxAssociationBaseSchema.IsAutoSubscribed, false); if (valueOrDefault) { mailboxAssociationPerformanceTracker.IncrementAutoSubscribedMembers(); } } result = list; } } return(result); }
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); }
internal void AddGlobalStore <K, V, S>(string topicName, StoreBuilder <S> storeBuilder, string sourceName, ConsumedInternal <K, V> consumed, ProcessorParameters <K, V> processorParameters) where S : IStateStore { string processorName = processorParameters.ProcessorName; ValidateGlobalStoreArguments(sourceName, topicName, processorName, processorParameters.Processor, storeBuilder.Name, storeBuilder.LoggingEnabled); ValidateTopicNotAlreadyRegistered(topicName); var predecessors = new[] { sourceName }; var nodeFactory = new ProcessorNodeFactory <K, V>(processorName, predecessors, processorParameters.Processor); globalTopics.Add(topicName); nodeFactories.Add(sourceName, new SourceNodeFactory <K, V>(sourceName, topicName, consumed.TimestampExtractor, consumed.KeySerdes, consumed.ValueSerdes)); // TODO: ? // nodeToSourceTopics.put(sourceName, Arrays.asList(topics)); nodeGrouper.Add(sourceName); nodeFactory.AddStateStore(storeBuilder.Name); nodeFactories.Add(processorName, nodeFactory); nodeGrouper.Add(processorName); nodeGrouper.Unite(processorName, predecessors); globalStateBuilders.Add(storeBuilder.Name, storeBuilder); ConnectSourceStoreAndTopic(storeBuilder.Name, topicName); nodeGroups = null; }
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(); } }
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)); } }
static void Main(string[] args) { try { var factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); var store = new Store(factory, ConnectionString); var builder = new StoreBuilder(factory, ConnectionString, new MySqlProvider()); //builder.CreateTable<TypesRecord>(); builder.CreateIndex<TypesRecord>(x => x.Name); //builder.CreateIndex<TypesRecord>(x => x.Age); //builder.CreateIndex<TypesRecord>(x => x.DateOfBirth); var test = new TypesRecord { Age = 1337, DateOfBirth = new DateTime(2011, 10, 09, 08, 07, 6), Name = "Testing" }; store.Save(test); store.GetByProperty<TypesRecord>(x => x.Age, 21); } catch (Exception ex) { System.Console.WriteLine(ex); } System.Console.WriteLine("Done."); System.Console.ReadKey(); }
public StoreBuilder <TimestampedKeyValueStore <K, V> > Materialize() { KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier)materialized.StoreSupplier; if (supplier == null) { String name = materialized.StoreName; // TODO : RocksDB //supplier = Stores.persistentTimestampedKeyValueStore(name); supplier = new InMemoryKeyValueBytesStoreSupplier(name); } StoreBuilder <TimestampedKeyValueStore <K, V> > builder = Stores.TimestampedKeyValueStoreBuilder( supplier, materialized.KeySerdes, materialized.ValueSerdes); if (materialized.LoggingEnabled) { builder.WithLoggingEnabled(materialized.TopicConfig); } else { builder.WithLoggingDisabled(); } if (materialized.CachingEnabled) { builder.WithCachingEnabled(); } return(builder); }
public List <string> Execute() { IExtensibleLogger logger = MailboxAssociationDiagnosticsFrameFactory.Default.CreateLogger(this.groupSession.MailboxGuid, this.groupSession.OrganizationId); IMailboxAssociationPerformanceTracker performanceTracker = MailboxAssociationDiagnosticsFrameFactory.Default.CreatePerformanceTracker(null); List <string> result; using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "PinnersGetter", logger, performanceTracker)) { StoreBuilder storeBuilder = new StoreBuilder(this.groupSession, XSOFactory.Default, logger, this.groupSession.ClientInfoString); using (IAssociationStore associationStore = storeBuilder.Create(this.group, performanceTracker)) { IEnumerable <IPropertyBag> associationsByType = associationStore.GetAssociationsByType("IPM.MailboxAssociation.User", MailboxAssociationBaseSchema.IsPin, PinnersGetter.PinnerProperties); List <string> list = new List <string>(); foreach (IPropertyBag propertyBag in associationsByType) { string text = propertyBag[MailboxAssociationBaseSchema.LegacyDN] as string; if (text != null) { list.Add(text); } else { PinnersGetter.Tracer.TraceError <string>((long)this.GetHashCode(), "PinnersGetter.Execute: Missing LegacyDn for item with Id {0}.", propertyBag[ItemSchema.Id].ToString()); } } result = list; } } return(result); }
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(); } }
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 }
public StoreBuilder <ITimestampedKeyValueStore <K, V> > Materialize() { KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier)materialized.StoreSupplier; if (supplier == null) { supplier = Stores.DefaultKeyValueStore(materialized.StoreName); } StoreBuilder <ITimestampedKeyValueStore <K, V> > builder = Stores.TimestampedKeyValueStoreBuilder( supplier, materialized.KeySerdes, materialized.ValueSerdes); if (materialized.LoggingEnabled) { builder.WithLoggingEnabled(materialized.TopicConfig); } else { builder.WithLoggingDisabled(); } if (materialized.CachingEnabled) { builder.WithCachingEnabled(); } return(builder); }
static void Main(string[] args) { var serviceProvider = new BrowserServiceProvider(services => services.AddSingleton( StoreBuilder <SampleClientState> .Create() .WithInitialState( new SampleClientState { CurrentCount = 0, WeatherForecasts = null } ) .WithThunkMiddleWare() .WithSelector("CURRENTCOUNT", (state) => state.CurrentCount) .WithSelector("WEATHERFORECASTS", (state) => state.WeatherForecasts) .WithReducers <Increment>((state, action) => new SampleClientState { CurrentCount = state.CurrentCount + 1, WeatherForecasts = state.WeatherForecasts }) .WithReducers <WeatherForecast[]>((state, action) => new SampleClientState { CurrentCount = state.CurrentCount, WeatherForecasts = action }) .Build() ) ); new BrowserRenderer(serviceProvider).AddComponent <App>("app"); }
public void GivenStoreWithoutDefaultPaymentMethod_WhenSinglePaymentMethodIsAdded_ThenDefaultPaymentMethodIsSet() { Singleton.Instance(this.DatabaseSession).RemoveDefaultInternalOrganisation(); this.DatabaseSession.Commit(); var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"]; var euro = netherlands.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build()) .Build(); var store = new StoreBuilder(this.DatabaseSession) .WithName("Organisation store") .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithPaymentMethod(ownBankAccount) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(ownBankAccount, store.DefaultPaymentMethod); }
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); } }
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); }
public void GivenInternalOrganisationWithInvoiceSequenceFiscalYear_WhenCreatingInvoice_ThenInvoiceNumberFromFiscalYearMustBeUsed() { var store = new StoreBuilder(this.DatabaseSession).WithName("store") .WithDefaultFacility(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility")) .WithOwner(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .Build(); var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithStore(store) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); Assert.IsFalse(store.ExistSalesInvoiceCounter); Assert.AreEqual(DateTime.UtcNow.Year, store.FiscalYearInvoiceNumbers.First.FiscalYear); Assert.AreEqual("1", invoice1.InvoiceNumber); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithStore(store) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .Build(); Assert.IsFalse(store.ExistSalesInvoiceCounter); Assert.AreEqual(DateTime.UtcNow.Year, store.FiscalYearInvoiceNumbers.First.FiscalYear); Assert.AreEqual("2", invoice2.InvoiceNumber); }
public void GivenStore_WhenBuild_ThenPostBuildRelationsMustExist() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var store = new StoreBuilder(this.DatabaseSession) .WithName("Organisation store") .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, store.CreditLimit); Assert.AreEqual(0, store.PaymentGracePeriod); Assert.AreEqual(0, store.ShipmentThreshold); Assert.AreEqual(internalOrganisation, store.Owner); Assert.AreEqual(internalOrganisation.DefaultPaymentMethod, store.DefaultPaymentMethod); Assert.AreEqual(1, store.PaymentMethods.Count); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), store.DefaultFacility); }
public void GivenCustomerShipment_WhenGettingShipmentNumberWithoutFormat_ThenShipmentNumberShouldBeReturned() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var store = new StoreBuilder(this.DatabaseSession).WithName("store") .WithDefaultFacility(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility")) .WithOwner(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .Build(); var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipment1 = new CustomerShipmentBuilder(this.DatabaseSession) .WithShipToParty(new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build()) .WithShipToAddress(shipToAddress) .WithStore(store) .WithShipmentMethod(store.DefaultShipmentMethod) .Build(); Assert.AreEqual("1", shipment1.ShipmentNumber); var shipment2 = new CustomerShipmentBuilder(this.DatabaseSession) .WithShipToParty(new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build()) .WithStore(store) .WithShipmentMethod(store.DefaultShipmentMethod) .Build(); Assert.AreEqual("2", shipment2.ShipmentNumber); }
public void GivenSalesOrder_WhenGettingOrderNumberWithoutFormat_ThenOrderNumberShouldBeReturned() { var billToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build(); var shipToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person2").Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(billToCustomer).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(shipToCustomer).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var store = new StoreBuilder(this.DatabaseSession).WithName("store") .WithDefaultFacility(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility")) .WithOwner(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .Build(); this.DatabaseSession.Derive(true); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(billToCustomer) .WithShipToCustomer(shipToCustomer) .WithTakenByInternalOrganisation(internalOrganisation) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .WithStore(store) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual("1", order1.OrderNumber); var order2 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(billToCustomer) .WithShipToCustomer(shipToCustomer) .WithTakenByInternalOrganisation(internalOrganisation) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .WithStore(store) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual("2", order2.OrderNumber); }
public void GivenSalesInvoice_WhenGettingInvoiceNumberWithFormat_ThenFormattedInvoiceNumberShouldBeReturned() { var store = new StoreBuilder(this.DatabaseSession).WithName("store") .WithDefaultFacility(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility")) .WithOwner(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .WithSalesInvoiceNumberPrefix("the format is ") .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .Build(); var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithStore(store) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); Assert.AreEqual("the format is 1", invoice.InvoiceNumber); }
public void GivenStore_WhenDeriving_ThenRequiredRelationsMustExist() { var builder = new StoreBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithName("Organisation store"); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); builder.WithSalesInvoiceCounter( new CounterBuilder(this.DatabaseSession).Build() ).Build(); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); builder.WithFiscalYearInvoiceNumber(new FiscalYearInvoiceNumberBuilder(this.DatabaseSession).WithFiscalYear(DateTime.Today.Year).Build()); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); }