public void Execute_ShouldCallGetFilesToBePurged() { bool getFilesToBePurgedWasCalled = false; FSI.IFileService fileservice = new StubIFileService() { GetFilesToBePurgedDouble = validStorageDays => { getFilesToBePurgedWasCalled = true; return new List<File>(); } }; IUnityContainer unityContainer = new UnityContainer(); using (ShimsContext.Create()) { ShimDiagnosticsProvider.ConstructorType = (dp, type) => { }; Constants.ShimConstants.UploadedFilesExpirationDurationInHoursGet = () => 3; ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdStringObjectArray = (diagnosticsProvider, traceEventId, message, args) => { }; IFileService filePurgeService = new FilePurgeService(fileservice, unityContainer); filePurgeService.Execute(); } Assert.IsTrue(getFilesToBePurgedWasCalled); }
public void Execute_ShouldCallDeleteFileForEachFileReturnedByGetFilesToBePurged() { int numberOfCallsToDeleteFile = 0; FSI.IFileService fileservice = new StubIFileService() { GetFilesToBePurgedDouble = validStorageDays => GetFiles(), DeleteFileInt32Int32 = (userId, fileId) => { numberOfCallsToDeleteFile++; return true; } }; IUnityContainer unityContainer = new UnityContainer(); using (ShimsContext.Create()) { ShimDiagnosticsProvider.ConstructorType = (dp, type) => { }; Constants.ShimConstants.UploadedFilesExpirationDurationInHoursGet = () => 3; ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdStringObjectArray = (diagnosticsProvider, traceEventId, message, args) => { }; FilePurgeService filePurgeService = new FilePurgeService(fileservice, unityContainer); filePurgeService.Execute(); } Assert.AreEqual(4, numberOfCallsToDeleteFile); }
public void Upload_ShouldReturnUploadedFileWithFileIdGreaterThanZero_WhenAFileIsUploaded() { IFileService fileService = new StubIFileService() { UploadFileDataDetail = dd => { dd.FileDetail.FileId = 1; return dd; } }; DefaultFileHandler defaultFileHandler = new DefaultFileHandler(fileService); DataFile dataFile = new DataFile() { FileContent = new byte[0] }; DataDetail dataDetail = defaultFileHandler.Upload(dataFile).First(); Assert.IsTrue(dataDetail.FileDetail.FileId > 0); }
public void Upload_ShouldThrowArgumentException_WhenDataFileIsNull() { IFileService fileService = new StubIFileService(); DefaultFileHandler defaultFileHandler = new DefaultFileHandler(fileService); try { defaultFileHandler.Upload(null); Assert.Fail("Should have exceptioned above!"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); Assert.IsTrue(ex.Message.ToString().Contains("dataFile")); } }
public void Initialize() { this.fileService = new StubIFileService() { CheckFileExistsStringInt32 = (fileName, userId) => { return true; }, UploadFileDataDetail = (dataDetail) => { DataDetail objDetail = new DataDetail(); objDetail.FileDetail.FileId = 1; objDetail.FileDetail.CreatedBy = 1; return objDetail; } }; }
public void Execute_UnhandledExceptionShouldWriteErrorTrace() { bool writeErrorTraceWasCalled = false; FSI.IFileService fileservice = new StubIFileService() { GetUploadedFiles = () => { throw new Exception(); } }; using (ShimsContext.Create()) { ShimDiagnosticsProvider.ConstructorType = (dp, type) => { }; Constants.ShimConstants.UploadedFilesExpirationDurationInHoursGet = () => 3; ShimDiagnosticsProvider.AllInstances.WriteErrorTraceTraceEventIdStringObjectArray = (diagnosticsProvider, traceEventId, message, args) => { writeErrorTraceWasCalled = true; }; FileUpdateService fileUpdateService = new FileUpdateService(fileservice); fileUpdateService.Execute(); } Assert.IsTrue(writeErrorTraceWasCalled); }
public void Upload_ShouldReturnUploadedFileWithFileIdGreaterThanZero_WhenAFileIsUploaded() { IFileService fileService = new StubIFileService() { UploadFileDataDetail = dd => { dd.FileDetail.FileId = 1; return dd; } }; DefaultFileHandler defaultFileHandler = new DefaultFileHandler(fileService); DataFile dataFile = new DataFile() { FileContent = new byte[0] }; IEnumerable<DataDetail> dataDetails; List<DataFile> dataFiles = new List<DataFile>(); dataFiles.Add(new DataFile() { FileContent = new byte[0] }); dataFiles.Add(new DataFile() { FileContent = new byte[0] }); using (ShimsContext.Create()) { ShimZipUtilities.GetListOfFilesFromStreamStreamInt32 = (zipstream, userId) => dataFiles; dataDetails = defaultFileHandler.Upload(dataFile); } Assert.IsTrue(dataDetails.All(fd => fd.FileDetail.FileId > 0)); }
public void Execute_ShouldCallUpdateFileForEachFileReturnedByGetUploadedFiles() { int numberOfCallsToUpdateFile = 0; FSI.IFileService fileservice = new StubIFileService() { GetUploadedFiles = () => GetFiles(), UpdateFileFile = (file) => { numberOfCallsToUpdateFile++; return true; } }; using (ShimsContext.Create()) { ShimDiagnosticsProvider.ConstructorType = (dp, type) => { }; Constants.ShimConstants.UploadedFilesExpirationDurationInHoursGet = () => 3; ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdStringObjectArray = (diagnosticsProvider, traceEventId, message, args) => { }; IFileService fileUpdateService = new FileUpdateService(fileservice); fileUpdateService.Execute(); } Assert.AreEqual(4, numberOfCallsToUpdateFile); }
public async Task GetQualityCheckRulesAndFileSheets_ShouldReturnHttpStatusCodeOK_WhenFileServiceReturnsAXlsxFile() { IFileService fileService = new StubIFileService() { GetFileByFileIdInt32 = (fileId) => new File() { Name = "abc.xlsx" }, GetDocumentSheetDetailsFile = (file) => Task.FromResult<IEnumerable<FileSheet>>(null) }; IFileServiceFactory fileServiceFactory = new StubIFileServiceFactory() { GetFileServiceString = instanceName => fileService }; IQCService qcService = new StubIQCService(); using (ShimsContext.Create()) { ShimIdentityHelper.GetCurrentUserIUserServiceClaimsPrincipal = (service, principle) => new User(); QCController fileController = new QCController(qcService, fileServiceFactory, null); fileController.Request = new HttpRequestMessage(HttpMethod.Get, string.Empty); fileController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration(); HttpResponseMessage httpResponseMessage = await fileController.GetQualityCheckRulesAndFileSheets(0); Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode); } }
public async Task GetQualityCheckRulesAndFileSheets_ShouldReturnHttpStatusCodeNotImplemented_WhenFileServiceReturnsAFileOtherThanXlsxAndCsv() { IFileService fileService = new StubIFileService() { GetFileByFileIdInt32 = (fileId) => new File() { Name = "abc.xyz" } }; IFileServiceFactory fileServiceFactory = new StubIFileServiceFactory() { GetFileServiceString = instanceName => fileService }; using (ShimsContext.Create()) { ShimIdentityHelper.GetCurrentUserIUserServiceClaimsPrincipal = (service, principle) => new User(); QCController fileController = new QCController(null, fileServiceFactory, null); fileController.Request = new HttpRequestMessage(HttpMethod.Get, string.Empty); fileController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration(); HttpResponseMessage httpResponseMessage = await fileController.GetQualityCheckRulesAndFileSheets(0); Assert.AreEqual(HttpStatusCode.NotImplemented, httpResponseMessage.StatusCode); } }