public async Task ProcessAsync_ValidAction_CallsCorrespondingArchivistToProcess() { var repositoryStab = new Mock <IDocumentRepository>(); var archivistFactoryMock = new Mock <IArchivistFactory>(); var visibleArchivistMock = new Mock <GetVisibleArchivist>(); var documentInfos = new[] { new DocumentWithoutContent { Id = "1", IsProtected = true, IsVisible = true, Name = "name1" }, new DocumentWithoutContent { Id = "12", IsProtected = false, IsVisible = true, Name = "name12" }, new DocumentWithoutContent { Id = "123", IsProtected = true, IsVisible = false, Name = "name123" }, }; const string actionName = "visible"; repositoryStab.Setup(it => it.GetDocumentsListAsync()).ReturnsAsync(documentInfos); archivistFactoryMock.Setup(it => it.CreateArchivistChain(It.Is <DocumentProcessingAction[]> (actions => actions.Single().ActionName == actionName))) .Returns(visibleArchivistMock.Object); var strategy = new EnumerateDocumentStrategy(repositoryStab.Object, archivistFactoryMock.Object); await strategy.ProcessAsync(Subject.Nothing, new[] { new DocumentProcessingAction { ActionName = actionName } }); archivistFactoryMock.Verify(it => it.CreateArchivistChain(It.Is <DocumentProcessingAction[]>(actions => actions.Single().ActionName == actionName)), Times.Once); visibleArchivistMock.Verify(it => it.Rethink(It.IsAny <Document>()), Times.Exactly(documentInfos.Length)); }
public async Task ProcessAsync_NoActions_ReturnsAllDocuments(DocumentProcessingAction[] actions) { var repositoryStab = new Mock <IDocumentRepository>(); var archivistFactoryStub = new Mock <IArchivistFactory>(); var documentInfos = new[] { new DocumentWithoutContent { Id = "1", IsProtected = true, IsVisible = true, Name = "name1" }, new DocumentWithoutContent { Id = "12", IsProtected = false, IsVisible = true, Name = "name12" }, new DocumentWithoutContent { Id = "123", IsProtected = true, IsVisible = false, Name = "name123" }, }; repositoryStab.Setup(it => it.GetDocumentsListAsync()).ReturnsAsync(documentInfos); archivistFactoryStub.Setup(it => it.CreateArchivistChain(It.IsAny <DocumentProcessingAction[]>())).Returns(new DoNothingArchivist()); var strategy = new EnumerateDocumentStrategy(repositoryStab.Object, archivistFactoryStub.Object); var result = await strategy.ProcessAsync(Subject.Nothing, actions); Assert.Equal(result.Type, DocumentViewType.Ok); var documentListContent = result.Content as DocumentListContent <DocumentDescriptionContent>; Assert.NotNull(documentListContent); Assert.Equal(documentInfos.Length, documentListContent.Count()); foreach (var documentWithoutContent in documentInfos) { var content = documentListContent.FirstOrDefault(it => it.DocumentName == documentWithoutContent.Name); Assert.NotNull(content); Assert.Equal(content.IsDocumentProtected, documentWithoutContent.IsProtected); Assert.Equal(content.IsDocumentVisible, documentWithoutContent.IsVisible); } }