Skip to content

Commit f422a29

Browse files
author
sergey-sorokin-virtoworks
authored
VCST-3911: Remove leading and trailing spaces from product name (#125)
1 parent f72822f commit f422a29

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/VirtoCommerce.CatalogCsvImportModule.Data/Services/CsvCatalogImporter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public async Task DoImport(List<CsvProduct> csvProducts, CsvImportInfo importInf
8282
throw new InvalidOperationException($"Catalog with id '{importInfo.CatalogId}' does not exist.");
8383
}
8484

85+
foreach (var csvProduct in csvProducts.Where(csvProduct => !string.IsNullOrEmpty(csvProduct.Name)))
86+
{
87+
csvProduct.Name = csvProduct.Name.Trim();
88+
}
89+
8590
var valid = await ValidateCsvProducts(csvProducts, progressInfo, progressCallback);
8691
if (!valid)
8792
{

tests/VirtoCommerce.CatalogCsvImportModule.Test/ImporterTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,25 @@ public async Task DoImport_NewProductWithVariationsProductUseId()
15161516
Assert.Equal(mainProduct.Id, variationProduct.MainProductId);
15171517
}
15181518

1519+
[Fact]
1520+
public async Task DoImport_ProductNameShouldBeTrimmed()
1521+
{
1522+
// Arrange
1523+
var product = GetCsvProductBase();
1524+
1525+
const string expectedProductName = "Trimmed name";
1526+
product.Name = "\n \r" + expectedProductName + "\t";
1527+
1528+
var target = GetImporter();
1529+
var exportInfo = new ExportImportProgressInfo();
1530+
1531+
// Act
1532+
await target.DoImport([product], GetCsvImportInfo(), exportInfo, _ => { });
1533+
1534+
// Assert
1535+
Assert.Equal(expectedProductName, product.Name);
1536+
}
1537+
15191538

15201539
private CsvCatalogImporter GetImporter(IPropertyDictionaryItemService propertyDictionaryItemService = null, bool? createDictionaryValues = false)
15211540
{

0 commit comments

Comments
 (0)