コード例 #1
0
        public void Parent_and_child()
        {
            ObjectId hierarchyId;
            var      builder = new ChangeSetBuilder(objectFacade, null);
            {
                var hierarchy = builder.CreateHierarchy();
                hierarchyId = hierarchy.Id;
                var parentUnit = builder.CreateUnit("Parent", new Address("Lubicz", "23", "Krakow", "PL"));
                var childUnit  = builder.CreateUnit("Child", null);

                builder.SetHierarchyRoot(hierarchy, parentUnit);
                builder.SetParent(hierarchy, childUnit, parentUnit);
            }
            var view = objectFacade.GetSnapshot(builder.PendingChanges);
            {
                var hierarchy      = view.GetById <Hierarchy>(hierarchyId);
                var rootUnit       = hierarchy.RootUnit;
                var childUnits     = hierarchy.RootUnit.GetChildrenWithin(hierarchy);
                var firstChildUnit = childUnits.First();

                Assert.AreEqual("Parent", rootUnit.Name);
                Assert.AreEqual(new Address("Lubicz", "23", "Krakow", "PL"), rootUnit.Address);
                Assert.AreEqual("Child", firstChildUnit.Name);

                var allUnits = view.List <Unit>().ToList();
                Assert.AreEqual(2, allUnits.Count());
            }
        }
コード例 #2
0
        public void It_can_handle_1000_objects_with_10_changes_each()
        {
            var dataStore = new InMemoryDataStore();

            var objectIds = GenerateObjectIds(1000);

            ChangeSetId?previousChangeSetId = null;
            ChangeSetId currentChangeSetId  = ChangeSetId.NewUniqueId();

            dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateCreateCommands(objectIds)));
            previousChangeSetId = currentChangeSetId;

            for (int i = 0; i < 9; i++)
            {
                currentChangeSetId = ChangeSetId.NewUniqueId();
                dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateUpdateCommands(i, objectIds)));
                previousChangeSetId = currentChangeSetId;
            }

            var commandExecutor = new CommandExecutor()
                                  .RegisterCommandHandler(new CreateObjectCommandHandler())
                                  .RegisterCommandHandler(new ModifyAttributeCommandHandler());
            var objectTypeRepository = new ObjectTypeDescriptorRepository()
                                       .RegisterUsingReflection <TestingObject>();
            var dataFacade   = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory());
            var objectFacade = new ObjectFacade(dataFacade, objectTypeRepository, commandExecutor);

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var currentView = objectFacade.GetSnapshot(currentChangeSetId);
            var allObjects  = currentView.List <TestingObject>().ToList();

            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Assert.AreEqual(1000, allObjects.Count);
            foreach (var testingObject in allObjects)
            {
                Assert.AreEqual("8", testingObject.TextValue);
            }
        }
コード例 #3
0
        public void It_can_handle_1000_objects_with_10_changes_each()
        {
            var dataStore = new InMemoryDataStore();

            var objectIds = GenerateObjectIds(1000);

            ChangeSetId? previousChangeSetId = null;
            ChangeSetId currentChangeSetId = ChangeSetId.NewUniqueId();
            dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateCreateCommands(objectIds)));
            previousChangeSetId = currentChangeSetId;

            for (int i = 0; i < 9; i++)
            {
                currentChangeSetId = ChangeSetId.NewUniqueId();
                dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateUpdateCommands(i, objectIds)));
                previousChangeSetId = currentChangeSetId;
            }

            var commandExecutor = new CommandExecutor()
                .RegisterCommandHandler(new CreateObjectCommandHandler())
                .RegisterCommandHandler(new ModifyAttributeCommandHandler());
            var objectTypeRepository = new ObjectTypeDescriptorRepository()
                .RegisterUsingReflection<TestingObject>();
            var dataFacade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory());
            var objectFacade = new ObjectFacade(dataFacade, objectTypeRepository, commandExecutor);

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var currentView = objectFacade.GetSnapshot(currentChangeSetId);
            var allObjects = currentView.List<TestingObject>().ToList();
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Assert.AreEqual(1000, allObjects.Count);
            foreach (var testingObject in allObjects)
            {
                Assert.AreEqual("8", testingObject.TextValue);
            }
        }