public virtual async Task <IActionResult> ExportXlsx() { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedView()); } try { var bytes = await _exportManager .ExportCategoriesToXlsxAsync((await _categoryService.GetAllCategoriesAsync(showHidden: true)).ToList()); return(File(bytes, MimeTypes.TextXlsx, "categories.xlsx")); } catch (Exception exc) { await _notificationService.ErrorNotificationAsync(exc); return(RedirectToAction("List")); } }
public async Task CanExportCategoriesToXlsx() { var categories = await _categoryService.GetAllCategoriesAsync(); var excelData = await _exportManager.ExportCategoriesToXlsxAsync(categories); var worksheet = GetWorksheets(excelData); var manager = GetPropertyManager <Category>(worksheet); manager.ReadFromXlsx(worksheet, 2); var category = categories.First(); var ignore = new List <string> { "CreatedOnUtc", "EntityCacheKey", "Picture", "PictureId", "AppliedDiscounts", "UpdatedOnUtc", "SubjectToAcl", "LimitedToStores", "Deleted", "DiscountCategoryMappings" }; AreAllObjectPropertiesPresent(category, manager, ignore.ToArray()); PropertiesShouldEqual(category, manager, new Dictionary <string, string>()); manager.GetProperties.First(p => p.PropertyName == "Picture").PropertyValue.Should().NotBeNull(); }