public void CreateSemanticNetworkFromNodeCandidates_IfNodeExistsInRepo_UpdateIt() { #region arrange var serviceUnderTests = CreateServiceUnderTest(); var generalType = ReturnsGeneralNotionTypeFromRepository(); var notionTypeId = GeneratedGuids.First; var notionType = Substitute.For <NotionType>(); FakeNotionTypeRepository.GetById(Arg.Is(notionTypeId)).Returns(notionType); var root = Substitute.For <Node>(); FakeNodeRepository.GetByNotionAndType(Arg.Is("baseNotion"), Arg.Is(generalType)).Returns(root); var node = Substitute.For <Node>(); FakeNodeRepository.GetByNotionAndType(Arg.Is("notion"), Arg.Is(notionType)).Returns(node); var nodeCandidate = new NodeCandidate { IsSaveAsNode = true, Notion = "notion", TypeId = GeneratedGuids.First }; var session = CreateFakeSession("baseNotion"); #endregion serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidate.Enumerate(), session); FakeNodeRepository.Received(1).AddOrUpdate(Arg.Is(root)); FakeNodeRepository.Received(1).AddOrUpdate(Arg.Is(node)); }
public void CreateSemanticNetworkFromNodeCandidates_CreateNodeForRootAndForNodeCandidates() { #region arrange var serviceUnderTests = CreateServiceUnderTest(); FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null); var generalType = ReturnsGeneralNotionTypeFromRepository(); var notionTypeId = GeneratedGuids.First; var notionType = Substitute.For <NotionType>(); FakeNotionTypeRepository.GetById(Arg.Is(notionTypeId)).Returns(notionType); var nodeCandidate = new NodeCandidate { IsSaveAsNode = true, Notion = "notion", TypeId = notionTypeId }; var session = CreateFakeSession("baseNotion"); #endregion serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidate.Enumerate(), session); FakeNodeRepository.Received(1) .AddOrUpdate(Arg.Is <Node>(x => x.Notion == "baseNotion" && x.Type == generalType)); FakeNodeRepository.Received(1).AddOrUpdate(Arg.Is <Node>(x => x.Notion == "notion" && x.Type == notionType)); }
public void CreateSemanticNetworkFromNodeCandidates_FilteredByIsSaveAsNode() { #region arrange var serviceUnderTests = CreateServiceUnderTest(); FakeNodeRepository.GetByNotionAndType(Arg.Any <string>(), Arg.Any <NotionType>()).Returns((Node)null); var notionTypeId = GeneratedGuids.First; var notionType = Substitute.For <NotionType>(); FakeNotionTypeRepository.GetById(Arg.Is(notionTypeId)).Returns(notionType); var nodeCandidates = new[] { new NodeCandidate { IsSaveAsNode = true, Notion = "notion", TypeId = notionTypeId }, new NodeCandidate { IsSaveAsNode = false, Notion = "notion2", TypeId = notionTypeId } }; var session = CreateFakeSession("baseNotion"); #endregion serviceUnderTests.CreateSemanticNetworkFromNodeCandidates(nodeCandidates, session); FakeNodeRepository.Received(1).AddOrUpdate(Arg.Is <Node>(x => x.Notion == "notion" && x.Type == notionType)); FakeNodeRepository.DidNotReceive() .AddOrUpdate(Arg.Is <Node>(x => x.Notion == "notion2" && x.Type == notionType)); }
private NotionType FromNotionTypeRepositoryReturnFakeType(Guid notionTypeId) { var notionType = Substitute.For <NotionType>(); FakeNotionTypeRepository.GetById(Arg.Is(notionTypeId)).Returns(notionType); return(notionType); }