Browse Source

More the API more idempotent (#453)

pull/456/merge
Sebastian Stehle 6 years ago
committed by GitHub
parent
commit
26dd42b4b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      backend/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppClients.cs
  2. 10
      backend/src/Squidex.Domain.Apps.Entities/Assets/Guards/GuardAsset.cs
  3. 5
      backend/src/Squidex.Domain.Apps.Entities/Rules/Guards/GuardRule.cs
  4. 10
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppClientsTests.cs
  5. 20
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Guards/GuardAssetTests.cs
  6. 10
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/GuardRuleTests.cs

15
backend/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppClients.cs

@ -68,21 +68,6 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
{
e(Not.Valid("role"), nameof(command.Role));
}
if (client == null)
{
return;
}
if (!string.IsNullOrWhiteSpace(command.Name) && string.Equals(client.Name, command.Name))
{
e(Not.New("Client", "name"), nameof(command.Name));
}
if (command.Role == client.Role)
{
e(Not.New("Client", "role"), nameof(command.Role));
}
});
}

10
backend/src/Squidex.Domain.Apps.Entities/Assets/Guards/GuardAsset.cs

@ -25,16 +25,6 @@ namespace Squidex.Domain.Apps.Entities.Assets.Guards
{
e("Either file name, slug or tags must be defined.", nameof(command.FileName), nameof(command.Slug), nameof(command.Tags));
}
if (!string.IsNullOrWhiteSpace(command.FileName) && string.Equals(command.FileName, oldFileName))
{
e(Not.New("Asset", "name"), nameof(command.FileName));
}
if (!string.IsNullOrWhiteSpace(command.Slug) && string.Equals(command.Slug, oldSlug))
{
e(Not.New("Asset", "slug"), nameof(command.Slug));
}
});
}

5
backend/src/Squidex.Domain.Apps.Entities/Rules/Guards/GuardRule.cs

@ -70,11 +70,6 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards
errors.Foreach(x => x.AddTo(e));
}
if (command.Name != null && string.Equals(rule.Name, command.Name))
{
e(Not.New("Rule", "name"), nameof(command.Name));
}
});
}

10
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppClientsTests.cs

@ -118,25 +118,23 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
}
[Fact]
public void UpdateClient_should_throw_exception_if_client_has_same_name()
public void UpdateClient_should_not_throw_exception_if_client_has_same_name()
{
var command = new UpdateClient { Id = "ios", Name = "ios" };
var clients_1 = clients_0.Add("ios", "secret");
ValidationAssert.Throws(() => GuardAppClients.CanUpdate(clients_1, command, roles),
new ValidationError("Client has already this name.", "Name"));
GuardAppClients.CanUpdate(clients_1, command, roles);
}
[Fact]
public void UpdateClient_should_throw_exception_if_client_has_same_role()
public void UpdateClient_not_should_throw_exception_if_client_has_same_role()
{
var command = new UpdateClient { Id = "ios", Role = Role.Editor };
var clients_1 = clients_0.Add("ios", "secret");
ValidationAssert.Throws(() => GuardAppClients.CanUpdate(clients_1, command, roles),
new ValidationError("Client has already this role.", "Role"));
GuardAppClients.CanUpdate(clients_1, command, roles);
}
[Fact]

20
backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Guards/GuardAssetTests.cs

@ -24,25 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Guards
}
[Fact]
public void CanAnnotate_should_throw_exception_if_names_are_the_same()
{
var command = new AnnotateAsset { FileName = "asset-name" };
ValidationAssert.Throws(() => GuardAsset.CanAnnotate(command, "asset-name", "asset-slug"),
new ValidationError("Asset has already this name.", "FileName"));
}
[Fact]
public void CanAnnotate_should_throw_exception_if_slugs_are_the_same()
{
var command = new AnnotateAsset { Slug = "asset-slug" };
ValidationAssert.Throws(() => GuardAsset.CanAnnotate(command, "asset-name", "asset-slug"),
new ValidationError("Asset has already this slug.", "Slug"));
}
[Fact]
public void CanAnnotate_should_not_throw_exception_if_names_are_different()
public void CanAnnotate_should_not_throw_exception_if_a_value_is_passed()
{
var command = new AnnotateAsset { FileName = "new-name", Slug = "new-slug" };

10
backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/GuardRuleTests.cs

@ -100,15 +100,11 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards
}
[Fact]
public async Task CanUpdate_should_throw_exception_if_rule_has_already_this_name()
public async Task CanUpdate_should_not_throw_exception_if_rule_has_already_this_name()
{
var command = new UpdateRule
{
Name = "MyName"
};
var command = new UpdateRule { Name = "MyName" };
await ValidationAssert.ThrowsAsync(() => GuardRule.CanUpdate(command, appId.Id, appProvider, rule_0),
new ValidationError("Rule has already this name.", "Name"));
await GuardRule.CanUpdate(command, appId.Id, appProvider, rule_0);
}
[Fact]

Loading…
Cancel
Save