public void CanPublishFacts()
        {
            FactTreeMemento postTree = new FactTreeMemento(0);
            postTree.Add(new IdentifiedFactMemento(
                new FactID { key = 3961 },
                CreateDomain()));
            postTree.Add(new IdentifiedFactMemento(
                new FactID { key = 4979 },
                CreateRoom(3961)));
            _service.Post(ClientGuid1, "domain", postTree, new List<UnpublishMemento>());

            FactTreeMemento getTree = new FactTreeMemento(0);
            getTree.Add(new IdentifiedFactMemento(
                new FactID { key = 9898 },
                CreateDomain()));
            Dictionary<long, long> pivotIds = new Dictionary<long, long>();
            pivotIds[9898] = 0;
            var result = _service.GetManyAsync(ClientGuid2, "domain", getTree, pivotIds, 0).Result.Tree;

            Assert.AreEqual(2, result.Facts.Count());
            IdentifiedFactMemento resultDomain = (IdentifiedFactMemento)result.Facts.ElementAt(0);
            IdentifiedFactMemento resultRoom = (IdentifiedFactMemento)result.Facts.ElementAt(1);
            Assert.AreEqual(TypeDomain, resultDomain.Memento.FactType);
            Assert.IsFalse(resultDomain.Memento.Predecessors.Any());
            Assert.AreEqual(TypeRoom, resultRoom.Memento.FactType);
            Assert.AreEqual(resultDomain.Id, resultRoom.Memento.Predecessors.ElementAt(0).ID);
        }
        public async Task CanUnpublishFacts()
        {
            // There is a room published to the domain.
            long domainId = AddDomain();
            long roomId = AddRoom(domainId);

            // Client 1 unpublishes the room.
            FactTreeMemento tree = new FactTreeMemento(0);
            tree.Add(new IdentifiedFactMemento(
                new FactID { key = 3333 },
                CreateDomain()));
            tree.Add(new IdentifiedFactMemento(
                new FactID { key = 9879 },
                CreateRoom(3333)));
            _service.Post(ClientGuid1, "domain", tree,
                new List<UnpublishMemento>()
                {
                    new UnpublishMemento(new FactID { key = 9879 }, RoleRoomDomain)
                });

            // Client 2 subscribes to the domain.
            FactTreeMemento pivots = new FactTreeMemento(0);
            pivots.Add(new IdentifiedFactMemento(
                new FactID { key = 2222 },
                CreateDomain()));
            Dictionary<long, long> pivotIds = new Dictionary<long, long>()
            {
                { 2222, 0 }
            };
            var result = await _service.GetManyAsync(ClientGuid2, "domain", pivots, pivotIds, 0);

            // The room is conspicuously absent.
            Assert.AreEqual(0, result.Tree.Facts.Count());
        }
        public FactTreeMemento DeserializeFactTree(BinaryReader factReader)
        {
            long databaseId = BinaryHelper.ReadLong(factReader);
            FactTreeMemento factTreeMemento = new FactTreeMemento(databaseId);

            short factTypeCount = BinaryHelper.ReadShort(factReader);
            if (factTypeCount > MaxFactTypeCount)
                throw new CorrespondenceException("Maximum number of fact types exceeded.");
            for (short i = 0; i < factTypeCount; i++)
            {
                string typeName = BinaryHelper.ReadString(factReader);
                int version = BinaryHelper.ReadInt(factReader);
                _factTypes.Add(new CorrespondenceFactType(typeName, version));
            }

            short roleCount = BinaryHelper.ReadShort(factReader);
            if (roleCount > MaxRoleCount)
                throw new CorrespondenceException("Maximum number of roles exceeded.");
            for (short i = 0; i < roleCount; i++)
            {
                short factTypeId = BinaryHelper.ReadShort(factReader);
                string roleName = BinaryHelper.ReadString(factReader);
                _roles.Add(new RoleMemento(GetFactType(factTypeId), roleName, null, false));
            }

            short factCount = BinaryHelper.ReadShort(factReader);
            if (factCount > MaxFactCount)
                throw new CorrespondenceException("Maximum number of facts exceeded.");
            for (short i = 0; i < factCount; i++)
            {
                factTreeMemento.Add(DeserlializeFact(factReader));
            }
            return factTreeMemento;
        }
        private static FactTreeMemento CreateTreeWithSingleFact()
        {
            FactTreeMemento tree = new FactTreeMemento(0);

            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 42
            },
                         new FactMemento(new CorrespondenceFactType("TestModel.Domain", 1))));
            return(tree);
        }
 private void AddToFactTree(string domain, FactTreeMemento messageBody, FactID factId, Dictionary <FactID, FactID> localIdByRemoteId)
 {
     if (!messageBody.Contains(factId))
     {
         FactMemento fact = _repository.Load(domain, factId);
         foreach (PredecessorMemento predecessor in fact.Predecessors)
         {
             AddToFactTree(domain, messageBody, predecessor.ID, localIdByRemoteId);
         }
         messageBody.Add(new IdentifiedFactMemento(factId, fact));
     }
 }
Beispiel #6
0
        public void CanPublishFacts()
        {
            FactTreeMemento postTree = new FactTreeMemento(0);

            postTree.Add(new IdentifiedFactMemento(
                             new FactID {
                key = 3961
            },
                             CreateDomain()));
            postTree.Add(new IdentifiedFactMemento(
                             new FactID {
                key = 4979
            },
                             CreateRoom(3961)));
            _service.Post(ClientGuid1, "domain", postTree, new List <UnpublishMemento>());

            FactTreeMemento getTree = new FactTreeMemento(0);

            getTree.Add(new IdentifiedFactMemento(
                            new FactID {
                key = 9898
            },
                            CreateDomain()));
            Dictionary <long, long> pivotIds = new Dictionary <long, long>();

            pivotIds[9898] = 0;
            var result = _service.GetManyAsync(ClientGuid2, "domain", getTree, pivotIds, 0).Result.Tree;

            Assert.AreEqual(2, result.Facts.Count());
            IdentifiedFactMemento resultDomain = (IdentifiedFactMemento)result.Facts.ElementAt(0);
            IdentifiedFactMemento resultRoom   = (IdentifiedFactMemento)result.Facts.ElementAt(1);

            Assert.AreEqual(TypeDomain, resultDomain.Memento.FactType);
            Assert.IsFalse(resultDomain.Memento.Predecessors.Any());
            Assert.AreEqual(TypeRoom, resultRoom.Memento.FactType);
            Assert.AreEqual(resultDomain.Id, resultRoom.Memento.Predecessors.ElementAt(0).ID);
        }
        private Task <GetManyResult> GetFromClient1()
        {
            FactTreeMemento tree = new FactTreeMemento(0);

            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 4124
            },
                         CreateDomain()));
            Dictionary <long, long> pivotIds = new Dictionary <long, long>();

            pivotIds[4124] = 0;
            _service.Post(ClientGuid1, "domain", tree, new List <UnpublishMemento>());
            return(_service.GetManyAsync(ClientGuid1, "domain", tree, pivotIds, 1));
        }
Beispiel #8
0
        public async Task CanUnpublishFacts()
        {
            // There is a room published to the domain.
            long domainId = AddDomain();
            long roomId   = AddRoom(domainId);

            // Client 1 unpublishes the room.
            FactTreeMemento tree = new FactTreeMemento(0);

            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 3333
            },
                         CreateDomain()));
            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 9879
            },
                         CreateRoom(3333)));
            _service.Post(ClientGuid1, "domain", tree,
                          new List <UnpublishMemento>()
            {
                new UnpublishMemento(new FactID {
                    key = 9879
                }, RoleRoomDomain)
            });

            // Client 2 subscribes to the domain.
            FactTreeMemento pivots = new FactTreeMemento(0);

            pivots.Add(new IdentifiedFactMemento(
                           new FactID {
                key = 2222
            },
                           CreateDomain()));
            Dictionary <long, long> pivotIds = new Dictionary <long, long>()
            {
                { 2222, 0 }
            };
            var result = await _service.GetManyAsync(ClientGuid2, "domain", pivots, pivotIds, 0);

            // The room is conspicuously absent.
            Assert.AreEqual(0, result.Tree.Facts.Count());
        }
Beispiel #9
0
        public FactTreeMemento DeserializeFactTree(BinaryReader factReader)
        {
            long            databaseId      = BinaryHelper.ReadLong(factReader);
            FactTreeMemento factTreeMemento = new FactTreeMemento(databaseId);

            short factTypeCount = BinaryHelper.ReadShort(factReader);

            if (factTypeCount > MaxFactTypeCount)
            {
                throw new CorrespondenceException("Maximum number of fact types exceeded.");
            }
            for (short i = 0; i < factTypeCount; i++)
            {
                string typeName = BinaryHelper.ReadString(factReader);
                int    version  = BinaryHelper.ReadInt(factReader);
                _factTypes.Add(new CorrespondenceFactType(typeName, version));
            }

            short roleCount = BinaryHelper.ReadShort(factReader);

            if (roleCount > MaxRoleCount)
            {
                throw new CorrespondenceException("Maximum number of roles exceeded.");
            }
            for (short i = 0; i < roleCount; i++)
            {
                short  factTypeId = BinaryHelper.ReadShort(factReader);
                string roleName   = BinaryHelper.ReadString(factReader);
                _roles.Add(new RoleMemento(GetFactType(factTypeId), roleName, null, false));
            }

            short factCount = BinaryHelper.ReadShort(factReader);

            if (factCount > MaxFactCount)
            {
                throw new CorrespondenceException("Maximum number of facts exceeded.");
            }
            for (short i = 0; i < factCount; i++)
            {
                factTreeMemento.Add(DeserlializeFact(factReader));
            }
            return(factTreeMemento);
        }
Beispiel #10
0
        public void SkipsFactsAlreadyReceived()
        {
            long domainId = AddDomain();
            long roomId   = AddRoom(domainId);

            FactTreeMemento tree = new FactTreeMemento(0);

            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 4124
            },
                         CreateDomain()));
            Dictionary <long, long> pivotIds = new Dictionary <long, long>();

            pivotIds.Add(4124, roomId);

            var result = _service.GetManyAsync(Guid.Empty, "domain", tree, pivotIds, 0).Result.Tree;

            Assert.AreEqual(0, result.Facts.Count());
        }
        private static FactTreeMemento CreateTreeWithMultipleFacts()
        {
            FactTreeMemento tree = CreateTreeWithSingleFact();
            var             game = new FactMemento(
                new CorrespondenceFactType("TestModel.Game", 1))
                                   .AddPredecessor(
                CreateRoleDomain(),
                new FactID {
                key = 42
            },
                true);

            game.Data = new byte[] { 1, 2, 3, 4 };
            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 73
            },
                         game));
            return(tree);
        }
        public void CanGetPublishedFact()
        {
            long domainId = AddDomain();
            long roomId = AddRoom(domainId);

            FactTreeMemento tree = new FactTreeMemento(0);
            tree.Add(new IdentifiedFactMemento(
                new FactID { key = 4124 },
                new FactMemento(TypeDomain)));
            Dictionary<long, long> pivotIds = new Dictionary<long, long>();
            pivotIds.Add(4124, 0);

            var result = _service.GetManyAsync(ClientGuid1, "domain", tree, pivotIds, 0).Result.Tree;
            Assert.AreEqual(2, result.Facts.Count());
            IdentifiedFactMemento resultDomain = (IdentifiedFactMemento)result.Facts.ElementAt(0);
            IdentifiedFactMemento resultRoom = (IdentifiedFactMemento)result.Facts.ElementAt(1);
            Assert.AreEqual(TypeDomain, resultDomain.Memento.FactType);
            Assert.IsFalse(resultDomain.Memento.Predecessors.Any());
            Assert.AreEqual(TypeRoom, resultRoom.Memento.FactType);
            Assert.AreEqual(resultDomain.Id, resultRoom.Memento.Predecessors.ElementAt(0).ID);
            Assert.AreEqual(roomId, pivotIds[4124]);
        }
 private Task<GetManyResult> GetFromClient1()
 {
     FactTreeMemento tree = new FactTreeMemento(0);
     tree.Add(new IdentifiedFactMemento(
         new FactID { key = 4124 },
         CreateDomain()));
     Dictionary<long, long> pivotIds = new Dictionary<long, long>();
     pivotIds[4124] = 0;
     _service.Post(ClientGuid1, "domain", tree, new List<UnpublishMemento>());
     return _service.GetManyAsync(ClientGuid1, "domain", tree, pivotIds, 1);
 }
        public void SkipsFactsAlreadyReceived()
        {
            long domainId = AddDomain();
            long roomId = AddRoom(domainId);

            FactTreeMemento tree = new FactTreeMemento(0);
            tree.Add(new IdentifiedFactMemento(
                new FactID { key = 4124 },
                CreateDomain()));
            Dictionary<long, long> pivotIds = new Dictionary<long, long>();
            pivotIds.Add(4124, roomId);

            var result = _service.GetManyAsync(Guid.Empty, "domain", tree, pivotIds, 0).Result.Tree;
            Assert.AreEqual(0, result.Facts.Count());
        }
 private void AddToFactTree(string domain, FactTreeMemento messageBody, FactID factId, Dictionary<FactID, FactID> localIdByRemoteId)
 {
     if (!messageBody.Contains(factId))
     {
         FactMemento fact = _repository.Load(domain, factId);
         foreach (PredecessorMemento predecessor in fact.Predecessors)
             AddToFactTree(domain, messageBody, predecessor.ID, localIdByRemoteId);
         messageBody.Add(new IdentifiedFactMemento(factId, fact));
     }
 }
 private void PostFromClient2()
 {
     FactTreeMemento tree = new FactTreeMemento(0);
     tree.Add(new IdentifiedFactMemento(
         new FactID { key = 12 },
         CreateDomain()));
     tree.Add(new IdentifiedFactMemento(
         new FactID { key = 13 },
         CreateRoom(12)));
     _service.Post(ClientGuid2, "domain", tree, new List<UnpublishMemento>());
 }
        public void SkipsFactsToSourceClient()
        {
            FactTreeMemento postTree = new FactTreeMemento(0);
            postTree.Add(new IdentifiedFactMemento(
                new FactID { key = 3961 },
                CreateDomain()));
            postTree.Add(new IdentifiedFactMemento(
                new FactID { key = 4979 },
                CreateRoom(3961)));
            _service.Post(ClientGuid1, "domain", postTree, new List<UnpublishMemento>());

            FactTreeMemento getTree = new FactTreeMemento(0);
            getTree.Add(new IdentifiedFactMemento(
                new FactID { key = 9898 },
                CreateDomain()));
            Dictionary<long, long> pivotIds = new Dictionary<long, long>();
            pivotIds[9898] = 0;
            var result = _service.GetManyAsync(ClientGuid1, "domain", getTree, pivotIds, 0).Result.Tree;

            Assert.AreEqual(0, result.Facts.Count());
        }