/*
* Copyright (c) 2025 Proton AG
*
* This file is part of ProtonVPN.
*
* ProtonVPN is free software:
you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProtonVPN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProtonVPN. If not, see .
*/
using Autofac;
using NSubstitute;
using ProtonVPN.Api;
using ProtonVPN.Api.Contracts;
using ProtonVPN.Client.Common.Dispatching;
using ProtonVPN.Client.Core.Services.Navigation;
using ProtonVPN.Client.EventMessaging.Contracts;
using ProtonVPN.Client.Installers;
using ProtonVPN.Client.Localization.Building;
using ProtonVPN.Client.Logic.Auth.Srp.Contracts;
using ProtonVPN.Client.Services.Bootstrapping.Activators;
using ProtonVPN.Client.UI.Main.Sidebar.Connections.Bases.Contracts;
using ProtonVPN.Client.UI.Main.Sidebar.Search.Contracts;
using ProtonVPN.Common.Legacy.OS.Net.Http;
using RichardSzalay.MockHttp;
using File = System.IO.File;
namespace ProtonVPN.Integration.Tests;
public class TestBase
{
private IContainer? _container;
protected MockHttpMessageHandler? MessageHandler = new();
protected TestSrpProofGenerator SrpProofGenerator { get; } = new();
public T Resolve() => _container.Resolve();
[TestCleanup]
public virtual void Cleanup()
{
_container?.Dispose();
}
protected void InitializeContainer()
{
ContainerBuilder builder = new();
builder.RegisterModule();
builder.Register(_ => SrpProofGenerator).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For()).As().SingleInstance();
builder.Register(_ => Substitute.For>()).As>().SingleInstance();
HttpClient httpClient = MessageHandler!.ToHttpClient();
httpClient.BaseAddress = new Uri("http://localhost");
builder.Register(_ =>
{
IFileDownloadHttpClientFactory httpClients = Substitute.For();
httpClients.GetHttpClientWithTlsPinning().Returns(new WrappedHttpClient(httpClient));
return httpClients;
}).As();
builder.Register(_ =>
{
IApiHttpClientFactory httpClientFactory = Substitute.For();
httpClientFactory.GetApiHttpClientWithCache().Returns(httpClient);
httpClientFactory.GetApiHttpClientWithoutCache().Returns(httpClient);
return httpClientFactory;
}).As();
_container = builder.Build();
}
protected string GetJsonMock(string name)
{
return File.ReadAllText($"TestData\\{name}.json");
}
}