forked from Sitecore/ASP.NET-Core-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextFixture.cs
More file actions
42 lines (34 loc) · 1.56 KB
/
ContextFixture.cs
File metadata and controls
42 lines (34 loc) · 1.56 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
using AwesomeAssertions;
using Newtonsoft.Json.Linq;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;
using Xunit;
namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests;
public class ContextFixture
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Can't be done, confuses the compiler types.")]
public static TheoryData<ISitecoreLayoutSerializer> Serializers => new()
{
new JsonLayoutServiceSerializer()
};
[Theory]
[MemberData(nameof(Serializers))]
public void Context_CanBeRead(ISitecoreLayoutSerializer serializer)
{
// Arrange
string json = File.ReadAllText("./Json/edit.json");
dynamic jsonModel = JObject.Parse(json);
// Act
SitecoreLayoutResponseContent? result = serializer.Deserialize(json);
// Assert
Context? resultContext = result?.Sitecore?.Context;
dynamic? expectedContext = jsonModel.sitecore.context;
resultContext.Should().NotBeNull();
resultContext!.IsEditing.Should().Be((bool)expectedContext.pageEditing);
resultContext.Site.Should().NotBeNull();
resultContext.Site!.Name.Should().Be((string)expectedContext.site.name);
resultContext.PageState.Should().Be((PageState)expectedContext.pageState);
resultContext.Language.Should().Be((string)expectedContext.language);
}
}