Skip to content

Commit 5cd7569

Browse files
Optimizely Commerce testing (#3)
- Use one container with named databases and fix connection string issues - Add Catalog and make commerce tests pass - Split into two projects with separate assemblies to make initialization work for both Commerce and Cms - Include shared library to make commerce tests green - Removed example project and moved startup class to separate projects to not have to feature switch at all - Move nuget.config to root folder
1 parent add3afc commit 5cd7569

File tree

43 files changed

+413
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+413
-272
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Globalization;
2+
using EPiServer;
3+
using EPiServer.Commerce.Catalog.ContentTypes;
4+
using EPiServer.Core;
5+
using EPiServer.DataAccess;
6+
using EPiServer.Security;
7+
using Mediachase.Commerce;
8+
using Mediachase.Commerce.Catalog;
9+
using Microsoft.AspNetCore.Hosting;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Optimizely.TestContainers.Commerce.Tests.Models.Commerce;
12+
using Optimizely.TestContainers.Shared;
13+
14+
namespace Optimizely.TestContainers.Commerce.Tests;
15+
16+
public class CommerceCatalogIntegrationTests() : OptimizelyIntegrationTestBase(includeCommerce: true)
17+
{
18+
protected override void ConfiureWebHostBuilder(IWebHostBuilder webHostBuilder)
19+
{
20+
webHostBuilder.UseStartup<Startup>();
21+
}
22+
23+
[Fact]
24+
public void Can_Save_Catalog_And_Node_And_Product()
25+
{
26+
// Arrange
27+
var referenceConverter = Services.GetRequiredService<ReferenceConverter>();
28+
var contentRepository = Services.GetRequiredService<IContentRepository>();
29+
30+
var rootLink = referenceConverter.GetRootLink();
31+
32+
var aliensCatalog = contentRepository.GetDefault<CatalogContent>(rootLink);
33+
aliensCatalog.Name = "Aliens";
34+
aliensCatalog.DefaultCurrency = Currency.USD;
35+
aliensCatalog.DefaultLanguage = "en";
36+
aliensCatalog.WeightBase = "kgs"; // From WeightBaseSelectionFactory
37+
aliensCatalog.LengthBase = "cm"; // From LengthBaseSelectionFactory
38+
39+
var alienCatalogReference = contentRepository.Save(aliensCatalog, SaveAction.Publish, AccessLevel.NoAccess);
40+
41+
var aliensNode = contentRepository.GetDefault<NodeContent>(alienCatalogReference, CultureInfo.GetCultureInfo("en"));
42+
aliensNode.Name = "NeuralViz Aliens";
43+
44+
// Act
45+
var aliensNodeReference = contentRepository.Save(aliensNode, SaveAction.Publish, AccessLevel.NoAccess);
46+
47+
// Arrange
48+
var testAlienProduct = contentRepository.GetDefault<TestProduct>(aliensNodeReference, CultureInfo.GetCultureInfo("en"));
49+
testAlienProduct.Name = "Snarbo";
50+
testAlienProduct.Description = new XhtmlString("<p>Some scary facts about Aliens!</p>");
51+
52+
// Act
53+
var testAlienProductReference = contentRepository.Save(testAlienProduct, SaveAction.Publish, AccessLevel.NoAccess);
54+
55+
// Assert
56+
Assert.NotNull(aliensNodeReference);
57+
Assert.NotNull(testAlienProductReference);
58+
59+
// Act
60+
aliensNode = contentRepository.Get<NodeContent>(aliensNodeReference);
61+
testAlienProduct = contentRepository.Get<TestProduct>(testAlienProductReference);
62+
63+
// Assert
64+
Assert.Equal("Aliens", aliensCatalog.Name);
65+
Assert.Equal("NeuralViz Aliens", aliensNode.Name);
66+
Assert.Equal("Snarbo", testAlienProduct.Name);
67+
}
68+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using EPiServer.Commerce.Catalog.ContentTypes;
3+
using EPiServer.Commerce.Catalog.DataAnnotations;
4+
using EPiServer.Core;
5+
using EPiServer.DataAbstraction;
6+
using EPiServer.DataAnnotations;
7+
8+
namespace Optimizely.TestContainers.Commerce.Tests.Models.Commerce;
9+
10+
[CatalogContentType(
11+
GUID = "0B06DE9B-6AE3-40FB-909E-E718CCC260AE",
12+
DisplayName = "Test Product",
13+
Description = "Test product for integration tests.")]
14+
public class TestProduct : ProductContent
15+
{
16+
[Display(
17+
Name = "Description",
18+
GroupName = SystemTabNames.Content,
19+
Order = 1)]
20+
[Searchable]
21+
[CultureSpecific]
22+
[Tokenize]
23+
[IncludeInDefaultSearch]
24+
public virtual XhtmlString? Description { get; set; }
25+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
15+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="coverlet.collector" Version="6.0.4">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="EPiServer.CMS" Version="12.33.1" />
24+
<PackageReference Include="EPiServer.Commerce" Version="14.40.0" />
25+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
26+
<PackageReference Include="Testcontainers.MsSql" Version="4.6.0" />
27+
<PackageReference Include="xunit" Version="2.9.3" />
28+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
29+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
30+
<PrivateAssets>all</PrivateAssets>
31+
</PackageReference>
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<Using Include="Xunit" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\Optimizely.TestContainers.Shared\Optimizely.TestContainers.Shared.csproj" />
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<None Update="DefaultSiteContent.episerverdata">
44+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45+
</None>
46+
</ItemGroup>
47+
48+
<ItemGroup>
49+
<Folder Include="Models\" />
50+
</ItemGroup>
51+
52+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using EPiServer.Cms.Shell;
2+
using EPiServer.Cms.UI.AspNetIdentity;
3+
using EPiServer.Scheduler;
4+
using EPiServer.Web.Routing;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
9+
10+
namespace Optimizely.TestContainers.Commerce.Tests;
11+
12+
public class Startup(IWebHostEnvironment webHostingEnvironment)
13+
{
14+
public void ConfigureServices(IServiceCollection services)
15+
{
16+
if (webHostingEnvironment.IsDevelopment())
17+
{
18+
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(webHostingEnvironment.ContentRootPath, "App_Data"));
19+
20+
services.Configure<SchedulerOptions>(options => options.Enabled = false);
21+
}
22+
23+
services
24+
.AddCmsAspNetIdentity<ApplicationUser>()
25+
.AddCms()
26+
.AddCommerce()
27+
.AddAdminUserRegistration()
28+
.AddEmbeddedLocalization<Startup>();
29+
}
30+
31+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
32+
{
33+
if (env.IsDevelopment())
34+
{
35+
app.UseDeveloperExceptionPage();
36+
}
37+
38+
app.UseStaticFiles();
39+
app.UseRouting();
40+
app.UseAuthentication();
41+
app.UseAuthorization();
42+
43+
app.UseEndpoints(endpoints =>
44+
{
45+
endpoints.MapContent();
46+
});
47+
}
48+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)