public StoryReadServiceTests() { storyRepos = Mock.Create <IStoryRepository>(); nodeService = Mock.Create <IAsyncNodeService>(); storySectionRepository = Mock.Create <IStorySectionRepository>(); target = new StoryReadService(storyRepos, nodeService, storySectionRepository); testStory = new Story { Id = 1, Title = "A Story", Synopsis = "A Summary" }; Mock.Arrange(() => storyRepos.GetAsync(testStory.Id)) .Returns(() => Task.FromResult(testStory)); Mock.Arrange(() => nodeService.Get(Arg.IsAny <INode>(), Arg.IsAny <NodeType <Actor> >())) .Returns(() => Task.FromResult(new List <Actor>())); Mock.Arrange(() => storySectionRepository.GetTreeForStory(Arg.AnyInt)) .Returns(() => Task.FromResult(new OrderedHierarchicalTree <StorySection>())); }
public async Task GetStoryOverview_GetsActors() { var actor = new Actor { Id = 10, Name = "Actor" }; var actors = new List <Actor> { actor }; Mock.Arrange(() => nodeService.Get(Arg.IsAny <INode>(), Arg.IsAny <NodeType <Actor> >())) .Returns((INode node, INodeType nodetype) => Task.FromResult( node.Id == testStory.Id && node.NodeType.Equals(testStory.NodeType) && nodetype.Equals(StoryboardNodeTypes.Actor) ? actors : new List <Actor>())); var result = await target.GetStoryOverview(testStory.Id); Assert.Equal(1, result.Actors.Count); Assert.Equal(10, result.Actors[0].Id); }
/// <summary> /// Gets requested story overview /// </summary> /// <param name="id">Story Id</param> /// <returns>Requested StoryOverview</returns> public async Task <StoryOverview> GetStoryOverview(int id) { var result = new StoryOverview(); result.Summary = await GetStorySummary(id); var tree = await storySectionRepository.GetTreeForStory(id); result.Actors = await nodeService.Get(new Node(id, StoryboardNodeTypes.Story), StoryboardNodeTypes.Actor); if (tree != null && tree.Hierarchies.Count != 0) { if (tree.Hierarchies.Count != 1) { throw new InvalidOperationException("Multiple Hierarchical levels not supported"); } result.Sections = tree.GetHierarchicalLevel(tree.Hierarchies[0]).ToList(); } else { result.Sections = new List <StorySection>(); } return(result); }
public async Task Get_Node_ThrowsNullException_IfNodeNull() { await Assert.ThrowsAsync(typeof(ArgumentNullException), () => target.Get(null)); }