mirror of https://github.com/Squidex/squidex.git
37 changed files with 60 additions and 189 deletions
@ -1,58 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// ConfigAppLimitsProvider.cs
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex Group
|
|
||||
// All rights reserved.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using Squidex.Infrastructure; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations |
|
||||
{ |
|
||||
public sealed class ConfigAppPlansProvider : IAppPlansProvider |
|
||||
{ |
|
||||
private static readonly ConfigAppLimitsPlan Infinite = new ConfigAppLimitsPlan |
|
||||
{ |
|
||||
Id = "infinite", |
|
||||
Name = "Infinite", |
|
||||
MaxApiCalls = -1, |
|
||||
MaxAssetSize = -1, |
|
||||
MaxContributors = -1 |
|
||||
}; |
|
||||
|
|
||||
private readonly Dictionary<string, ConfigAppLimitsPlan> config; |
|
||||
|
|
||||
public ConfigAppPlansProvider(IEnumerable<ConfigAppLimitsPlan> config) |
|
||||
{ |
|
||||
Guard.NotNull(config, nameof(config)); |
|
||||
|
|
||||
this.config = config.Select(c => c.Clone()).OrderBy(x => x.MaxApiCalls).ToDictionary(c => c.Id, StringComparer.OrdinalIgnoreCase); |
|
||||
} |
|
||||
|
|
||||
public IEnumerable<IAppLimitsPlan> GetAvailablePlans() |
|
||||
{ |
|
||||
return config.Values; |
|
||||
} |
|
||||
|
|
||||
public IAppLimitsPlan GetPlanForApp(IAppEntity app) |
|
||||
{ |
|
||||
Guard.NotNull(app, nameof(app)); |
|
||||
|
|
||||
return GetPlan(app.PlanId); |
|
||||
} |
|
||||
|
|
||||
public IAppLimitsPlan GetPlan(string planId) |
|
||||
{ |
|
||||
return config.GetOrDefault(planId ?? string.Empty) ?? config.Values.FirstOrDefault() ?? Infinite; |
|
||||
} |
|
||||
|
|
||||
public bool IsConfiguredPlan(string planId) |
|
||||
{ |
|
||||
return planId != null && config.ContainsKey(planId); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,79 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// GeolocationPropertiesTests.cs
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex Group
|
|
||||
// All rights reserved.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Reflection; |
|
||||
using FluentAssertions; |
|
||||
using Squidex.Infrastructure; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Core.Schemas |
|
||||
{ |
|
||||
public class GeolocationFieldPropertiesTests |
|
||||
{ |
|
||||
private readonly List<ValidationError> errors = new List<ValidationError>(); |
|
||||
|
|
||||
[Fact] |
|
||||
public void Should_add_error_if_editor_is_not_valid() |
|
||||
{ |
|
||||
var sut = new GeolocationFieldProperties { Editor = (GeolocationFieldEditor)123 }; |
|
||||
|
|
||||
sut.Validate(errors); |
|
||||
|
|
||||
errors.ShouldBeEquivalentTo( |
|
||||
new List<ValidationError> |
|
||||
{ |
|
||||
new ValidationError("Editor is not a valid value", "Editor") |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Should_set_or_freeze_sut() |
|
||||
{ |
|
||||
var sut = new GeolocationFieldProperties(); |
|
||||
|
|
||||
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen")) |
|
||||
{ |
|
||||
var value = |
|
||||
property.PropertyType.GetTypeInfo().IsValueType ? |
|
||||
Activator.CreateInstance(property.PropertyType) : |
|
||||
null; |
|
||||
|
|
||||
property.SetValue(sut, value); |
|
||||
|
|
||||
var result = property.GetValue(sut); |
|
||||
|
|
||||
Assert.Equal(value, result); |
|
||||
} |
|
||||
|
|
||||
sut.Freeze(); |
|
||||
|
|
||||
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen")) |
|
||||
{ |
|
||||
var value = |
|
||||
property.PropertyType.GetTypeInfo().IsValueType ? |
|
||||
Activator.CreateInstance(property.PropertyType) : |
|
||||
null; |
|
||||
|
|
||||
Assert.Throws<InvalidOperationException>(() => |
|
||||
{ |
|
||||
try |
|
||||
{ |
|
||||
property.SetValue(sut, value); |
|
||||
} |
|
||||
catch (Exception ex) |
|
||||
{ |
|
||||
throw ex.InnerException; |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue