示例#1
0
        public void TestAddSession()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                var node = new Node("notion", notionType);
                GetRepository <Node>().AddOrUpdate(node);

                unitOfWork.Commit();
            }

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var session = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(session);

                var node = LinqProvider.Query <Node>().Single();
                node.AddSessionOfExperts(session);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var node = LinqProvider.Query <Node>().Single();

                node.SessionsOfExperts.Count.Should().Be(1);
            }
        }
示例#2
0
        private Node GetOrCreateNode(
            [NotNull] string notion,
            [NotNull] NotionType type,
            [NotNull] SessionOfExperts sessionOfExperts)
        {
            var node = _nodeRepository.GetByNotionAndType(notion, type) ?? new Node(notion, type);

            node.AddSessionOfExperts(sessionOfExperts);

            return(node);
        }
示例#3
0
        private void Seed()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create())
            {
                _session1 = new SessionOfExperts("baseNotion");
                _session2 = new SessionOfExperts("otherNotion");

                var sessionRepo = GetRepository <SessionOfExperts>();
                sessionRepo.AddOrUpdate(_session1);
                sessionRepo.AddOrUpdate(_session2);

                _expert1 = new Expert("name1", _session1);
                _expert2 = new Expert("name2", _session2);
                _expert3 = new Expert("name3", _session1);
                var expertRepo = GetRepository <Expert>();
                expertRepo.AddOrUpdate(_expert1);
                expertRepo.AddOrUpdate(_expert2);
                expertRepo.AddOrUpdate(_expert3);

                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                var nodeRepo = GetRepository <Node>();
                var node1    = new Node("notion1", notionType);
                node1.AddSessionOfExperts(_session1);
                nodeRepo.AddOrUpdate(node1);

                var node2 = new Node("notion2", notionType);
                node2.AddSessionOfExperts(_session1);
                nodeRepo.AddOrUpdate(node2);

                var relationType = new RelationType("type");
                GetRepository <RelationType>().AddOrUpdate(relationType);

                var vergeRepo = GetRepository <Verge>();
                var verge1    = new Verge(node1, node2, relationType, 20);
                verge1.UpdateWeightFromSession(20, _session1);
                vergeRepo.AddOrUpdate(verge1);

                var verge2 = new Verge(node2, node1, relationType, 20);
                verge2.UpdateWeightFromSession(20, _session1);
                vergeRepo.AddOrUpdate(verge2);

                unitOfWork.Commit();
            }
        }
示例#4
0
        public void TestNewNode()
        {
            Node node;

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                node = new Node("notion", notionType);
                GetRepository <Node>().AddOrUpdate(node);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var savedNode = GetRepository <Node>().GetById(node.Id);

                savedNode.Should().BeEquivalentTo(savedNode, opt => opt.ExcludingNestedObjects());
            }
        }
示例#5
0
        public void GetReadOnlyIngoingAndOutgoing()
        {
            Node  node1, node2;
            Verge verge1, verge2;

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                var nodeRepo = GetRepository <Node>();
                node1 = new Node("notion1", notionType);
                nodeRepo.AddOrUpdate(node1);

                node2 = new Node("notion2", notionType);
                nodeRepo.AddOrUpdate(node2);

                var relationType = new RelationType("type");
                GetRepository <RelationType>().AddOrUpdate(relationType);

                var vergeRepo = GetRepository <Verge>();
                verge1 = new Verge(node1, node2, relationType, 20);
                vergeRepo.AddOrUpdate(verge1);

                verge2 = new Verge(node2, node1, relationType, 20);
                vergeRepo.AddOrUpdate(verge2);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                node1 = GetRepository <Node>().GetById(node1.Id);
                node2 = GetRepository <Node>().GetById(node2.Id);

                node1.IngoingVerges.Select(x => x.Id).Should().BeEquivalentTo(new[] { verge2.Id });
                node1.OutgoingVerges.Select(x => x.Id).Should().BeEquivalentTo(new[] { verge1.Id });
                node2.IngoingVerges.Select(x => x.Id).Should().BeEquivalentTo(new[] { verge1.Id });
                node2.OutgoingVerges.Select(x => x.Id).Should().BeEquivalentTo(new[] { verge2.Id });
            }
        }
示例#6
0
        public void UpdateAssociationTypes()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var sessionOfExperts = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(sessionOfExperts);

                var expert = new Expert("expertName", sessionOfExperts);
                expert.ReplaceAllAssociations(new[] { "notion1", "notion2" });

                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            Guid associationIdForUpdate;

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                associationIdForUpdate = LinqProvider.Query <Association>().First().Id;

                var type = new NotionType("NotionType");
                GetRepository <NotionType>().AddOrUpdate(type);

                expert.SetTypeForAssociation(associationIdForUpdate, type, "offer");
                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                var type   = LinqProvider.Query <NotionType>().Single();

                expert.Associations.Single(x => x.Id == associationIdForUpdate).Should().BeEquivalentTo(
                    new { Expert = expert, Type = type, OfferType = "offer" },
                    opt => opt.ExcludingMissingMembers());
            }
        }
示例#7
0
        public void TestAddSession()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                var node1 = new Node("notion1", notionType);
                GetRepository <Node>().AddOrUpdate(node1);

                var node2 = new Node("notion2", notionType);
                GetRepository <Node>().AddOrUpdate(node2);

                var relationType = new RelationType("type");
                GetRepository <RelationType>().AddOrUpdate(relationType);

                var verge = new Verge(node1, node2, relationType, 20);
                GetRepository <Verge>().AddOrUpdate(verge);

                unitOfWork.Commit();
            }

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var session = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(session);

                var verge = LinqProvider.Query <Verge>().Single();
                verge.UpdateWeightFromSession(20, session);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var verge = LinqProvider.Query <Verge>().Single();

                verge.SessionWeightSlices.Count.Should().Be(1);
            }
        }
示例#8
0
 public Node GetByNotionAndType(string notion, NotionType type)
 {
     return(_linqProvider.Query <Node>().SingleOrDefault(x => x.Notion == notion && x.Type == type));
 }
示例#9
0
        public void Ctor()
        {
            var type = new NotionType("name");

            Assert.That(type.Name, Is.EqualTo("name"));
        }
示例#10
0
        public void GenerateRelationsAndSetTypes()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var sessionOfExperts = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(sessionOfExperts);

                var notionType = new NotionType("type");
                GetRepository <NotionType>().AddOrUpdate(notionType);

                var expert = new Expert("expertName", sessionOfExperts);
                var nodes  = new List <Node> {
                    new Node("notion1", notionType), new Node("notion2", notionType)
                };
                foreach (var node in nodes)
                {
                    GetRepository <Node>().AddOrUpdate(node);
                }
                expert.GenerateRelations(nodes);
                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            RelationType type1, type2;

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();

                type1 = new RelationType("type1");
                type2 = new RelationType("type2");
                var relationTypeRepo = GetRepository <RelationType>();
                relationTypeRepo.AddOrUpdate(type1);
                relationTypeRepo.AddOrUpdate(type2);

                expert.SetTypesForRelation(
                    expert.Relations.Single(x => x.Source.Notion == "notion1").Id,
                    new[] { type1, type2 },
                    "offer1");

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                var nodes  = LinqProvider.Query <Node>().ToList();

                expert.Relations.Should().BeEquivalentTo(
                    new[]
                {
                    new
                    {
                        Expert      = expert, Source = nodes.Single(x => x.Notion == "notion1"),
                        Destination = nodes.Single(x => x.Notion == "notion2"), Types = new[] { type1, type2 },
                        OfferType   = "offer1"
                    },
                    new
                    {
                        Expert      = expert, Source = nodes.Single(x => x.Notion == "notion2"),
                        Destination = nodes.Single(x => x.Notion == "notion1"), Types = new RelationType[0],
                        OfferType   = (string)null
                    }
                },
                    opt => opt.ExcludingMissingMembers());
            }
        }