public async Task FlagDisablesPopularityTransfers() { var downloadChanges = new SortedDictionary <string, long>(StringComparer.OrdinalIgnoreCase) { { "Package1", 5 } }; DownloadSetComparer .Setup(c => c.Compare(It.IsAny <DownloadData>(), It.IsAny <DownloadData>())) .Returns <DownloadData, DownloadData>((oldData, newData) => { return(downloadChanges); }); OldTransfers.AddTransfer("Package1", "Package2"); NewTransfers.AddTransfer("Package1", "Package2"); FeatureFlags .Setup(x => x.IsPopularityTransferEnabled()) .Returns(false); await Target.ExecuteAsync(); PopularityTransferDataClient .Verify( c => c.ReadLatestIndexedAsync(It.IsAny <IAccessCondition>(), It.IsAny <StringCache>()), Times.Once); DatabaseFetcher .Verify( d => d.GetPopularityTransfersAsync(), Times.Never); // The popularity transfers should not be given to the download transferrer. DownloadTransferrer .Verify( x => x.UpdateDownloadTransfers( NewDownloadData, downloadChanges, OldTransfers, It.Is <PopularityTransferData>(d => d.Count == 0)), Times.Once); // Popularity transfers auxiliary file should be empty. PopularityTransferDataClient.Verify( c => c.ReplaceLatestIndexedAsync( It.Is <PopularityTransferData>(d => d.Count == 0), It.IsAny <IAccessCondition>()), Times.Once); }
public async Task AppliesTransferChanges() { var downloadChanges = new SortedDictionary <string, long>(StringComparer.OrdinalIgnoreCase); DownloadSetComparer .Setup(c => c.Compare(It.IsAny <DownloadData>(), It.IsAny <DownloadData>())) .Returns <DownloadData, DownloadData>((oldData, newData) => { return(downloadChanges); }); TransferChanges["Package1"] = 100; TransferChanges["Package2"] = 200; NewTransfers.AddTransfer("Package1", "Package2"); await Target.ExecuteAsync(); PopularityTransferDataClient .Verify( c => c.ReadLatestIndexedAsync( It.Is <IAccessCondition>(x => x.IfMatchETag == null && x.IfNoneMatchETag == null), It.IsAny <StringCache>()), Times.Once); DatabaseFetcher .Verify( d => d.GetPopularityTransfersAsync(), Times.Once); DownloadTransferrer .Verify( x => x.UpdateDownloadTransfers( NewDownloadData, downloadChanges, OldTransfers, NewTransfers), Times.Once); // Documents should be updated. SearchDocumentBuilder .Verify( b => b.UpdateDownloadCount("Package1", SearchFilters.IncludePrereleaseAndSemVer2, 100), Times.Once); SearchDocumentBuilder .Verify( b => b.UpdateDownloadCount("Package2", SearchFilters.IncludePrereleaseAndSemVer2, 200), Times.Once); // Downloads auxiliary file should not include transfer changes. DownloadDataClient.Verify( c => c.ReplaceLatestIndexedAsync( It.Is <DownloadData>(d => d.Count == 0), It.IsAny <IAccessCondition>()), Times.Once); // Popularity transfers auxiliary file should have new data. PopularityTransferDataClient.Verify( c => c.ReplaceLatestIndexedAsync( It.Is <PopularityTransferData>(d => d.Count == 1 && d["Package1"].Count == 1 && d["Package1"].Contains("Package2")), It.IsAny <IAccessCondition>()), Times.Once); }