// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Threading; using System.Threading.Tasks; using Jupiter.Implementation; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; namespace Jupiter.UnitTests { [TestClass] public class BlobCleanupServiceTest { [TestMethod] public async Task CleanupOnPollAsync() { GCSettings gcSettings = new GCSettings() { CleanOldBlobs = false }; IOptionsMonitor gcSettingsMon = Mock.Of>(_ => _.CurrentValue == gcSettings); await using BlobCleanupService blobCleanupService = new BlobCleanupService(Mock.Of(), gcSettingsMon, NullLogger.Instance); Mock store1 = new Mock(); store1.Setup(cleanup => cleanup.ShouldRun()).Returns(true); Mock store2 = new Mock(); store2.Setup(cleanup => cleanup.ShouldRun()).Returns(true); blobCleanupService.RegisterCleanup(store1.Object); blobCleanupService.RegisterCleanup(store2.Object); using CancellationTokenSource tokenSource = new CancellationTokenSource(); await blobCleanupService.OnPollAsync(blobCleanupService.State, tokenSource.Token); store1.Verify(m => m.CleanupAsync(It.IsAny()), Times.Once); store2.Verify(m => m.CleanupAsync(It.IsAny()), Times.Once); } } }