Skip to content

Commit

Permalink
Merge pull request #142 from Lombiq/issue/OCC-245
Browse files Browse the repository at this point in the history
OCC-245: Update OC preview version and fix breaking changes
  • Loading branch information
Piedone authored Jul 28, 2024
2 parents 4eb691f + bc78c58 commit 8bc5f50
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 45 deletions.
10 changes: 5 additions & 5 deletions Lombiq.TrainingDemo.Tests/Services/TestedServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ public void NonExistingContentItemsShouldThrow()

mocker
.GetMock<IContentManager>()
.Verify(contentManager => contentManager.GetAsync(It.Is<string>(id => id == TestContentId)));
.Verify(contentManager => contentManager.GetAsync(It.Is<string>(id => id == TestContentId), It.IsAny<VersionOptions>()));
}

[Fact]
public async Task ContentItemsAreRetrieved()
{
// In this test we'll mock IContentManager so it actually returns something we can then verify.
// In this test we'll mock IContentManager, so it actually returns something we can then verify.

var service = CreateTestedService(out var mocker);

// Setting up an IContentManager mock that'll return a basic ContentItem placeholder.
mocker
.GetMock<IContentManager>()
.Setup(contentManager => contentManager.GetAsync(It.IsAny<string>()))
.ReturnsAsync<string, IContentManager, ContentItem>(id => new ContentItem { ContentItemId = id });
.Setup(contentManager => contentManager.GetAsync(It.IsAny<string>(), It.IsAny<VersionOptions>()))
.ReturnsAsync<string, VersionOptions, IContentManager, ContentItem>((id, _) => new ContentItem { ContentItemId = id });

var contentItem = await service.GetContentItemOrThrowAsync(TestContentId);

Expand All @@ -71,7 +71,7 @@ private static TestedService CreateTestedService(out AutoMocker mocker)
// We're using a library called AutoMocker here. It extends the Moq mocking library with the ability to
// automatically substitute injected dependencies with a mocked instance. It's a bit like a special dependency
// injection container. This way, your tested classes will get all their dependencies injected even if you don't
// explicitly register a mock or stub for the.
// explicitly register a mock or stub.

mocker = new AutoMocker();
return mocker.CreateInstance<TestedService>();
Expand Down
7 changes: 3 additions & 4 deletions Lombiq.TrainingDemo.Web/Lombiq.TrainingDemo.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Logging.NLog" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="1.8.3" />
<PackageReference Include="OrchardCore.Logging.NLog" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="2.0.0-preview-18282" />
<!-- This reference is not strictly needed here but included so if the web and the module projects' Orchard Core
versions go out of sync, the CI build's package consolidation validation will fail. -->
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18282" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.TrainingDemo.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
.UseStaticFiles()
.UseOrchardCore();

app.Run();
await app.RunAsync();
7 changes: 1 addition & 6 deletions Lombiq.TrainingDemo/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ namespace Lombiq.TrainingDemo.Controllers;
// endpoints should most of the time use the "Api" authentication scheme: This is not the same that standard users are
// authenticated with (via cookies).
[Authorize(AuthenticationSchemes = "Api"), IgnoreAntiforgeryToken, AllowAnonymous]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Major Code Smell",
"S6961:API Controllers should derive from ControllerBase instead of Controller",
Justification = "Can't be changed due to line 62. Will be applicable after an Orchard upgrade due to " +
"https://github.com/OrchardCMS/OrchardCore/issues/16186 being fixed.")]
public class ApiController : Controller
public class ApiController : ControllerBase
{
private readonly IAuthorizationService _authorizationService;
private readonly IContentManager _contentManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CrossTenantServicesController : Controller
// A simple route for convenience. You can access this from under /CrossTenantServices?contentItemId=ID. Here ID
// needs to be a content item ID that you can get e.g. from the URL when you open an item to edit from the admin (it
// looks something like "4da2sme18cc2k2r5d4w23d4cwj" which is NOT made by a cat walking across the keyboard!).
[Route("CrossTenantServices")]
[HttpGet, Route("CrossTenantServices")]
public async Task<string> Index(string contentItemId)
{
// If ModelState is not in a valid state we should abort the action and return null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ActionResult Index()
}

// Let's see some custom routing here. This attribute will override the default route and use this one.
[Route("TrainingDemo/NotifyMe")]
[HttpGet, Route("TrainingDemo/NotifyMe")]
public async Task<IActionResult> NotifyMe()
{
// ILogger is an ASP.NET Core service that will write something into the specific log files. In Orchard Core
Expand Down
14 changes: 7 additions & 7 deletions Lombiq.TrainingDemo/GraphQL/Services/ContentItemTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ContentItemTypeBuilder : IContentTypeBuilder

// Here you can add arguments to every Content Type (top level) field.
public void Build(
ISchema schema,
FieldType contentQuery,
ContentTypeDefinition contentTypeDefinition,
ContentItemType contentItemType)
Expand All @@ -26,11 +27,7 @@ public void Build(

// The resolved type can be anything that can be represented with JSON and has a known graph type, but we stick
// with numbers for simplicity's sake. This one filters for equation.
contentQuery.Arguments.Add(new QueryArgument<IntGraphType>
{
Name = AgeFilterName,
ResolvedType = new IntGraphType(),
});
AddFilter(contentQuery, suffix: string.Empty);

// You can't use special characters in the argument names so by GraphQL convention these two letter suffixes
// that represent the relational operators. Except equation which customarily gets no suffix.
Expand All @@ -43,12 +40,15 @@ public void Build(
AddFilter(contentQuery, "_ne");
}

private static void AddFilter(FieldType contentQuery, string suffix) =>
contentQuery.Arguments.Add(new QueryArgument<IntGraphType>
private static void AddFilter(FieldType contentQuery, string suffix)
{
contentQuery.Arguments ??= [];
contentQuery.Arguments!.Add(new QueryArgument<IntGraphType>
{
Name = AgeFilterName + suffix,
ResolvedType = new IntGraphType(),
});
}
}

// NEXT STATION: Services/PersonAgeGraphQLFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Task<IEnumerable<ContentItem>> PostQueryAsync(
IResolveFieldContext context)
{
var (name, value) = context.Arguments.FirstOrDefault(
argument => argument.Key.StartsWith(AgeFilterName, StringComparison.Ordinal));
argument => argument.Value.Value is int && argument.Key.StartsWithOrdinal(AgeFilterName));

if (name != null && value.Value is int age)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@ public PersonPartObjectGraphType()
}
}

// Warning: There seems to be a bug when your query includes the built-in "biography" field before the "person" field.
// If you do it the other way around it works though. You can track the issue here:
// https://github.com/OrchardCMS/OrchardCore/issues/10181

// NEXT STATION: Services/PersonPartWhereInputObjectGraphType.cs
30 changes: 15 additions & 15 deletions Lombiq.TrainingDemo/Lombiq.TrainingDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="OrchardCore.Users.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Workflows.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.BackgroundTasks" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Data.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DynamicCache" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.FileStorage.FileSystem" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Indexing.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Users.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Workflows.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.BackgroundTasks" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Data.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.DynamicCache" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.FileStorage.FileSystem" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Indexing.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18282" />
<!-- Note that you need to add a reference to OrchardCore.ResourceManagement for the basic tag helpers like <style>
and <script> to properly work when the app is built for production (and thus Razor Runtime Compilation is turned
off. OrchardCore.DisplayManagement is needed for a variety of things but also for the <shape> tag helper for the
same reason. -->
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18282" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18282" />
</ItemGroup>

<!-- This module requires Lombiq.HelpfulLibraries.OrchardCore, and it can be included two ways. The PackageReference
Expand All @@ -51,7 +51,7 @@
</ItemGroup>

<ItemGroup Condition="!Exists('..\..\..\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.OrchardCore\Lombiq.HelpfulLibraries.OrchardCore.csproj')">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.1-alpha.2.occ-245" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="OrchardCorePreview" value="https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json" />
<add key="LombiqPreview" value="https://nuget.cloudsmith.io/lombiq/open-source-orchard-core-extensions/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit 8bc5f50

Please sign in to comment.