mirror of https://github.com/Squidex/squidex.git
85 changed files with 334 additions and 440 deletions
@ -1,38 +0,0 @@ |
|||
// ==========================================================================
|
|||
// GeolocationPropertiesDto.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using NJsonSchema.Annotations; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
namespace Squidex.Controllers.Api.Schemas.Models |
|||
{ |
|||
[JsonSchema("Geolocation")] |
|||
public sealed class GeolocationFieldPropertiesDto : FieldPropertiesDto |
|||
{ |
|||
/// <summary>
|
|||
/// The default value for the field value.
|
|||
/// </summary>
|
|||
public bool? DefaultValue { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The editor that is used to manage this field.
|
|||
/// </summary>
|
|||
[JsonConverter(typeof(StringEnumConverter))] |
|||
public GeolocationFieldEditor Editor { get; set; } |
|||
|
|||
public override FieldProperties ToProperties() |
|||
{ |
|||
var result = SimpleMapper.Map(this, new GeolocationFieldProperties()); |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// ==========================================================================
|
|||
// ContentsDto.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Controllers.ContentApi.Models |
|||
{ |
|||
public sealed class AssetsDto |
|||
{ |
|||
/// <summary>
|
|||
/// The total number of content items.
|
|||
/// </summary>
|
|||
public long Total { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The content items.
|
|||
/// </summary>
|
|||
public ContentDto[] Items { get; set; } |
|||
} |
|||
} |
|||
@ -1,110 +0,0 @@ |
|||
// ==========================================================================
|
|||
// AssetStoreTestsBase.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Xunit; |
|||
|
|||
// ReSharper disable VirtualMemberCallInConstructor
|
|||
// ReSharper disable MemberCanBeProtected.Global
|
|||
|
|||
namespace Squidex.Infrastructure.Assets |
|||
{ |
|||
public abstract class AssetStoreTests<T> : IDisposable where T : IAssetStore |
|||
{ |
|||
private readonly T sut; |
|||
|
|||
protected AssetStoreTests() |
|||
{ |
|||
sut = CreateStore(); |
|||
} |
|||
|
|||
protected T Sut |
|||
{ |
|||
get { return sut; } |
|||
} |
|||
|
|||
public abstract T CreateStore(); |
|||
|
|||
public abstract void Dispose(); |
|||
|
|||
|
|||
[Fact] |
|||
public Task Should_throw_exception_if_asset_to_download_is_not_found() |
|||
{ |
|||
((IExternalSystem)Sut).Connect(); |
|||
|
|||
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.DownloadAsync(Id(), 1, "suffix", new MemoryStream())); |
|||
} |
|||
|
|||
[Fact] |
|||
public Task Should_throw_exception_if_asset_to_copy_is_not_found() |
|||
{ |
|||
((IExternalSystem)Sut).Connect(); |
|||
|
|||
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.CopyTemporaryAsync(Id(), Id(), 1, null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_read_and_write_file() |
|||
{ |
|||
((IExternalSystem)Sut).Connect(); |
|||
|
|||
var assetId = Id(); |
|||
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|||
|
|||
await Sut.UploadAsync(assetId, 1, "suffix", assetData); |
|||
|
|||
var readData = new MemoryStream(); |
|||
|
|||
await Sut.DownloadAsync(assetId, 1, "suffix", readData); |
|||
|
|||
Assert.Equal(assetData.ToArray(), readData.ToArray()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_commit_temporary_file() |
|||
{ |
|||
((IExternalSystem)Sut).Connect(); |
|||
|
|||
var tempId = Id(); |
|||
|
|||
var assetId = Id(); |
|||
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|||
|
|||
await Sut.UploadTemporaryAsync(tempId, assetData); |
|||
await Sut.CopyTemporaryAsync(tempId, assetId, 1, "suffix"); |
|||
|
|||
var readData = new MemoryStream(); |
|||
|
|||
await Sut.DownloadAsync(assetId, 1, "suffix", readData); |
|||
|
|||
Assert.Equal(assetData.ToArray(), readData.ToArray()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_ignore_when_deleting_twice() |
|||
{ |
|||
((IExternalSystem)Sut).Connect(); |
|||
|
|||
var tempId = Id(); |
|||
|
|||
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|||
|
|||
await Sut.UploadTemporaryAsync(tempId, assetData); |
|||
await Sut.DeleteTemporaryAsync(tempId); |
|||
await Sut.DeleteTemporaryAsync(tempId); |
|||
} |
|||
|
|||
private static string Id() |
|||
{ |
|||
return Guid.NewGuid().ToString(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,53 +0,0 @@ |
|||
// ==========================================================================
|
|||
// EnrichWithTimestampCommandMiddlewareTests.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using NodaTime; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Infrastructure.CQRS.Commands |
|||
{ |
|||
public sealed class EnrichWithTimestampCommandMiddlewareTests |
|||
{ |
|||
private sealed class MyTimestampCommand : ITimestampCommand |
|||
{ |
|||
public Instant Timestamp { get; set; } |
|||
|
|||
public long? ExpectedVersion { get; set; } |
|||
} |
|||
|
|||
private readonly IClock clock = A.Fake<IClock>(); |
|||
|
|||
[Fact] |
|||
public async Task Should_set_timestamp_for_timestamp_command() |
|||
{ |
|||
var utc = Instant.FromUnixTimeSeconds(1000); |
|||
var sut = new EnrichWithTimestampHandler(clock); |
|||
|
|||
A.CallTo(() => clock.GetCurrentInstant()) |
|||
.Returns(utc); |
|||
|
|||
var command = new MyTimestampCommand(); |
|||
|
|||
await sut.HandleAsync(new CommandContext(command)); |
|||
|
|||
Assert.Equal(utc, command.Timestamp); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_do_nothing_for_normal_command() |
|||
{ |
|||
var sut = new EnrichWithTimestampHandler(clock); |
|||
|
|||
await sut.HandleAsync(new CommandContext(A.Dummy<ICommand>())); |
|||
|
|||
A.CallTo(() => clock.GetCurrentInstant()).MustNotHaveHappened(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,91 +0,0 @@ |
|||
// ==========================================================================
|
|||
// LogExceptionHandlerTests.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Squidex.Infrastructure.Log; |
|||
using Squidex.Infrastructure.Tasks; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Infrastructure.CQRS.Commands |
|||
{ |
|||
public class LogExceptionHandlerTests |
|||
{ |
|||
private readonly MyLog log = new MyLog(); |
|||
private readonly LogCommandMiddleware sut; |
|||
private readonly ICommand command = A.Dummy<ICommand>(); |
|||
|
|||
private sealed class MyLog : ISemanticLog |
|||
{ |
|||
public int LogCount { get; private set; } |
|||
|
|||
public Dictionary<SemanticLogLevel, int> LogLevels { get; } = new Dictionary<SemanticLogLevel, int>(); |
|||
|
|||
public void Log(SemanticLogLevel logLevel, Action<IObjectWriter> action) |
|||
{ |
|||
LogCount++; |
|||
LogLevels[logLevel] = LogLevels.GetOrDefault(logLevel) + 1; |
|||
} |
|||
|
|||
public ISemanticLog CreateScope(Action<IObjectWriter> objectWriter) |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
} |
|||
|
|||
public LogExceptionHandlerTests() |
|||
{ |
|||
sut = new LogCommandMiddleware(log); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_log_before_and_after_request() |
|||
{ |
|||
var context = new CommandContext(command); |
|||
|
|||
await sut.HandleAsync(context, () => |
|||
{ |
|||
context.Complete(true); |
|||
|
|||
return TaskHelper.Done; |
|||
}); |
|||
|
|||
Assert.Equal(3, log.LogCount); |
|||
Assert.Equal(3, log.LogLevels[SemanticLogLevel.Information]); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_log_error_if_command_failed() |
|||
{ |
|||
var context = new CommandContext(command); |
|||
|
|||
await Assert.ThrowsAsync<InvalidOperationException>(async () => |
|||
{ |
|||
await sut.HandleAsync(context, () => throw new InvalidOperationException()); |
|||
}); |
|||
|
|||
Assert.Equal(3, log.LogCount); |
|||
Assert.Equal(2, log.LogLevels[SemanticLogLevel.Information]); |
|||
Assert.Equal(1, log.LogLevels[SemanticLogLevel.Error]); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_log_if_command_is_not_handled() |
|||
{ |
|||
var context = new CommandContext(command); |
|||
|
|||
await sut.HandleAsync(context, () => TaskHelper.Done); |
|||
|
|||
Assert.Equal(4, log.LogCount); |
|||
Assert.Equal(3, log.LogLevels[SemanticLogLevel.Information]); |
|||
Assert.Equal(1, log.LogLevels[SemanticLogLevel.Fatal]); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue