mirror of https://github.com/Squidex/squidex.git
6 changed files with 92 additions and 17 deletions
@ -0,0 +1,22 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using MongoDB.Bson.Serialization; |
|||
|
|||
namespace Squidex.Infrastructure.MongoDb |
|||
{ |
|||
public static class Field |
|||
{ |
|||
public static string Of<T>(Func<T, string> mapper) |
|||
{ |
|||
var name = mapper(default!); |
|||
|
|||
return BsonClassMap.LookupClassMap(typeof(T)).GetMemberMap(name).ElementName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Infrastructure.MongoDb |
|||
{ |
|||
public class FieldTests |
|||
{ |
|||
public sealed class Entity |
|||
{ |
|||
public string Id { get; set; } |
|||
|
|||
public string Default { get; set; } |
|||
|
|||
[BsonElement("_c")] |
|||
public string Custom { get; set; } |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_resolve_id_field() |
|||
{ |
|||
var name = Field.Of<Entity>(x => nameof(x.Id)); |
|||
|
|||
Assert.Equal("_id", name); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_resolve_default_field() |
|||
{ |
|||
var name = Field.Of<Entity>(x => nameof(x.Default)); |
|||
|
|||
Assert.Equal("Default", name); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_resolve_custom_field() |
|||
{ |
|||
var name = Field.Of<Entity>(x => nameof(x.Custom)); |
|||
|
|||
Assert.Equal("_c", name); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue