33using EPiServer . Commerce . Catalog . ContentTypes ;
44using EPiServer . Core ;
55using EPiServer . DataAccess ;
6+ using EPiServer . Security ;
7+ using Mediachase . Commerce ;
68using Mediachase . Commerce . Catalog ;
79using Microsoft . Extensions . DependencyInjection ;
810using Optimizely . TestContainers . Models . Commerce ;
@@ -12,38 +14,48 @@ namespace OptimizelyTestContainers.Tests;
1214public class CommerceCatalogIntegrationTests ( ) : OptimizelyIntegrationTestBase ( includeCommerce : true )
1315{
1416 [ Fact ]
15- public void Can_Save_Node_And_Product ( )
17+ public void Can_Save_Catalog_And_Node_And_Product ( )
1618 {
17- // Arrange #1
19+ // Arrange
1820 var referenceConverter = Services . GetRequiredService < ReferenceConverter > ( ) ;
1921 var contentRepository = Services . GetRequiredService < IContentRepository > ( ) ;
2022
2123 var rootLink = referenceConverter . GetRootLink ( ) ;
2224
23- var aliensNode = contentRepository . GetDefault < NodeContent > ( rootLink , CultureInfo . GetCultureInfo ( "en" ) ) ;
24- aliensNode . Name = "Aliens" ;
25+ var aliensCatalog = contentRepository . GetDefault < CatalogContent > ( rootLink ) ;
26+ aliensCatalog . Name = "Aliens" ;
27+ aliensCatalog . DefaultCurrency = Currency . USD ;
28+ aliensCatalog . DefaultLanguage = "en" ;
29+ aliensCatalog . WeightBase = "kgs" ; // From WeightBaseSelectionFactory
30+ aliensCatalog . LengthBase = "cm" ; // From LengthBaseSelectionFactory
31+
32+ var alienCatalogReference = contentRepository . Save ( aliensCatalog , SaveAction . Publish , AccessLevel . NoAccess ) ;
33+
34+ var aliensNode = contentRepository . GetDefault < NodeContent > ( alienCatalogReference , CultureInfo . GetCultureInfo ( "en" ) ) ;
35+ aliensNode . Name = "NeuralViz Aliens" ;
2536
26- // Act #1
27- var aliensNodeReference = contentRepository . Save ( aliensNode , SaveAction . Publish ) ;
37+ // Act
38+ var aliensNodeReference = contentRepository . Save ( aliensNode , SaveAction . Publish , AccessLevel . NoAccess ) ;
2839
29- // Arrange #2
40+ // Arrange
3041 var testAlienProduct = contentRepository . GetDefault < TestProduct > ( aliensNodeReference , CultureInfo . GetCultureInfo ( "en" ) ) ;
3142 testAlienProduct . Name = "Snarbo" ;
3243 testAlienProduct . Description = new XhtmlString ( "<p>Some scary facts about Aliens!</p>" ) ;
3344
34- // Act #2
35- var testAlienProductReference = contentRepository . Save ( testAlienProduct , SaveAction . Publish ) ;
45+ // Act
46+ var testAlienProductReference = contentRepository . Save ( testAlienProduct , SaveAction . Publish , AccessLevel . NoAccess ) ;
3647
37- // Assert # 1 & 2
48+ // Assert
3849 Assert . NotNull ( aliensNodeReference ) ;
3950 Assert . NotNull ( testAlienProductReference ) ;
4051
41- // Act #3
52+ // Act
4253 aliensNode = contentRepository . Get < NodeContent > ( aliensNodeReference ) ;
4354 testAlienProduct = contentRepository . Get < TestProduct > ( testAlienProductReference ) ;
4455
45- // Assert #3
46- Assert . Equal ( "Aliens" , aliensNode . Name ) ;
56+ // Assert
57+ Assert . Equal ( "Aliens" , aliensCatalog . Name ) ;
58+ Assert . Equal ( "NeuralViz Aliens" , aliensNode . Name ) ;
4759 Assert . Equal ( "Snarbo" , testAlienProduct . Name ) ;
4860 }
4961}
0 commit comments