public void SaveRelationsAsVergesOfSemanticNetwork_IfVergeExists_UpdateIt()
        {
            #region arrange

            var serviceUnderTests = CreateServiceUnderTest();

            var verge       = Substitute.For <Verge>();
            var source      = Substitute.For <Node>();
            var destination = Substitute.For <Node>();
            var type        = Substitute.For <RelationType>();
            FakeVergeRepository.GetByNodesAndTypes(Arg.Is(source), Arg.Is(destination), Arg.Is(type)).Returns(verge);
            var session = CreateFakeSession();

            var groupedRelations = new[]
            {
                new GroupedRelation
                {
                    Source           = source, Destination = destination, ExpertCount = 1,
                    TotalExpectCount = 5, Type = type
                }
            };

            #endregion

            serviceUnderTests.SaveRelationsAsVergesOfSemanticNetwork(groupedRelations, session);

            verge.Received(1).UpdateWeightFromSession(Arg.Is(20), Arg.Is(session));
        }
        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_IfVergeExists_UpdateItAndLinkSession()
        {
            #region arrange

            var serviceUnderTests = CreateServiceUnderTest();

            FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null);
            var verge = Substitute.For <Verge>();
            FakeVergeRepository.GetByNodesAndTypes(
                Arg.Is <Node>(x => x.Notion == "source"),
                Arg.Is <Node>(x => x.Notion == "destination"),
                Arg.Any <RelationType>())
            .Returns(verge);
            var session = CreateFakeSession("source");

            var nodeCandidates = new[]
            {
                new NodeCandidate {
                    IsSaveAsNode = true, Notion = "destination", TotalExpert = 5, ExpertCount = 2
                }
            };

            #endregion

            serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidates, session);

            verge.Received(1).UpdateWeightFromSession(Arg.Is(40), Arg.Is(session));
        }
        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));
        }