public void SaveRelationsAsVergesOfSemanticNetwork()
        {
            #region arrange

            var serviceUnderTests = CreateServiceUnderTest();

            FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null);
            FakeVergeRepository.GetByNodesAndTypes(Arg.Any <Node>(), Arg.Any <Node>(), Arg.Any <RelationType>())
            .Returns((Verge)null);

            var source           = Substitute.For <Node>();
            var destination      = Substitute.For <Node>();
            var type             = Substitute.For <RelationType>();
            var groupedRelations = new[]
            {
                new GroupedRelation
                {
                    Source      = source, Destination = destination, Type = type,
                    ExpertCount = 4, TotalExpectCount = 5
                }
            };
            var session = CreateFakeSession("baseNotion");

            #endregion

            serviceUnderTests.SaveRelationsAsVergesOfSemanticNetwork(groupedRelations, session);

            FakeVergeRepository.Received(1).AddOrUpdate(
                Arg.Is <Verge>(
                    x =>
                    x.SourceNode == source && x.DestinationNode == destination &&
                    x.Weight == 80));
        }
        public void CreateSemanticNetworkFromNodeCandidates_CreateVergesFromRootToEachNodeCandidateSavedAsNode()
        {
            #region arrange

            var serviceUnderTests = CreateServiceUnderTest();

            FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null);
            FakeVergeRepository.GetByNodesAndTypes(Arg.Any <Node>(), Arg.Any <Node>(), Arg.Any <RelationType>())
            .Returns((Verge)null);
            var generalRelationType = ReturnsGeneralRelationTypeFromRepository();

            var nodeCandidates = new[]
            {
                new NodeCandidate {
                    IsSaveAsNode = true, Notion = "notion", ExpertCount = 1, TotalExpert = 5
                },
                new NodeCandidate {
                    IsSaveAsNode = false, Notion = "notion2"
                }
            };
            var session = CreateFakeSession("baseNotion");

            #endregion

            serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidates, session);

            FakeVergeRepository.Received(1).AddOrUpdate(
                Arg.Is <Verge>(
                    x =>
                    x.SourceNode.Notion == "baseNotion" && x.DestinationNode.Notion == "notion" &&
                    x.Type == generalRelationType));
            FakeVergeRepository.Received(1).AddOrUpdate(
                Arg.Is <Verge>(
                    x =>
                    x.SourceNode.Notion == "notion" && x.DestinationNode.Notion == "baseNotion" &&
                    x.Type == generalRelationType));
        }
        public void CreateSemanticNetworkFromNodeCandidates_CalculateVergeWeight()
        {
            #region arrange

            var serviceUnderTests = CreateServiceUnderTest();

            FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null);
            FakeVergeRepository.GetByNodesAndTypes(Arg.Any <Node>(), Arg.Any <Node>(), Arg.Any <RelationType>())
            .Returns((Verge)null);

            var nodeCandidates = new[]
            {
                new NodeCandidate {
                    IsSaveAsNode = true, Notion = "notion", TotalExpert = 5, ExpertCount = 2
                },
                new NodeCandidate {
                    IsSaveAsNode = true, Notion = "notion2", TotalExpert = 5, ExpertCount = 3
                }
            };
            var session = CreateFakeSession("baseNotion");

            #endregion

            serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidates, session);

            FakeVergeRepository.Received(1).AddOrUpdate(
                Arg.Is <Verge>(
                    x =>
                    x.SourceNode.Notion == "baseNotion" && x.DestinationNode.Notion == "notion" &&
                    x.Weight == 40));
            FakeVergeRepository.Received(1).AddOrUpdate(
                Arg.Is <Verge>(
                    x =>
                    x.SourceNode.Notion == "baseNotion" && x.DestinationNode.Notion == "notion2" &&
                    x.Weight == 60));
        }