-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommerceCatalogIntegrationTests.cs
More file actions
79 lines (66 loc) · 3.32 KB
/
CommerceCatalogIntegrationTests.cs
File metadata and controls
79 lines (66 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Globalization;
using EPiServer;
using EPiServer.Commerce.Catalog.ContentTypes;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Optimizely.TestContainers.Commerce.Tests.Models.Commerce;
using Optimizely.TestContainers.Shared;
namespace Optimizely.TestContainers.Commerce.Tests;
/// <summary>
/// Integration tests for Commerce catalog functionality (catalogs, nodes, products).
/// Tests Commerce-specific content types and operations.
/// </summary>
[Collection("CommerceCatalogIntegrationTests")]
public class CommerceCatalogIntegrationTests() : OptimizelyIntegrationTestBase(includeCommerce: true)
{
/// <summary>
/// Configure web host with Commerce-specific Startup and services.
/// The base class provides CMS, Commerce, and Find configuration automatically.
/// </summary>
protected override void ConfigureWebHostBuilder(IWebHostBuilder webHostBuilder)
{
// Register the Startup class that configures Commerce services and content types
webHostBuilder.UseStartup<Startup>();
}
[Fact]
public void Can_Save_Catalog_And_Node_And_Product()
{
// Arrange
var referenceConverter = Services.GetRequiredService<ReferenceConverter>();
var contentRepository = Services.GetRequiredService<IContentRepository>();
var rootLink = referenceConverter.GetRootLink();
var aliensCatalog = contentRepository.GetDefault<CatalogContent>(rootLink);
aliensCatalog.Name = "Aliens";
aliensCatalog.DefaultCurrency = Currency.USD;
aliensCatalog.DefaultLanguage = "en";
aliensCatalog.WeightBase = "kgs"; // From WeightBaseSelectionFactory
aliensCatalog.LengthBase = "cm"; // From LengthBaseSelectionFactory
var alienCatalogReference = contentRepository.Save(aliensCatalog, SaveAction.Publish, AccessLevel.NoAccess);
var aliensNode = contentRepository.GetDefault<NodeContent>(alienCatalogReference, CultureInfo.GetCultureInfo("en"));
aliensNode.Name = "NeuralViz Aliens";
// Act
var aliensNodeReference = contentRepository.Save(aliensNode, SaveAction.Publish, AccessLevel.NoAccess);
// Arrange
var testAlienProduct = contentRepository.GetDefault<TestProduct>(aliensNodeReference, CultureInfo.GetCultureInfo("en"));
testAlienProduct.Name = "Snarbo";
testAlienProduct.Description = new XhtmlString("<p>Some scary facts about Aliens!</p>");
// Act
var testAlienProductReference = contentRepository.Save(testAlienProduct, SaveAction.Publish, AccessLevel.NoAccess);
// Assert
Assert.NotNull(aliensNodeReference);
Assert.NotNull(testAlienProductReference);
// Act
aliensCatalog = contentRepository.Get<CatalogContent>(alienCatalogReference);
aliensNode = contentRepository.Get<NodeContent>(aliensNodeReference);
testAlienProduct = contentRepository.Get<TestProduct>(testAlienProductReference);
// Assert
Assert.Equal("Aliens", aliensCatalog.Name);
Assert.Equal("NeuralViz Aliens", aliensNode.Name);
Assert.Equal("Snarbo", testAlienProduct.Name);
}
}