Beispiel #1
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());
            }
        }