Skip to content

Commit

Permalink
Fix for rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 20, 2023
1 parent 2330fa6 commit a2bd561
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.user
*.vs
*.log
*.received.txt

.vs
.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class ConfigurationService : IConfigurationService

private sealed class ConfigurationModel
{
public Dictionary<string, ConfiguredApp> Apps { get; } = new Dictionary<string, ConfiguredApp>();
public Dictionary<string, ConfiguredApp> Apps { get; } = [];

public string? CurrentApp { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace Squidex.CLI.Configuration;

public sealed class ConfigurationStore : IConfigurationStore
{
private readonly JsonSerializer jsonSerializer = new JsonSerializer();
private readonly JsonSerializer jsonSerializer = new JsonSerializer
{
Formatting = Formatting.Indented,
};
private DirectoryInfo workingDirectory;

public DirectoryInfo WorkingDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,60 @@ namespace Squidex.ClientLibrary.Tests;

public class ContentQueryTests
{
private readonly SquidexOptions options = new SquidexOptions();

[Fact]
public void Should_create_query_for_empty_query()
{
var query = new ContentQuery().ToQuery(true);
var query = new ContentQuery().ToQuery(true, options);

Assert.Empty(query);
}

[Fact]
public void Should_create_query_for_top()
{
var query = new ContentQuery { Top = 10 }.ToQuery(true);
var query = new ContentQuery { Top = 10 }.ToQuery(true, options);

Assert.Equal("?$top=10", query);
}

[Fact]
public void Should_create_query_for_skip()
{
var query = new ContentQuery { Skip = 10 }.ToQuery(true);
var query = new ContentQuery { Skip = 10 }.ToQuery(true, options);

Assert.Equal("?$skip=10", query);
}

[Fact]
public void Should_create_query_for_skip_and_top()
{
var query = new ContentQuery { Skip = 20, Top = 10 }.ToQuery(true);
var query = new ContentQuery { Skip = 20, Top = 10 }.ToQuery(true, options);

Assert.Equal("?$skip=20&$top=10", query);
}

[Fact]
public void Should_create_query_for_filter()
{
var query = new ContentQuery { Filter = "my-filter" }.ToQuery(true);
var query = new ContentQuery { Filter = "my-filter" }.ToQuery(true, options);

Assert.Equal("?$filter=my-filter", query);
}

[Fact]
public void Should_create_query_for_search()
{
var query = new ContentQuery { Search = "my-search" }.ToQuery(true);
var query = new ContentQuery { Search = "my-search" }.ToQuery(true, options);

Assert.Equal("?$search=\"my-search\"", query);
}

[Fact]
public void Should_create_query_for_search_and_filter()
{
var query = new ContentQuery { Search = "my-search", Filter = "my-filter" }.ToQuery(true);
var query = new ContentQuery { Search = "my-search", Filter = "my-filter" }.ToQuery(true, options);

Assert.Equal("?$search=\"my-search\"&$filter=my-filter", query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Squidex.ClientLibrary.EnrichedEvents;
using Xunit;

namespace Squidex.ClientLibrary.Tests.EnrichedEvents;

[UsesVerify]
public class EnrichedEventsTests
{

private readonly SquidexOptions options = new SquidexOptions();

public class SchemaData
{
[JsonConverter(typeof(InvariantConverter))]
Expand All @@ -24,143 +29,107 @@ public class Schema : Content<SchemaData>
{
}

private const string JsonEnrichedContentEvent = @"{
'type': 'SchemaUpdated',
'payload': {
'$type': 'EnrichedContentEvent',
'id': '062b936f-7496-4f87-bd4f-ba7bbb63c751',
'actor': 'subject:601c2cbafa4e669f214c0438',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'created': '2021-01-01T00:00:00Z',
'createdBy': 'subject:601c2cbafa4e669f214c0438',
'lastModified': '2021-01-01T00:01:00Z',
'lastModifiedBy': 'subject:601c2cbafa4e669f214c0438',
'name': 'SchemaUpdated',
'partition': -792991992,
'schemaId': '062b936f-7496-4f87-bd4f-ba7bbb63c751,schema',
'status': 'Published',
'timestamp': '2021-01-01T00:01:00Z',
'type': 'Updated',
'version': 3,
'data': {
'testField': {
'iv': 'test2'
}
},
'dataOld': {
'testField': {
'iv': 'test'
}
private static readonly string JsonEnrichedContentEvent = @"{
'type': 'SchemaUpdated',
'payload': {
'$type': 'EnrichedContentEvent',
'id': '062b936f-7496-4f87-bd4f-ba7bbb63c751',
'actor': 'subject:601c2cbafa4e669f214c0438',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'created': '2021-01-01T00:00:00Z',
'createdBy': 'subject:601c2cbafa4e669f214c0438',
'lastModified': '2021-01-01T00:01:00Z',
'lastModifiedBy': 'subject:601c2cbafa4e669f214c0438',
'name': 'SchemaUpdated',
'partition': -792991992,
'schemaId': '062b936f-7496-4f87-bd4f-ba7bbb63c751,schema',
'status': 'Published',
'timestamp': '2021-01-01T00:01:00Z',
'type': 'Updated',
'version': 3,
'data': {
'testField': {
'iv': 'test2'
}
},
'timestamp': '2021-01-01T00:01:00Z'
}";
'dataOld': {
'testField': {
'iv': 'test'
}
}
},
'timestamp': '2021-01-01T00:01:00Z'
}";

[Fact]
public void Should_deserialize_EnrichedContentEvent()
public async void Should_deserialize_EnrichedContentEvent()
{
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedContentEvent);
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedContentEvent, options);

Assert.True(envelope.Payload is EnrichedContentEvent);

var contentEvent = (EnrichedContentEvent)envelope.Payload;

Assert.Equal("SchemaUpdated", contentEvent.Name);
Assert.Equal("testapp", contentEvent.App.Name);
Assert.Equal("601c2cbafa4e669f214c0438", contentEvent.Actor.Id);
Assert.Equal(typeof(JObject), contentEvent.Data.GetType());

switch (contentEvent.Schema.Name)
{
case "schema":
var res = contentEvent.ToTyped<SchemaData>();

Assert.Equal(typeof(EnrichedContentEvent<SchemaData>), res.GetType());
Assert.Equal(typeof(SchemaData), res.Data.GetType());

Assert.Equal("test2", res.Data.TestField);
Assert.Equal("test", res.DataOld.TestField);
break;
default: throw new Exception("Unknown schema");
}
await Verify(envelope.Payload);
}

public static string JsonEnrichedCommentEvent { get; } = @"{
'type': 'UserMentioned',
'payload': {
'$type': 'EnrichedCommentEvent',
'actor': 'subject:601c2cbafa4e669f214c0438',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'name': 'UserMentioned',
'partition': -1730311374,
'text': '@[email protected] testmessage',
'timestamp': '2021-01-01T00:00:00Z',
'url': '/app/testapp/content/schema/0e5955e3-cd2a-49f2-92ba-303acf4dd192/comments',
'version': 0
},
'timestamp': '2021-01-01T00:00:00Z'
}";
'type': 'UserMentioned',
'payload': {
'$type': 'EnrichedCommentEvent',
'actor': 'subject:601c2cbafa4e669f214c0438',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'name': 'UserMentioned',
'partition': -1730311374,
'text': '@[email protected] testmessage',
'timestamp': '2021-01-01T00:00:00Z',
'url': '/app/testapp/content/schema/0e5955e3-cd2a-49f2-92ba-303acf4dd192/comments',
'version': 0
},
'timestamp': '2021-01-01T00:00:00Z'
}";

[Fact]
public void Should_deserialize_EnrichedCommentEvent()
public async Task Should_deserialize_EnrichedCommentEvent()
{
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedCommentEvent);
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedCommentEvent, options);

Assert.True(envelope.Payload is EnrichedCommentEvent);

var commentEvent = (EnrichedCommentEvent)envelope.Payload;

Assert.Equal("@[email protected] testmessage", commentEvent.Text);
Assert.Equal("UserMentioned", commentEvent.Name);
Assert.Equal("testapp", commentEvent.App.Name);
Assert.Equal("601c2cbafa4e669f214c0438", commentEvent.Actor.Id);
await Verify(envelope.Payload);
}

public static string JsonEnrichedAssetEvent { get; } = @"{
'type': 'AssetCreatedFromSnapshot',
'payload': {
'$type': 'EnrichedAssetEvent',
'id': 'c5dc4403-713d-4ebd-9a8f-a17efdba924e',
'actor': 'subject:6025a698a825d86becf541fe',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'assetType': 'Unknown',
'created': '2021-01-01T00:00:00Z',
'createdBy': 'subject:6025a698a825d86becf541fe',
'fileName': 'name.pdf',
'fileSize': 447021,
'fileVersion': 0,
'isImage': false,
'lastModified': '2021-01-01T00:00:00Z',
'lastModifiedBy': 'subject:6025a698a825d86becf541fe',
'mimeType': 'application/pdf',
'name': 'AssetCreatedFromSnapshot',
'partition': -755061617,
'timestamp': '1970-01-01T00:00:00Z',
'type': 'Created',
'version': 1
},
'timestamp': '1970-01-01T00:00:00Z'
}";
'type': 'AssetCreatedFromSnapshot',
'payload': {
'$type': 'EnrichedAssetEvent',
'id': 'c5dc4403-713d-4ebd-9a8f-a17efdba924e',
'actor': 'subject:6025a698a825d86becf541fe',
'appId': '3e2df825-86a9-43cb-8eb7-97d5a5bd4eea,testapp',
'assetType': 'Unknown',
'created': '2021-01-01T00:00:00Z',
'createdBy': 'subject:6025a698a825d86becf541fe',
'fileName': 'name.pdf',
'fileSize': 447021,
'fileVersion': 0,
'isImage': false,
'lastModified': '2021-01-01T00:00:00Z',
'lastModifiedBy': 'subject:6025a698a825d86becf541fe',
'mimeType': 'application/pdf',
'name': 'AssetCreatedFromSnapshot',
'partition': -755061617,
'timestamp': '1970-01-01T00:00:00Z',
'type': 'Created',
'version': 1
},
'timestamp': '1970-01-01T00:00:00Z'
}";

[Fact]
public void Should_deserialize_EnrichedAssetEvent()
public async Task Should_deserialize_EnrichedAssetEvent()
{
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedAssetEvent);
var envelope = EnrichedEventEnvelope.FromJson(JsonEnrichedAssetEvent, options);

Assert.True(envelope.Payload is EnrichedAssetEvent);

var assetEvent = (EnrichedAssetEvent)envelope.Payload;

Assert.Equal("6025a698a825d86becf541fe", assetEvent.Actor.Id);
Assert.Equal("6025a698a825d86becf541fe", assetEvent.CreatedBy.Id);
Assert.Equal("6025a698a825d86becf541fe", assetEvent.LastModifiedBy.Id);
Assert.Equal("application/pdf", assetEvent.MimeType);
Assert.Equal("AssetCreatedFromSnapshot", assetEvent.Name);
Assert.Equal("c5dc4403-713d-4ebd-9a8f-a17efdba924e", assetEvent.Id);
Assert.Equal("name.pdf", assetEvent.FileName);
Assert.Equal("subject", assetEvent.CreatedBy.Type);
Assert.Equal("subject", assetEvent.LastModifiedBy.Type);
Assert.Equal("testapp", assetEvent.App.Name);
Assert.Equal(447021, assetEvent.FileSize);
await Verify(envelope.Payload);
}
}
Loading

0 comments on commit a2bd561

Please sign in to comment.