Example #1
0
        public async Task HeadFile_UnknownException_InternalServerErrorFailure()
        {
            // Arrange
            var moq = new Mock <IFilesRepository>();

            moq.Setup(t => t.GetFileHead(It.IsAny <Guid>())).Throws(new Exception());
            var moqFileStreamRepo = new Mock <IFileStreamRepository>();
            var moqConfigRepo     = new Mock <IConfigRepository>();
            var moqLog            = new Mock <sl.IServiceLogRepository>();

            var controller = new FilesController(moq.Object, moqFileStreamRepo.Object, moqConfigRepo.Object, moqLog.Object)
            {
                Request = new HttpRequestMessage
                {
                    RequestUri = new Uri("http://localhost/files"),
                    Method     = HttpMethod.Head
                },
                Configuration = new HttpConfiguration()
            };

            controller.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "files/{id}",
                defaults: new { id = RouteParameter.Optional });

            // Act
            var actionResult = await controller.GetFileHead("33333333333333333333333333333333");

            System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken();
            HttpResponseMessage response = await actionResult.ExecuteAsync(cancellationToken);

            // Assert
            Assert.IsTrue(response.StatusCode == HttpStatusCode.InternalServerError);
        }
Example #2
0
        public async Task HeadFile_GetHeadForExistentFileStreamFile_Success()
        {
            // Arrange
            var moq = new Mock <IFilesRepository>();
            var moqFileStreamRepo = new Mock <IFileStreamRepository>();
            var moqConfigRepo     = new Mock <IConfigRepository>();
            var moqLog            = new Mock <sl.IServiceLogRepository>();

            var file = new File
            {
                FileId       = new Guid("33333333-3333-3333-3333-333333333333"),
                FileName     = "Test3.txt",
                StoredTime   = I18NHelper.DateTimeParseExactInvariant("2015-09-05T22:57:31.7824054-04:00", "o"),
                FileType     = "text/html",
                ChunkCount   = 1,
                IsLegacyFile = true
            };

            moq.Setup(t => t.GetFileHead(It.IsAny <Guid>())).ReturnsAsync((File)null);

            moqFileStreamRepo.Setup(t => t.FileExists(file.FileId)).Returns(true);
            moqFileStreamRepo.Setup(t => t.GetFileHead(file.FileId)).Returns(file);

            var controller = new FilesController(moq.Object, moqFileStreamRepo.Object, moqConfigRepo.Object, moqLog.Object)
            {
                Request = new HttpRequestMessage
                {
                    RequestUri = new Uri("http://localhost/files"),
                    Method     = HttpMethod.Head
                },
                Configuration = new HttpConfiguration()
            };

            controller.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "files/{id}",
                defaults: new { id = RouteParameter.Optional });

            // Act
            var actionResult = await controller.GetFileHead("33333333333333333333333333333333");

            System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken();
            HttpResponseMessage response = await actionResult.ExecuteAsync(cancellationToken);

            var content     = response.Content;
            var contentType = content.Headers.ContentType;
            var fileName    = content.Headers.ContentDisposition.FileName;
            var storedTime  = response.Headers.GetValues("Stored-Date");

            // Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreEqual("Test3.txt", fileName);
            Assert.AreEqual("application/octet-stream", contentType.MediaType, string.Format("Returned content type {0} does not match expected {1}", contentType, "text/html"));
            Assert.AreEqual(DateTime.Parse("2015-09-05T22:57:31.7824054-04:00"), DateTime.Parse(storedTime.First()));
        }