-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VP-2440: Fix CatalogImage.itemId empty field after import products (#53)
- Loading branch information
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
tests/VirtoCommerce.CatalogCsvImportModule.Test/MergingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using VirtoCommerce.CatalogCsvImportModule.Core.Model; | ||
using VirtoCommerce.CatalogModule.Core.Model; | ||
using VirtoCommerce.CoreModule.Core.Seo; | ||
using Xunit; | ||
|
||
namespace VirtoCommerce.CatalogCsvImportModule.Test | ||
{ | ||
public class MergingTests | ||
{ | ||
[Fact] | ||
public void CsvProductMergeTest_ProductHasSameImages_ImagesUpdated() | ||
{ | ||
//Arrange | ||
var catalogProduct = GetCatalogProductWithImage(); | ||
var csvProduct = new CsvProduct() | ||
{ | ||
Images = new List<Image>() {new Image() {Id = "", Url = "SameURL"}} | ||
}; | ||
//Act | ||
csvProduct.MergeFrom(catalogProduct); | ||
|
||
//Assets | ||
Assert.Equal(1, csvProduct.Images.Count); | ||
Assert.NotNull(csvProduct.Images.FirstOrDefault(x => x.Id == "1")); | ||
} | ||
|
||
[Fact] | ||
public void CsvProductMergeTest_ProductHasAnotherImages_ImagesAdded() | ||
{ | ||
//Arrange | ||
var catalogProduct = GetCatalogProductWithImage(); | ||
|
||
var csvProduct = new CsvProduct() | ||
{ | ||
Images = new List<Image>() { new Image() { Id = "", Url = "AnotherUrl" } } | ||
}; | ||
|
||
//Act | ||
csvProduct.MergeFrom(catalogProduct); | ||
|
||
//Assert | ||
Assert.Equal(2, csvProduct.Images.Count); | ||
Assert.NotNull(csvProduct.Images.FirstOrDefault(x => x.Id == "1")); | ||
Assert.NotNull(csvProduct.Images.FirstOrDefault(x => x.Id == "")); | ||
} | ||
|
||
private CatalogProduct GetCatalogProductWithImage() | ||
{ | ||
return new CatalogProduct() | ||
{ | ||
Images = new List<Image>() { new Image() { Id = "1", Url = "SameURL" } }, | ||
Assets = new List<Asset>(), | ||
Reviews = new List<EditorialReview>(), | ||
Properties = new List<Property>(), | ||
SeoInfos = new List<SeoInfo>() | ||
}; | ||
} | ||
|
||
} | ||
} |