public static async Task DownloadAsync_DocumentRepositoryException_IsLogged()
        {
            var expectedException = new DocumentRepositoryException(
                new InvalidOperationException(),
                StatusCodes.Status502BadGateway);

            var mockStorage = new Mock <IDocumentRepository>();

            mockStorage.Setup(s => s.DownloadAsync(It.IsAny <string>())).Throws(expectedException);

            var mockLogger = new Mock <ILogger <DocumentsController> >();

            var controller = new DocumentsController(mockStorage.Object, mockLogger.Object);

            await controller.DownloadAsync("directory");

            Expression <Action <ILogger <DocumentsController> > > expression = l => l.Log(
                It.Is <LogLevel>(l => l == LogLevel.Error),
                It.IsAny <EventId>(),
                It.Is <It.IsAnyType>((v, t) => true),
                It.Is <Exception>(e => e == expectedException),
                It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true));

            mockLogger.Verify(expression);
        }
예제 #2
0
        public async Task DownloadAsync_DocumentRepositoryException_IsLogged()
        {
            var exception = new DocumentRepositoryException(
                new InvalidOperationException(),
                StatusCodes.Status502BadGateway);

            var mockStorage = new Mock <IDocumentRepository>();

            mockStorage.Setup(s => s.DownloadAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Throws(exception);

            var       logLevel        = LogLevel.None;
            Exception actualException = null;

            void Callback(LogLevel l, Exception e)
            {
                logLevel        = l;
                actualException = e;
            }

            var mockLogger = new MockLogger <SolutionsController>(Callback);

            var controller = new SolutionsController(mockStorage.Object, mockLogger);

            await controller.DownloadAsync("ID", "directory");

            logLevel.Should().Be(LogLevel.Error);
            actualException.Should().Be(exception);
        }
예제 #3
0
        public void Constructor_Parameterless_InitializesCorrectly()
        {
            var repoException = new DocumentRepositoryException();

            repoException.HttpStatusCode.Should().Be(0);
            repoException.InnerException.Should().BeNull();
            repoException.Message.Should().Be(DocumentRepositoryException.DefaultMessage);
        }
예제 #4
0
        public void Constructor_String_InitializesCorrectly()
        {
            const string message = "This is a message.";

            var repoException = new DocumentRepositoryException(message);

            repoException.HttpStatusCode.Should().Be(0);
            repoException.InnerException.Should().BeNull();
            repoException.Message.Should().Be(message);
        }
        public static void Constructor_String_Exception_InitializesCorrectly()
        {
            const string message = "This is a message.";

            var innerException      = new InvalidOperationException();
            var repositoryException = new DocumentRepositoryException(message, innerException);

            repositoryException.HttpStatusCode.Should().Be(0);
            repositoryException.InnerException.Should().Be(innerException);
            repositoryException.Message.Should().Be(message);
        }
        public static async Task DownloadAsync_DocumentRepositoryException_ReturnsStatusCodeResult()
        {
            var exception = new DocumentRepositoryException(
                new InvalidOperationException(),
                StatusCodes.Status502BadGateway);

            var mockStorage = new Mock <IDocumentRepository>();

            mockStorage.Setup(s => s.DownloadAsync(It.IsAny <string>())).Throws(exception);

            var controller = new DocumentsController(mockStorage.Object, Mock.Of <ILogger <DocumentsController> >());

            var result = await controller.DownloadAsync("directory") as StatusCodeResult;

            Assert.NotNull(result);
            result.StatusCode.Should().Be(exception.HttpStatusCode);
        }