mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.4 KiB
111 lines
3.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using FluentAssertions;
|
|
using Squidex.Domain.Apps.Core.Apps;
|
|
using Xunit;
|
|
|
|
#pragma warning disable SA1310 // Field names must not contain underscore
|
|
|
|
namespace Squidex.Domain.Apps.Core.Model.Apps
|
|
{
|
|
public class AppClientsTests
|
|
{
|
|
private readonly AppClients clients_0 = AppClients.Empty.Add("1", "my-secret");
|
|
|
|
[Fact]
|
|
public void Should_assign_client()
|
|
{
|
|
var clients_1 = clients_0.Add("2", "my-secret");
|
|
|
|
clients_1["2"].Should().BeEquivalentTo(new AppClient("2", "my-secret", Role.Editor));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_assign_clients_with_permission()
|
|
{
|
|
var clients_1 = clients_0.Add("2", new AppClient("my-name", "my-secret", Role.Reader));
|
|
|
|
clients_1["2"].Should().BeEquivalentTo(new AppClient("my-name", "my-secret", Role.Reader));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_throw_exception_if_assigning_client_with_same_id()
|
|
{
|
|
var clients_1 = clients_0.Add("2", "my-secret");
|
|
|
|
Assert.Throws<ArgumentException>(() => clients_1.Add("2", "my-secret"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_do_nothing_if_assigning_client_object_with_same_id()
|
|
{
|
|
var clients_1 = clients_0.Add("2", "my-secret");
|
|
|
|
clients_1.Add("2", new AppClient("my-name", "my-secret", "my-role"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_rename_client()
|
|
{
|
|
var clients_1 = clients_0.Rename("1", "new-name");
|
|
|
|
clients_1["1"].Should().BeEquivalentTo(new AppClient("new-name", "my-secret", Role.Editor));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_same_clients_if_client_is_updated_with_the_same_values()
|
|
{
|
|
var clients_1 = clients_0.Rename("2", "2");
|
|
|
|
Assert.Same(clients_0, clients_1);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_same_clients_if_client_to_rename_not_found()
|
|
{
|
|
var clients_1 = clients_0.Rename("2", "new-name");
|
|
|
|
Assert.Same(clients_0, clients_1);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_update_client()
|
|
{
|
|
var client_1 = clients_0.Update("1", Role.Reader);
|
|
|
|
client_1["1"].Should().BeEquivalentTo(new AppClient("1", "my-secret", Role.Reader));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_same_clients_if_client_to_update_not_found()
|
|
{
|
|
var clients_1 = clients_0.Update("2", Role.Reader);
|
|
|
|
Assert.Same(clients_0, clients_1);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_revoke_client()
|
|
{
|
|
var clients_1 = clients_0.Add("2", "secret2");
|
|
var clients_2 = clients_1.Add("3", "secret3");
|
|
var clients_3 = clients_2.Revoke("2");
|
|
|
|
Assert.Equal(new[] { "1", "3" }, clients_3.Keys);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_do_nothing_if_client_to_revoke_not_found()
|
|
{
|
|
var clients_1 = clients_0.Revoke("2");
|
|
|
|
Assert.Same(clients_0, clients_1);
|
|
}
|
|
}
|
|
}
|
|
|