mirror of https://github.com/Squidex/squidex.git
32 changed files with 313 additions and 361 deletions
@ -1,46 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
using System; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Contents |
|||
{ |
|||
public struct Status2 : IEquatable<Status2> |
|||
{ |
|||
public static readonly Status2 Published = new Status2("Published"); |
|||
|
|||
public string Name { get; } |
|||
|
|||
public Status2(string name) |
|||
{ |
|||
Guard.NotNullOrEmpty(name, nameof(name)); |
|||
|
|||
Name = name; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return obj is Status2 status && Equals(status); |
|||
} |
|||
|
|||
public bool Equals(Status2 other) |
|||
{ |
|||
return Name.Equals(other.Name); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
return Name.GetHashCode(); |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return Name; |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Core.Contents |
|||
{ |
|||
public enum StatusChange |
|||
{ |
|||
Archived, |
|||
Published, |
|||
Restored, |
|||
Unpublished |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Contents |
|||
{ |
|||
public static class StatusFlow |
|||
{ |
|||
private static readonly Dictionary<Status, Status[]> Flow = new Dictionary<Status, Status[]> |
|||
{ |
|||
[Status.Draft] = new[] { Status.Published, Status.Archived }, |
|||
[Status.Archived] = new[] { Status.Draft }, |
|||
[Status.Published] = new[] { Status.Draft, Status.Archived } |
|||
}; |
|||
|
|||
public static bool Exists(Status status) |
|||
{ |
|||
return Flow.ContainsKey(status); |
|||
} |
|||
|
|||
public static bool CanChange(Status status, Status toStatus) |
|||
{ |
|||
return Flow.TryGetValue(status, out var state) && state.Contains(toStatus); |
|||
} |
|||
|
|||
public static IEnumerable<Status> Next(Status status) |
|||
{ |
|||
return Flow.TryGetValue(status, out var result) ? result : Enumerable.Empty<Status>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Model.Contents |
|||
{ |
|||
public class StatusFlowTests |
|||
{ |
|||
[Fact] |
|||
public void Should_make_tests() |
|||
{ |
|||
Assert.True(StatusFlow.Exists(Status.Draft)); |
|||
Assert.True(StatusFlow.Exists(Status.Archived)); |
|||
Assert.True(StatusFlow.Exists(Status.Published)); |
|||
|
|||
Assert.True(StatusFlow.CanChange(Status.Draft, Status.Archived)); |
|||
Assert.True(StatusFlow.CanChange(Status.Draft, Status.Published)); |
|||
|
|||
Assert.True(StatusFlow.CanChange(Status.Published, Status.Draft)); |
|||
Assert.True(StatusFlow.CanChange(Status.Published, Status.Archived)); |
|||
|
|||
Assert.True(StatusFlow.CanChange(Status.Archived, Status.Draft)); |
|||
|
|||
Assert.False(StatusFlow.Exists((Status)int.MaxValue)); |
|||
Assert.False(StatusFlow.CanChange(Status.Archived, Status.Published)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue