2022-06-30 01:46:41 +02:00
|
|
|
|
using Bit.Core.Services;
|
2022-06-28 18:17:14 +02:00
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using NSubstitute.Core;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
namespace Bit.Core.Test.Services;
|
|
|
|
|
|
|
|
|
|
[SutProviderCustomize]
|
|
|
|
|
public class AppleIapServiceTests
|
2022-06-28 18:17:14 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
[Theory, BitAutoData]
|
|
|
|
|
public async Task GetReceiptStatusAsync_MoreThanFourAttempts_Throws(SutProvider<AppleIapService> sutProvider)
|
2022-06-28 18:17:14 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
var result = await sutProvider.Sut.GetReceiptStatusAsync("test", false, 5, null);
|
|
|
|
|
Assert.Null(result);
|
2022-06-28 18:17:14 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
var errorLog = sutProvider.GetDependency<ILogger<AppleIapService>>()
|
|
|
|
|
.ReceivedCalls()
|
|
|
|
|
.SingleOrDefault(LogOneWarning);
|
2022-06-28 18:17:14 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
Assert.True(errorLog != null, "Must contain one error log of warning level containing 'null'");
|
2022-06-28 18:17:14 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
static bool LogOneWarning(ICall call)
|
|
|
|
|
{
|
|
|
|
|
if (call.GetMethodInfo().Name != "Log")
|
2022-06-28 18:17:14 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-28 18:17:14 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
var args = call.GetArguments();
|
|
|
|
|
var logLevel = (LogLevel)args[0];
|
|
|
|
|
var exception = (Exception)args[3];
|
2022-06-28 18:17:14 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
return logLevel == LogLevel.Warning && exception.Message.Contains("null");
|
2022-06-28 18:17:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|