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.
75 lines
2.0 KiB
75 lines
2.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using MongoDB.Bson.IO;
|
|
using MongoDB.Bson.Serialization;
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Infrastructure.MongoDb;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.MongoDb
|
|
{
|
|
public sealed class StatusSerializerTests
|
|
{
|
|
private sealed record ValueHolder<T>
|
|
{
|
|
public T Value { get; set; }
|
|
}
|
|
|
|
public StatusSerializerTests()
|
|
{
|
|
TypeConverterStringSerializer<Status>.Register();
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize_status()
|
|
{
|
|
var source = new ValueHolder<Status>
|
|
{
|
|
Value = Status.Published
|
|
};
|
|
|
|
var deserialized = SerializeAndDeserializeBson(source);
|
|
|
|
Assert.Equal(source, deserialized);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize_default_status()
|
|
{
|
|
var source = new ValueHolder<Status>
|
|
{
|
|
Value = default
|
|
};
|
|
|
|
var deserialized = SerializeAndDeserializeBson(source);
|
|
|
|
Assert.Equal(source, deserialized);
|
|
}
|
|
|
|
private static T SerializeAndDeserializeBson<T>(T value)
|
|
{
|
|
var stream = new MemoryStream();
|
|
|
|
using (var writer = new BsonBinaryWriter(stream))
|
|
{
|
|
BsonSerializer.Serialize(writer, value);
|
|
|
|
writer.Flush();
|
|
}
|
|
|
|
stream.Position = 0;
|
|
|
|
using (var reader = new BsonBinaryReader(stream))
|
|
{
|
|
var result = BsonSerializer.Deserialize<T>(reader);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|