Skip to content

Commit e3b1c3e

Browse files
committed
Merge branch 'release/1.0.0-rc4'
2 parents d6e7da3 + 9b4359a commit e3b1c3e

11 files changed

+96
-119
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Wilcommerce Catalog contains all the components to build a catalog system.
33

44
## Installation
5-
Nuget package available here [https://www.nuget.org/packages/Wilcommerce.Catalog/1.0.0-rc3](https://www.nuget.org/packages/Wilcommerce.Catalog/1.0.0-rc3)
5+
Nuget package available here [https://www.nuget.org/packages/Wilcommerce.Catalog/1.0.0-rc4](https://www.nuget.org/packages/Wilcommerce.Catalog/1.0.0-rc4)
66

77
## Models
88
The **Models** namespace contains all the classes representing the components useful for building a catalog (i.e. Category, Product, Brand, etc.).

Wilcommerce.Catalog.Test/Models/CatalogSettingsTest.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void CatalogSettingsFactory_Should_Throw_ArgumentException_If_CategoriesP
1616
CatalogSettings.ViewType.LIST
1717
));
1818

19-
Assert.Equal("category per page cannot be less than zero", ex.Message);
19+
Assert.Equal("categoriesPerPage", ex.ParamName);
2020
}
2121

2222
[Fact]
@@ -29,7 +29,7 @@ public void CatalogSettingsFactory_Should_Throw_ArgumentException_If_ProductsPer
2929
CatalogSettings.ViewType.LIST
3030
));
3131

32-
Assert.Equal("products per page cannot be less than zero", ex.Message);
32+
Assert.Equal("productsPerPage", ex.ParamName);
3333
}
3434

3535
[Fact]
@@ -43,7 +43,7 @@ public void SetCategoriesPerPage_Should_Throw_ArgumentException_If_CategoriesPer
4343
);
4444

4545
var ex = Assert.Throws<ArgumentException>(() => settings.SetCategoriesPerPage(-1));
46-
Assert.Equal("category per page cannot be less than zero", ex.Message);
46+
Assert.Equal("categoriesPerPage", ex.ParamName);
4747
}
4848

4949
[Fact]
@@ -57,7 +57,7 @@ public void SetProductsPerPage_Should_Throw_ArgumentException_If_ProductsPerPage
5757
);
5858

5959
var ex = Assert.Throws<ArgumentException>(() => settings.SetProductsPerPage(-1));
60-
Assert.Equal("products per page cannot be less than zero", ex.Message);
60+
Assert.Equal("productsPerPage", ex.ParamName);
6161
}
6262

6363
[Fact]
@@ -73,7 +73,7 @@ public void SetProductReviewsPerPage_Should_Throw_ArgumentException_If_ReviewsPe
7373
settings.AllowProductReviews(true);
7474

7575
var ex = Assert.Throws<ArgumentException>(() => settings.SetProductReviewsPerPage(-1));
76-
Assert.Equal("reviews per page cannot be less than zero", ex.Message);
76+
Assert.Equal("reviewsPerPage", ex.ParamName);
7777
}
7878

7979
[Fact]

Wilcommerce.Catalog.Test/Models/CategoryTest.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void Category_SetAsVisible_Should_Fail_If_VisibleTo_Is_Previous_Than_Visi
8484
}
8585

8686
[Fact]
87-
public void Category_AddChildren_Should_Fail_If_Children_IsNull()
87+
public void Category_AddChild_Should_Fail_If_Children_IsNull()
8888
{
8989
var category = Category.Create(
9090
"TEST1",
@@ -94,32 +94,32 @@ public void Category_AddChildren_Should_Fail_If_Children_IsNull()
9494

9595
var ex = Assert.Throws<ArgumentNullException>(() => category.AddChild(null));
9696

97-
Assert.Equal("children", ex.ParamName);
97+
Assert.Equal("child", ex.ParamName);
9898
}
9999

100100
[Fact]
101-
public void Category_AddChildren_Should_Fail_If_Children_Is_Already_InCollection()
101+
public void Category_AddChild_Should_Fail_If_Children_Is_Already_InCollection()
102102
{
103103
var category = Category.Create(
104104
"TEST1",
105105
"Test Category",
106106
"test-category"
107107
);
108108

109-
var children = Category.Create(
109+
var child = Category.Create(
110110
"TEST2",
111111
"Children Category",
112112
"children-category"
113113
);
114114

115-
category.AddChild(children);
115+
category.AddChild(child);
116116

117-
var ex = Assert.Throws<ArgumentException>(() => category.AddChild(children));
117+
var ex = Assert.Throws<ArgumentException>(() => category.AddChild(child));
118118
Assert.Equal("The category contains the children yet", ex.Message);
119119
}
120120

121121
[Fact]
122-
public void Category_AddChildren_Should_Increment_ChildrenNumber()
122+
public void Category_AddChild_Should_Increment_ChildrenNumber()
123123
{
124124
var category = Category.Create(
125125
"TEST1",
@@ -129,13 +129,13 @@ public void Category_AddChildren_Should_Increment_ChildrenNumber()
129129

130130
int childrenCount = category.Children.Count();
131131

132-
var children = Category.Create(
132+
var child = Category.Create(
133133
"TEST2",
134134
"Children Category",
135135
"children-category"
136136
);
137137

138-
category.AddChild(children);
138+
category.AddChild(child);
139139

140140
Assert.Equal(childrenCount + 1, category.Children.Count());
141141
}

Wilcommerce.Catalog.Test/Models/ProductTest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void SetUnitInStock_Should_Throw_ArgumentException_If_Unit_IsLessThan_Zer
110110
);
111111

112112
var ex = Assert.Throws<ArgumentException>(() => product.SetUnitInStock(-1));
113-
Assert.Equal("Stock unit cannot be less than zero", ex.Message);
113+
Assert.Equal("unitInStock", ex.ParamName);
114114
}
115115

116116
[Theory]
@@ -224,7 +224,7 @@ public void SetPrice_Should_Throw_ArgumentException_If_Price_Amount_IsLessThan_Z
224224
};
225225

226226
var ex = Assert.Throws<ArgumentException>(() => product.SetPrice(price));
227-
Assert.Equal("Price amount cannot be less than zero", ex.Message);
227+
Assert.Equal(nameof(price), ex.ParamName);
228228
}
229229

230230
[Fact]
@@ -353,7 +353,7 @@ public void Product_AddCategory_Throws_ArgumentException_If_Category_Is_Already_
353353
product.AddCategory(category);
354354

355355
var ex = Assert.Throws<ArgumentException>(() => product.AddCategory(category));
356-
Assert.Equal("The category is already in collection", ex.Message);
356+
Assert.Equal(nameof(category), ex.ParamName);
357357
}
358358

359359
[Fact]
@@ -455,7 +455,7 @@ public void Product_AddVariant_Should_Throw_ArgumentException_If_PriceAmount_IsL
455455
var price = new Currency { Code = "EUR", Amount = -10 };
456456
var ex = Assert.Throws<ArgumentException>(() => product.AddVariant("name", "ean", "sku", price));
457457

458-
Assert.Equal("Price amount cannot be less than zero", ex.Message);
458+
Assert.Equal(nameof(price), ex.ParamName);
459459
}
460460

461461
[Fact]

Wilcommerce.Catalog.Test/Wilcommerce.Catalog.Test.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<AssemblyName>Wilcommerce.Catalog.Test</AssemblyName>
66
<PackageId>Wilcommerce.Catalog.Test</PackageId>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -17,7 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
2121
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
2222
<PackageReference Include="xunit" Version="2.3.1" />
2323
</ItemGroup>

src/Wilcommerce.Catalog/Models/Brand.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public class Brand : IAggregateRoot
1919
/// <summary>
2020
/// Construct the brand
2121
/// </summary>
22-
protected Brand() { }
22+
protected Brand()
23+
{
24+
Logo = new Image();
25+
Seo = new SeoData();
26+
}
2327
#endregion
2428

2529
#region Properties
@@ -68,7 +72,7 @@ public virtual void ChangeName(string name)
6872
{
6973
if (string.IsNullOrEmpty(name))
7074
{
71-
throw new ArgumentNullException("name");
75+
throw new ArgumentNullException(nameof(name));
7276
}
7377

7478
Name = name;
@@ -82,7 +86,7 @@ public virtual void ChangeDescription(string description)
8286
{
8387
if (string.IsNullOrEmpty(description))
8488
{
85-
throw new ArgumentNullException("description");
89+
throw new ArgumentNullException(nameof(description));
8690
}
8791

8892
Description = description;
@@ -96,7 +100,7 @@ public virtual void ChangeUrl(string url)
96100
{
97101
if (string.IsNullOrEmpty(url))
98102
{
99-
throw new ArgumentNullException("url");
103+
throw new ArgumentNullException(nameof(url));
100104
}
101105

102106
Url = url;
@@ -108,12 +112,7 @@ public virtual void ChangeUrl(string url)
108112
/// <param name="logo">The logo image</param>
109113
public virtual void SetLogo(Image logo)
110114
{
111-
if (logo == null)
112-
{
113-
throw new ArgumentNullException("logo");
114-
}
115-
116-
Logo = logo;
115+
Logo = logo ?? throw new ArgumentNullException(nameof(logo));
117116
}
118117

119118
/// <summary>
@@ -122,12 +121,7 @@ public virtual void SetLogo(Image logo)
122121
/// <param name="seo">The seo data</param>
123122
public virtual void SetSeoData(SeoData seo)
124123
{
125-
if (seo == null)
126-
{
127-
throw new ArgumentNullException("seo");
128-
}
129-
130-
Seo = seo;
124+
Seo = seo ?? throw new ArgumentNullException(nameof(seo));
131125
}
132126

133127
/// <summary>
@@ -168,12 +162,12 @@ public static Brand Create(string name, string url)
168162
{
169163
if (string.IsNullOrEmpty(name))
170164
{
171-
throw new ArgumentNullException("name");
165+
throw new ArgumentNullException(nameof(name));
172166
}
173167

174168
if (string.IsNullOrEmpty(url))
175169
{
176-
throw new ArgumentNullException("url");
170+
throw new ArgumentNullException(nameof(url));
177171
}
178172

179173
var brand = new Brand

src/Wilcommerce.Catalog/Models/CatalogSettings.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public virtual void SetCategoriesPerPage(int categoriesPerPage)
8585
{
8686
if (categoriesPerPage < 0)
8787
{
88-
throw new ArgumentException("category per page cannot be less than zero");
88+
throw new ArgumentException("category per page cannot be less than zero", nameof(categoriesPerPage));
8989
}
9090

9191
CategoriesPerPage = categoriesPerPage;
@@ -99,7 +99,7 @@ public virtual void SetProductsPerPage(int productsPerPage)
9999
{
100100
if (productsPerPage < 0)
101101
{
102-
throw new ArgumentException("products per page cannot be less than zero");
102+
throw new ArgumentException("products per page cannot be less than zero", nameof(productsPerPage));
103103
}
104104

105105
ProductsPerPage = productsPerPage;
@@ -113,7 +113,7 @@ public virtual void SetProductReviewsPerPage(int reviewsPerPage)
113113
{
114114
if (reviewsPerPage < 0)
115115
{
116-
throw new ArgumentException("reviews per page cannot be less than zero");
116+
throw new ArgumentException("reviews per page cannot be less than zero", nameof(reviewsPerPage));
117117
}
118118

119119
if (!ProductReviewsAllowed)
@@ -157,12 +157,12 @@ public static CatalogSettings Create(int categoriesPerPage, int productsPerPage,
157157
{
158158
if (categoriesPerPage < 0)
159159
{
160-
throw new ArgumentException("category per page cannot be less than zero");
160+
throw new ArgumentException("category per page cannot be less than zero", nameof(categoriesPerPage));
161161
}
162162

163163
if (productsPerPage < 0)
164164
{
165-
throw new ArgumentException("products per page cannot be less than zero");
165+
throw new ArgumentException("products per page cannot be less than zero", nameof(productsPerPage));
166166
}
167167

168168
return new CatalogSettings

src/Wilcommerce.Catalog/Models/Category.cs

+11-20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected Category()
3636
{
3737
_children = new HashSet<Category>();
3838
_products = new HashSet<ProductCategory>();
39+
Seo = new SeoData();
3940
}
4041
#endregion
4142

@@ -164,7 +165,7 @@ public virtual void AddChild(Category child)
164165
{
165166
if (child == null)
166167
{
167-
throw new ArgumentNullException("children");
168+
throw new ArgumentNullException(nameof(child));
168169
}
169170

170171
if (_children.Contains(child))
@@ -183,7 +184,7 @@ public virtual void ChangeName(string name)
183184
{
184185
if (string.IsNullOrEmpty(name))
185186
{
186-
throw new ArgumentNullException("name");
187+
throw new ArgumentNullException(nameof(name));
187188
}
188189

189190
Name = name;
@@ -197,7 +198,7 @@ public virtual void ChangeCode(string code)
197198
{
198199
if (string.IsNullOrEmpty(code))
199200
{
200-
throw new ArgumentNullException("code");
201+
throw new ArgumentNullException(nameof(code));
201202
}
202203

203204
Code = code;
@@ -211,7 +212,7 @@ public virtual void ChangeDescription(string description)
211212
{
212213
if (string.IsNullOrEmpty(description))
213214
{
214-
throw new ArgumentNullException("description");
215+
throw new ArgumentNullException(nameof(description));
215216
}
216217

217218
Description = description;
@@ -225,7 +226,7 @@ public virtual void ChangeUrl(string url)
225226
{
226227
if (string.IsNullOrEmpty(url))
227228
{
228-
throw new ArgumentNullException("url");
229+
throw new ArgumentNullException(nameof(url));
229230
}
230231

231232
Url = url;
@@ -237,12 +238,7 @@ public virtual void ChangeUrl(string url)
237238
/// <param name="parent">The parent category</param>
238239
public virtual void SetParentCategory(Category parent)
239240
{
240-
if (parent == null)
241-
{
242-
throw new ArgumentNullException("parent");
243-
}
244-
245-
Parent = parent;
241+
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
246242
}
247243

248244
/// <summary>
@@ -303,12 +299,7 @@ public virtual void RemoveParent()
303299
/// <param name="seo">The seo information</param>
304300
public virtual void SetSeoData(SeoData seo)
305301
{
306-
if (seo == null)
307-
{
308-
throw new ArgumentNullException("seo");
309-
}
310-
311-
Seo = seo;
302+
Seo = seo ?? throw new ArgumentNullException(nameof(seo));
312303
}
313304

314305
#endregion
@@ -325,17 +316,17 @@ public static Category Create(string code, string name, string url)
325316
{
326317
if (string.IsNullOrEmpty(code))
327318
{
328-
throw new ArgumentNullException("code");
319+
throw new ArgumentNullException(nameof(code));
329320
}
330321

331322
if (string.IsNullOrEmpty(name))
332323
{
333-
throw new ArgumentNullException("name");
324+
throw new ArgumentNullException(nameof(name));
334325
}
335326

336327
if (string.IsNullOrEmpty(url))
337328
{
338-
throw new ArgumentNullException("url");
329+
throw new ArgumentNullException(nameof(url));
339330
}
340331

341332
var category = new Category

0 commit comments

Comments
 (0)