Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Test warning fixes (#543)
Browse files Browse the repository at this point in the history
* Test warning fixes

* Second round of fixes. No more xUnit warnings at all.
  • Loading branch information
agr authored Jun 6, 2019
1 parent d7346f2 commit bfd836b
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 86 deletions.
18 changes: 9 additions & 9 deletions tests/CatalogTests/CatalogCommitUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ public void StartProcessingBatchesIfNoFailures_WhenAnyBatchIsFailed_DoesNotStart
NoOpProcessBatchAsync,
CancellationToken.None);

Assert.Equal(1, unprocessedBatches.Count);
Assert.Equal(1, processingBatches.Count);
Assert.Single(unprocessedBatches);
Assert.Single(processingBatches);
}

[Fact]
Expand All @@ -357,8 +357,8 @@ public void StartProcessingBatchesIfNoFailures_WhenNoBatchIsCancelled_DoesNotSta
NoOpProcessBatchAsync,
CancellationToken.None);

Assert.Equal(1, unprocessedBatches.Count);
Assert.Equal(1, processingBatches.Count);
Assert.Single(unprocessedBatches);
Assert.Single(processingBatches);
}

[Fact]
Expand Down Expand Up @@ -386,8 +386,8 @@ public void StartProcessingBatchesIfNoFailures_WhenMaxConcurrencyLimitHit_DoesNo
NoOpProcessBatchAsync,
CancellationToken.None);

Assert.Equal(1, unprocessedBatches.Count);
Assert.Equal(1, processingBatches.Count);
Assert.Single(unprocessedBatches);
Assert.Single(processingBatches);
}
}

Expand All @@ -407,8 +407,8 @@ public void StartProcessingBatchesIfNoFailures_WhenCanStartNewBatch_StartsNewBat
NoOpProcessBatchAsync,
CancellationToken.None);

Assert.Equal(0, unprocessedBatches.Count);
Assert.Equal(1, processingBatches.Count);
Assert.Empty(unprocessedBatches);
Assert.Single(processingBatches);
}

[Fact]
Expand All @@ -429,7 +429,7 @@ public void StartProcessingBatchesIfNoFailures_WhenProcessingQueueContainsComple
NoOpProcessBatchAsync,
CancellationToken.None);

Assert.Equal(0, unprocessedBatches.Count);
Assert.Empty(unprocessedBatches);
Assert.Equal(2, processingBatches.Count);
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/CatalogTests/Dnx/DnxCatalogCollectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public async Task RunAsync_WhenPackageDoesNotHaveNuspec_SkipsPackage()

await _target.RunAsync(front, back, CancellationToken.None);

Assert.Equal(1, _catalogToDnxStorage.Content.Count);
Assert.Single(_catalogToDnxStorage.Content);
Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
Assert.True(_catalogToDnxStorage.ContentBytes.ContainsKey(_cursorJsonUri));
Expand Down Expand Up @@ -357,7 +357,7 @@ public async Task RunAsync_WhenSourceNupkgIsNotFound_SkipsPackage()

await _target.RunAsync(front, back, CancellationToken.None);

Assert.Equal(1, _catalogToDnxStorage.Content.Count);
Assert.Single(_catalogToDnxStorage.Content);
Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(nupkgUri));
Expand Down Expand Up @@ -424,7 +424,7 @@ public async Task RunAsync_WithValidPackage_RespectsDeletion()

await _target.RunAsync(front, back, CancellationToken.None);

Assert.Equal(1, _catalogToDnxStorage.Content.Count);
Assert.Single(_catalogToDnxStorage.Content);
Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(nupkgUri));
Expand Down Expand Up @@ -454,7 +454,7 @@ public async Task RunAsync_WithPackageCreatedThenDeleted_LeavesNoArtifacts()

await _target.RunAsync(front, back, CancellationToken.None);

Assert.Equal(1, _catalogToDnxStorage.Content.Count);
Assert.Single(_catalogToDnxStorage.Content);
Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
Assert.False(_catalogToDnxStorage.Content.ContainsKey(nupkgUri));
Expand Down Expand Up @@ -710,7 +710,7 @@ public async Task RunAsync_WhenDownloadingPackage_RejectsUnexpectedHttpStatusCod
Assert.Equal(
$"Expected status code OK for package download, actual: {statusCode}",
exception.InnerException.Message);
Assert.Equal(0, _catalogToDnxStorage.Content.Count);
Assert.Empty(_catalogToDnxStorage.Content);
}

[Fact]
Expand Down
24 changes: 12 additions & 12 deletions tests/CatalogTests/Dnx/DnxMakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ public async Task DeletePackageAsync_WithValidVersion_RemovesNupkgAndNuspecFromS

await maker.DeletePackageAsync(_packageId, version, CancellationToken.None);

Assert.Equal(0, catalogToDnxStorage.Content.Count);
Assert.Equal(0, storageForPackage.Content.Count);
Assert.Empty(catalogToDnxStorage.Content);
Assert.Empty(storageForPackage.Content);
}
}

Expand Down Expand Up @@ -637,8 +637,8 @@ public async Task UpdatePackageVersionIndexAsync_WithValidVersion_CreatesIndex(s
var versions = indexObject["versions"].ToObject<string[]>();
var expectedContent = GetExpectedIndexJsonContent(normalizedVersion);

Assert.Equal(1, catalogToDnxStorage.Content.Count);
Assert.Equal(1, storageForPackage.Content.Count);
Assert.Single(catalogToDnxStorage.Content);
Assert.Single(storageForPackage.Content);

Verify(catalogToDnxStorage, indexJsonUri, expectedContent, _expectedPackageVersionIndexJsonCacheControl, _expectedPackageVersionIndexJsonContentType);
Verify(storageForPackage, indexJsonUri, expectedContent, _expectedPackageVersionIndexJsonCacheControl, _expectedPackageVersionIndexJsonContentType);
Expand All @@ -661,16 +661,16 @@ public async Task UpdatePackageVersionIndexAsync_WhenLastVersionRemoved_RemovesI
var indexJson = await storageForPackage.LoadAsync(indexJsonUri, CancellationToken.None);

Assert.NotNull(indexJson);
Assert.Equal(1, catalogToDnxStorage.Content.Count);
Assert.Equal(1, storageForPackage.Content.Count);
Assert.Single(catalogToDnxStorage.Content);
Assert.Single(storageForPackage.Content);

await maker.UpdatePackageVersionIndexAsync(_packageId, v => v.Remove(version), CancellationToken.None);

indexJson = await storageForPackage.LoadAsync(indexJsonUri, CancellationToken.None);

Assert.Null(indexJson);
Assert.Equal(0, catalogToDnxStorage.Content.Count);
Assert.Equal(0, storageForPackage.Content.Count);
Assert.Empty(catalogToDnxStorage.Content);
Assert.Empty(storageForPackage.Content);
}

[Fact]
Expand All @@ -687,8 +687,8 @@ public async Task UpdatePackageVersionIndexAsync_WithNoVersions_DoesNotCreateInd
var indexJson = await storageForPackage.LoadAsync(indexJsonUri, CancellationToken.None);

Assert.Null(indexJson);
Assert.Equal(0, catalogToDnxStorage.Content.Count);
Assert.Equal(0, storageForPackage.Content.Count);
Assert.Empty(catalogToDnxStorage.Content);
Assert.Empty(storageForPackage.Content);
}

[Fact]
Expand All @@ -715,8 +715,8 @@ public async Task UpdatePackageVersionIndexAsync_WithMultipleVersions_SortsVersi
var indexObject = JObject.Parse(indexJson.GetContentString());
var versions = indexObject["versions"].ToObject<string[]>();

Assert.Equal(1, catalogToDnxStorage.Content.Count);
Assert.Equal(1, storageForPackage.Content.Count);
Assert.Single(catalogToDnxStorage.Content);
Assert.Single(storageForPackage.Content);
Assert.Collection(
versions,
version => Assert.Equal(unorderedVersions[2].ToNormalizedString(), version),
Expand Down
9 changes: 7 additions & 2 deletions tests/CatalogTests/Helpers/Db2CatalogCursorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using NuGet.Services.Metadata.Catalog.Helpers;
using Xunit;

Expand All @@ -25,8 +26,8 @@ public void TargetsCreatedColumn(Func<DateTime, int, Db2CatalogCursor> cursorMet
}

[Theory]
[MemberData(nameof(CursorMethodToColumnNameMappings))]
public void ProtectsAgainstSqlMinDate(Func<DateTime, int, Db2CatalogCursor> cursorMethod, string expectedColumnName)
[MemberData(nameof(CursorMethods))]
public void ProtectsAgainstSqlMinDate(Func<DateTime, int, Db2CatalogCursor> cursorMethod)
{
const int top = 1;
var since = new DateTime(SqlDateTime.MinValue.Value.Ticks - 1, DateTimeKind.Utc);
Expand All @@ -40,5 +41,9 @@ public void ProtectsAgainstSqlMinDate(Func<DateTime, int, Db2CatalogCursor> curs
new object[] { (Func<DateTime, int, Db2CatalogCursor>)((since, top) => Db2CatalogCursor.ByCreated(since, top)), Db2CatalogProjectionColumnNames.Created },
new object[] { (Func<DateTime, int, Db2CatalogCursor>)((since, top) => Db2CatalogCursor.ByLastEdited(since, top)), Db2CatalogProjectionColumnNames.LastEdited }
};

public static IEnumerable<object[]> CursorMethods =>
from testData in CursorMethodToColumnNameMappings
select new object[] { testData[0] };
}
}
2 changes: 1 addition & 1 deletion tests/CatalogTests/Helpers/FeedPackageIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void PackageIdentityConstructorUsesFullString()
}

Assert.False(feedPackage.Equals(differentFeedPackage));
Assert.Equal(false, feedPackage.GetHashCode() == differentFeedPackage.GetHashCode());
Assert.NotEqual(feedPackage.GetHashCode(), differentFeedPackage.GetHashCode());
}
}
}
8 changes: 4 additions & 4 deletions tests/CatalogTests/Helpers/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public void GetNupkgMetadataWithLicenseUrl_ReturnsLicenseUrl()
);

// Assert
Assert.Equal(0, licenseFileTriples.Count());
Assert.Equal(0, licenseExpressionTriples.Count());
Assert.Equal(1, licenseUrlTriples.Count());
Assert.Empty(licenseFileTriples);
Assert.Empty(licenseExpressionTriples);
Assert.Single(licenseUrlTriples);
}

[Theory]
Expand Down Expand Up @@ -168,7 +168,7 @@ public void GetNupkgMetadataWithLicenseType_ReturnsLicense(string packageName, s

// Assert
Assert.Equal(expectedLicenseUrlNumber, licenseUrlTriples.Count());
Assert.Equal(1, licenseTriples.Count());
Assert.Single(licenseTriples);
Assert.Equal(licenseContent, result.Value);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/CatalogTests/PackageCatalogItemCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ public async Task CreateAsync_WhenBlobChangesBetweenReads_ReturnsInstanceFromHtt
CancellationToken.None);

AssertCorrect(item, test.FeedPackageDetails);
Assert.Equal(1, test.Handler.Requests.Count());
Assert.Single(test.Handler.Requests);

Assert.Equal(1, test.TelemetryService.TrackMetricCalls.Count);
Assert.Single(test.TelemetryService.TrackMetricCalls);

var call = test.TelemetryService.TrackMetricCalls[0];

Expand Down
2 changes: 1 addition & 1 deletion tests/CatalogTests/ReadOnlyGraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static void VerifyIdTriple(ReadOnlyGraph readOnlyGraph)
var idTriples = readOnlyGraph.GetTriplesWithSubjectPredicate(
readOnlyGraph.CreateUriNode(PackageUri),
readOnlyGraph.CreateUriNode(Schema.Predicates.Id));
Assert.Equal(1, idTriples.Count());
Assert.Single(idTriples);
Assert.Equal(PackageId, ((LiteralNode)idTriples.First().Object).Value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CatalogTests/Registration/RegistrationCollectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public async Task CreatesRegistrationsWithSemVer2()

// Assert
// Verify the contents of the legacy (non-SemVer 2.0.0) storage
Assert.Equal(1, _legacyStorage.Content.Count);
Assert.Single(_legacyStorage.Content);

var legacyCursorJson = _legacyStorage.Content.FirstOrDefault(pair => pair.Key.PathAndQuery.EndsWith("cursor.json"));
Assert.NotNull(legacyCursorJson.Key);
Expand Down Expand Up @@ -367,7 +367,7 @@ public async Task IgnoresSemVer2PackagesInLegacyStorageWhenSemVer2IsEnabled()
Assert.Null(legacyIndex.Key);
var legacyLeaf = _legacyStorage.Content.FirstOrDefault(pair => pair.Key.PathAndQuery.EndsWith("/testpackage.semver2/1.0.0-alpha.1.json"));
Assert.Null(legacyLeaf.Key);
Assert.Equal(1, _legacyStorage.Content.Count);
Assert.Single(_legacyStorage.Content);

var semVer2Cursor = _semVer2Storage.Content.FirstOrDefault(pair => pair.Key.PathAndQuery.EndsWith("cursor.json"));
Assert.Null(semVer2Cursor.Key);
Expand Down
7 changes: 5 additions & 2 deletions tests/CatalogTests/Registration/RegistrationEntryKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void EqualsIgnoresCaseAndComparesNormalized(string idA, string versionA,

[Theory]
[MemberData(nameof(EqualRegistrationEntryKeys))]
public void GetHashCodeIgnoresCaseAndUsesNormalized(string idA, string versionA, string idB, string versionB, bool expectedEquals)
public void GetHashCodeIgnoresCaseAndUsesNormalized(string idA, string versionA, string idB, string versionB)
{
// Arrange
var a = new RegistrationEntryKey(new RegistrationKey(idA), versionA);
Expand Down Expand Up @@ -60,6 +60,9 @@ public static IEnumerable<object[]> RegistrationEntryKeys
}
}

public static IEnumerable<object[]> EqualRegistrationEntryKeys => RegistrationEntryKeys.Where(a => (bool)a[4]);
public static IEnumerable<object[]> EqualRegistrationEntryKeys =>
RegistrationEntryKeys
.Where(a => (bool)a[4])
.Select(a => new object[] { a[0], a[1], a[2], a[3] });
}
}
7 changes: 5 additions & 2 deletions tests/CatalogTests/Registration/RegistrationKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void EqualsIgnoresCase(string idA, string idB, bool expectedEquals)

[Theory]
[MemberData(nameof(EqualRegistrationKeys))]
public void GetHashCodeIgnoresCaseAndUsesNormalized(string idA, string idB, bool expectedEquals)
public void GetHashCodeIgnoresCaseAndUsesNormalized(string idA, string idB)
{
// Arrange
var a = new RegistrationKey(idA);
Expand Down Expand Up @@ -72,6 +72,9 @@ public static IEnumerable<object[]> RegistrationKeys
}
}

public static IEnumerable<object[]> EqualRegistrationKeys => RegistrationKeys.Where(a => (bool)a[2]);
public static IEnumerable<object[]> EqualRegistrationKeys =>
RegistrationKeys
.Where(a => (bool)a[2])
.Select(a => new object[] { a[0], a[1] });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ public void CreatePageContent_SetsLicenseUrlAndExpressionProperly(
content.CreateUriNode(Schema.Predicates.LicenseFile));

// Assert
Assert.Equal(1, licenseUrlTriples.Count());
Assert.Equal(expectedLicenseUrlValue, licenseUrlTriples.First().Object.ToString());
Assert.Equal(1, licenseExpressionTriples.Count());
Assert.Equal(licenseExpression == null ? "" : licenseExpression, licenseExpressionTriples.First().Object.ToString());
Assert.Equal(0, licenseFileTriples.Count());
Assert.Equal(expectedLicenseUrlValue, Assert.Single(licenseUrlTriples).Object.ToString());
Assert.Equal(licenseExpression ?? "", Assert.Single(licenseExpressionTriples).Object.ToString());
Assert.Empty(licenseFileTriples);
}

public static IEnumerable<object[]> CreatePageContent_SetsDeprecationInformationProperly_Data
Expand Down
4 changes: 4 additions & 0 deletions tests/CatalogTests/RetryWithExponentialBackoffTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public static IEnumerable<object[]> ReturnsFalseIfResponseStatusBelow500OrWhitel
}
}

[Theory]
[MemberData(nameof(ReturnsFalseIfResponseStatusBelow500OrWhitelisted_Data))]
public void ReturnsFalseIfResponseStatusBelow500OrWhitelisted(Exception e, HttpStatusCode status)
{
var response = new HttpResponseMessage(status);
Expand Down Expand Up @@ -103,6 +105,8 @@ public static IEnumerable<object[]> ReturnsTrueIfResponseStatusAbove500_Data
}
}

[Theory]
[MemberData(nameof(ReturnsTrueIfResponseStatusAbove500_Data))]
public void ReturnsTrueIfResponseStatusAbove500(Exception e, HttpStatusCode status)
{
var response = new HttpResponseMessage(status);
Expand Down
6 changes: 3 additions & 3 deletions tests/NgTests/AggregateStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public async Task PropagatesDeleteToAllStorage()
await aggregateStorageRoot.DeleteAsync(new Uri("http://tempuri.org/firstone/test.txt"), CancellationToken.None);

// Assert
Assert.Equal(1, storage1.Content.Count);
Assert.Equal(1, storage2.Content.Count);
Assert.Equal(1, storage3.Content.Count);
Assert.Single(storage1.Content);
Assert.Single(storage2.Content);
Assert.Single(storage3.Content);

AssertUriAndContentDoesNotExist(storage1, new Uri("http://tempuri.org/firstone/test.txt"), "test1");
AssertUriAndContentDoesNotExist(storage2, new Uri("http://tempuri.org/secondone/test.txt"), "test1");
Expand Down
8 changes: 4 additions & 4 deletions tests/NgTests/AuditRecordHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task GetDeletionAuditRecords_FiltersOnPackage_EntryExists()
var auditEntries = await DeletionAuditEntry.GetAsync(CreateStorageFactory(auditingStorage, targetPackageIdentity), CancellationToken.None, targetPackageIdentity, logger: _logger);

// Assert
Assert.Equal(1, auditEntries.Count());
Assert.Single(auditEntries);

var auditEntry = auditEntries.ElementAt(0);

Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task GetDeletionAuditRecords_FiltersOnMinTimestamp_EntryExists()
var auditEntries = await DeletionAuditEntry.GetAsync(auditingStorage, CancellationToken.None, minTime: minTimestamp, logger: _logger);

// Assert
Assert.Equal(1, auditEntries.Count());
Assert.Single(auditEntries);

var auditEntry = auditEntries.ElementAt(0);

Expand Down Expand Up @@ -153,7 +153,7 @@ public async Task GetDeletionAuditRecords_FiltersOnMaxTimestamp_EntryExists()
var auditEntries = await DeletionAuditEntry.GetAsync(auditingStorage, CancellationToken.None, maxTime: maxTimestamp, logger: _logger);

// Assert
Assert.Equal(1, auditEntries.Count());
Assert.Single(auditEntries);

var auditEntry = auditEntries.ElementAt(0);

Expand Down Expand Up @@ -195,7 +195,7 @@ public async Task GetDeletionAuditRecords_FiltersOnAll_EntryExists()
var auditEntries = await DeletionAuditEntry.GetAsync(CreateStorageFactory(auditingStorage, targetPackageIdentity), CancellationToken.None, targetPackageIdentity, minTimestamp, maxTimestamp, logger: _logger);

// Assert
Assert.Equal(1, auditEntries.Count());
Assert.Single(auditEntries);

var auditEntry = auditEntries.ElementAt(0);

Expand Down
2 changes: 1 addition & 1 deletion tests/NgTests/Db2CatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace NgTests
{
public class Db2CatalogTests
public class Db2CatalogTests : IDisposable
{
private const string PackageContentUrlFormat = "https://unittest.org/packages/{id-lower}/{version-lower}.nupkg";

Expand Down
Loading

0 comments on commit bfd836b

Please sign in to comment.