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.
49 lines
1.7 KiB
49 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
using Squidex.Domain.Apps.Entities.TestHelpers;
|
|
|
|
#pragma warning disable MA0048 // File name must match type name
|
|
|
|
namespace Squidex.MongoDb.TestHelpers;
|
|
|
|
[CollectionDefinition(Name)]
|
|
public sealed class DocumentDbCollection : ICollectionFixture<DocumentDbFixture>
|
|
{
|
|
public const string Name = "DocumentDb";
|
|
}
|
|
|
|
public class DocumentDbFixture
|
|
{
|
|
public IMongoClient Client { get; private set; }
|
|
|
|
public IMongoDatabase Database => Client.GetDatabase($"Test_{Guid.NewGuid()}");
|
|
|
|
public DocumentDbFixture()
|
|
{
|
|
var settings = MongoClientSettings.FromConnectionString(
|
|
TestConfig.Configuration.GetValue<string>("documentDb:configuration")
|
|
);
|
|
|
|
var certPath = TestConfig.Configuration.GetValue<string>("documentDb:keyFile")!;
|
|
var certFile = X509CertificateLoader.LoadCertificateFromFile(certPath);
|
|
|
|
settings.RetryWrites = false;
|
|
settings.RetryReads = false;
|
|
settings.SslSettings = new SslSettings
|
|
{
|
|
ClientCertificates = [certFile],
|
|
CheckCertificateRevocation = false,
|
|
ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true,
|
|
};
|
|
|
|
Client = new MongoClient(settings);
|
|
}
|
|
}
|
|
|