public void GivenNotInitialized_WhenAppendErrorRows_ThenThrowException() { var offering = TestData.ServiceOfferings[0]; var writer = new WorksheetWriter(offering, null); Target.ExpectException <InvalidOperationException>(() => Target.AppendErrorRows(null, writer)); }
public DownloadFileModel CreateTemplateDownload(EducationSecurityPrincipal user, string templatePath, int serviceOfferingId) { var offering = ServiceOfferingRepository.Items.Include(s => s.Provider). Include(s => s.ServiceType). Include(s => s.Program). SingleOrDefault(s => s.Id == serviceOfferingId); if (offering == null) { return(null); } if (!GrantUserAccessToUploadOffering(user, offering)) { throw new EntityAccessUnauthorizedException("You are not have the appropriate rights to download this service offering."); } var processor = new WorksheetWriter(offering, ServiceOfferingSheetName); var fileName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", offering.Name.GetSafeFileName(), ".xlsx"); var downloadFile = new DownloadFileModel { FileName = fileName, BlobAddress = string.Empty }; ExcelWriter writer = new ExcelWriter(); writer.InitializeFrom(templatePath, processor); downloadFile.FileContentStream = writer.FileContentStream; downloadFile.FileContentStream.Position = 0; return(downloadFile); }
public void InitializeTest() { TestData = new TestData(); ServiceOffering = new ServiceOffering() { Id = 1, Provider = TestData.Providers[0], ServiceType = TestData.ServiceTypes[0], Program = TestData.Programs[0] }; Target = new WorksheetWriter(ServiceOffering, "Assign Service Offering"); }
public void GivenAServiceOffering_AndInitializeFromTemplate_WhenWrite_ThenFileSavedWithExpectedContentType() { string expectedContentType = ExcelWriter.ContentType; var offering = TestData.ServiceOfferings[0]; var fileName = string.Format("{0}-{1}-{2}{3}", offering.Provider.Name, offering.ServiceType.Name, DateTime.Now.Ticks, ".xlsx"); var downloadfilePath = string.Format("{0}{1}", AssignedServiceOfferingTemplatePath.Replace("\\App_Data\\Uploads\\Templates\\" + ServiceOfferingController.TemplateFile, "\\Content\\Downloads\\"), fileName); WorksheetWriter writer = new WorksheetWriter(offering, ServiceOfferingSheetName); IBlobContainer mockBlobContainer = MockRepository.GenerateMock<IBlobContainer>(); Target.InitializeFrom(AssignedServiceOfferingTemplatePath, writer); Target.Write(mockBlobContainer, downloadfilePath); mockBlobContainer.AssertWasCalled(m => m.UploadFromStream(downloadfilePath, Target.FileContentStream, expectedContentType)); }
public void GivenAServiceOffering_AndInitializeFromTemplate_WhenWrite_ThenItIsSavedForTheUserToDownload() { var offering = TestData.ServiceOfferings[0]; var fileName = string.Format("{0}-{1}-{2}{3}", offering.Provider.Name, offering.ServiceType.Name, DateTime.Now.Ticks, ".xlsx"); var downloadfilePath = string.Format("{0}{1}", AssignedServiceOfferingTemplatePath.Replace("\\App_Data\\Uploads\\Templates\\" + ServiceOfferingController.TemplateFile, "\\Content\\Downloads\\"), fileName); var writer = new WorksheetWriter(offering, ServiceOfferingSheetName); IBlobContainer mockBlobContainer = CreateMockBlobContainer(); Target.InitializeFrom(AssignedServiceOfferingTemplatePath, writer); Target.Write(mockBlobContainer, downloadfilePath); Assert.IsTrue(File.Exists(downloadfilePath)); File.Delete(downloadfilePath); }
public void GivenANullSheetName_AndInitializeFromFile_WhenAppendErrorRows_AndWrite_ThenTheFirstSheetIsUsed() { var filePath = UploadFileTemplatePath + "NullStartEndDateAndNotesCol.xlsx"; var destinationPath = CopyTestFile(filePath); var offering = TestData.ServiceOfferings[0]; var writer = new WorksheetWriter(offering, null); IBlobContainer mockBlobContainer = CreateMockBlobContainer(); Target.InitializeFrom(destinationPath); Target.AppendErrorRows(null, writer); Target.Write(mockBlobContainer, destinationPath); Assert.IsNotNull(File.Exists(destinationPath)); DestroyTestFile(destinationPath); }
public void GivenAServiceOffering_AndInitializeFromTemplate_WhenWrite_ThenFileSavedWithExpectedContentType() { string expectedContentType = ExcelWriter.ContentType; var offering = TestData.ServiceOfferings[0]; var fileName = string.Format("{0}-{1}-{2}{3}", offering.Provider.Name, offering.ServiceType.Name, DateTime.Now.Ticks, ".xlsx"); var downloadfilePath = string.Format("{0}{1}", AssignedServiceOfferingTemplatePath.Replace("\\App_Data\\Uploads\\Templates\\" + ServiceOfferingController.TemplateFile, "\\Content\\Downloads\\"), fileName); WorksheetWriter writer = new WorksheetWriter(offering, ServiceOfferingSheetName); IBlobContainer mockBlobContainer = MockRepository.GenerateMock <IBlobContainer>(); Target.InitializeFrom(AssignedServiceOfferingTemplatePath, writer); Target.Write(mockBlobContainer, downloadfilePath); mockBlobContainer.AssertWasCalled(m => m.UploadFromStream(downloadfilePath, Target.FileContentStream, expectedContentType)); }
public void GivenNotInitialized_WhenAppendErrorRows_ThenThrowException() { var offering = TestData.ServiceOfferings[0]; var writer = new WorksheetWriter(offering, null); Target.ExpectException<InvalidOperationException>(() => Target.AppendErrorRows(null, writer)); }
public DownloadFileModel CreateTemplateDownload(EducationSecurityPrincipal user, string templatePath, int serviceOfferingId) { var offering = ServiceOfferingRepository.Items.Include(s => s.Provider). Include(s => s.ServiceType). Include(s => s.Program). SingleOrDefault(s => s.Id == serviceOfferingId); if (offering == null) { return null; } if (!GrantUserAccessToUploadOffering(user, offering)) { throw new EntityAccessUnauthorizedException("You are not have the appropriate rights to download this service offering."); } var processor = new WorksheetWriter(offering, ServiceOfferingSheetName); var fileName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", offering.Name.GetSafeFileName(), ".xlsx"); var downloadFile = new DownloadFileModel { FileName = fileName, BlobAddress = string.Empty }; ExcelWriter writer = new ExcelWriter(); writer.InitializeFrom(templatePath, processor); downloadFile.FileContentStream = writer.FileContentStream; downloadFile.FileContentStream.Position = 0; return downloadFile; }