This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VDS-790: Load product parts of the configurable product with him (#56)
* Generate API client for DemoSolutionFeaturesModule * Regenerate DemoSolutionFeatures API client Right * Add API client and service to IDemoCatalog * Load product parts of configurable product at product loading * Fix code smells * Fix null reference exception * Take into account PR notes * Change ProductIsBuyableSpecification for configurable product case * Remove usings. Use const instead of static props * Fix error with ProductIsBuyableSpecification for configurable products * Fix error. Missing price for Unavailable product * Attempt to fix anonnymous cart merge * Add unit tests for ProductIsBuyableSpecification * Fix code smells * Add comments according to AAA unit tests pattern * Revert "Attempt to fix anonnymous cart merge" This reverts commit 1328380. * Fix merge issues Co-authored-by: Aleksandr Vishniakov <av@virtoway.com> Co-authored-by: Dmitry Pushnitsa <d.pushnitsa@gmail.com>
- Loading branch information
1 parent
795f154
commit 7be9cc0
Showing
20 changed files
with
2,617 additions
and
210 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
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,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace VirtoCommerce.Storefront.Model.Catalog | ||
{ | ||
public partial class Product | ||
{ | ||
public ICollection<ProductPart> Parts { get; set; } = new List<ProductPart>(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
VirtoCommerce.Storefront.Model/Catalog/Demo/ProductTypes.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,11 @@ | ||
namespace VirtoCommerce.Storefront.Model.Catalog.Demo | ||
{ | ||
public static class ProductTypes | ||
{ | ||
public const string Configurable = "Configurable"; | ||
|
||
public const string Physical = "Physical"; | ||
|
||
public const string Digital = "Digital"; | ||
} | ||
} |
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
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
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
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
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
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
153 changes: 153 additions & 0 deletions
153
VirtoCommerce.Storefront.Tests/Catalog/Specifications/ProductIsBuyableSpecificationTests.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,153 @@ | ||
using System; | ||
using Xunit; | ||
using Bogus; | ||
using VirtoCommerce.Storefront.Model.Catalog; | ||
using VirtoCommerce.Storefront.Model.Catalog.Demo; | ||
using VirtoCommerce.Storefront.Model.Common; | ||
using VirtoCommerce.Storefront.Model; | ||
|
||
namespace VirtoCommerce.Storefront.Tests.Catalog.Specifications | ||
{ | ||
public class ProductIsBuyableSpecificationTests | ||
{ | ||
const string CURRENCY_CODE = "USD"; | ||
static readonly Currency Usd = new Currency(Language.InvariantLanguage, CURRENCY_CODE); | ||
static readonly Randomizer Rand = new Randomizer(); | ||
static readonly Faker Faker = new Faker(); | ||
|
||
[Fact] | ||
public void IsSatisfiedBy_NotConfigurable_True() | ||
{ | ||
// arrange | ||
var product = new Product() | ||
{ | ||
ProductType = ProductTypes.Physical, | ||
IsActive = true, | ||
IsBuyable = true, | ||
Price = new ProductPrice(Usd) | ||
{ | ||
ListPrice = new Money(Rand.Decimal(1), Usd) | ||
} | ||
}; | ||
|
||
var spec = new ProductIsBuyableSpecification(); | ||
|
||
// act | ||
var result = spec.IsSatisfiedBy(product); | ||
|
||
// assert | ||
Assert.True(result); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, false, 1, int.MaxValue)] | ||
[InlineData(false, true, 1, int.MaxValue)] | ||
[InlineData(false, false, 1, int.MaxValue)] | ||
[InlineData(false, false, 0, 0)] | ||
[InlineData(true, true, 0, 0)] | ||
public void IsSatisfiedBy_NotConfigurable_False(bool isActive, bool isBuyable, int priceMin, int priceMax) | ||
{ | ||
// arrange | ||
var product = new Product() | ||
{ | ||
ProductType = ProductTypes.Physical, | ||
IsActive = isActive, | ||
IsBuyable = isBuyable, | ||
Price = new ProductPrice(Usd) | ||
{ | ||
ListPrice = new Money(Rand.Decimal(priceMin, priceMax), Usd) | ||
} | ||
}; | ||
|
||
var spec = new ProductIsBuyableSpecification(); | ||
|
||
// act | ||
var result = spec.IsSatisfiedBy(product); | ||
|
||
// assert | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsSatisfiedBy_Configurable_True() | ||
{ | ||
// arrange | ||
var partItemFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Physical); | ||
|
||
var partFaker = new Faker<ProductPart>() | ||
.RuleFor(p => p.Items, f => partItemFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var productFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Configurable) | ||
.RuleFor(p => p.Parts, f => partFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var product = productFaker.Generate(); | ||
|
||
var spec = new ProductIsBuyableSpecification(); | ||
|
||
// act | ||
var result = spec.IsSatisfiedBy(product); | ||
|
||
// assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsSatisfiedBy_ConfigurablePartsIsEmpty_False() | ||
{ | ||
// arrange | ||
var partItemFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Physical); | ||
|
||
var partFaker = new Faker<ProductPart>() | ||
.RuleFor(p => p.Items, f => partItemFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var productFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Configurable) | ||
.RuleFor(p => p.Parts, f => partFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var product = productFaker.Generate(); | ||
|
||
product.Parts = Array.Empty<ProductPart>(); | ||
|
||
var spec = new ProductIsBuyableSpecification(); | ||
|
||
// act | ||
var result = spec.IsSatisfiedBy(product); | ||
|
||
// assert | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsSatisfiedBy_ConfigurableAnyPartItemsIsEmpty_False() | ||
{ | ||
// arrange | ||
var partItemFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Physical); | ||
|
||
var partFaker = new Faker<ProductPart>() | ||
.RuleFor(p => p.Items, f => partItemFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var productFaker = new Faker<Product>() | ||
.RuleFor(p => p.ProductType, f => ProductTypes.Configurable) | ||
.RuleFor(p => p.Parts, f => partFaker.Generate(Rand.Int(1, 5)).ToArray()); | ||
|
||
var product = productFaker.Generate(); | ||
|
||
var part = Faker.PickRandom(product.Parts); | ||
|
||
part.Items= Array.Empty<Product>(); | ||
|
||
var spec = new ProductIsBuyableSpecification(); | ||
|
||
// act | ||
var result = spec.IsSatisfiedBy(product); | ||
|
||
// assert | ||
Assert.False(result); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.