Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some incorrect as usage and better leverage Assert.IsType #10038

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void ConfiguresTelemetryClientWrapper()

// Assert
Assert.NotNull(telemetryClient);
Assert.IsType<TelemetryClientWrapper>(telemetryClient);

var telemetryClientWrapper = (TelemetryClientWrapper)telemetryClient;
var telemetryClientWrapper = Assert.IsType<TelemetryClientWrapper>(telemetryClient);

Assert.Equal(
_appConfiguration.AppInsightsInstrumentationKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class CorrectIsLatestPackagesMethod : FactsBase
[Fact]
public void WhenPackagesHaveCorrectIsLatestReturnEmptyArray()
{
var result = CorrectIsLatestController.CorrectIsLatestPackages() as JsonResult;
var packages = result.Data as List<CorrectIsLatestPackage>;
var result = (JsonResult)CorrectIsLatestController.CorrectIsLatestPackages();
var packages = (List<CorrectIsLatestPackage>)result.Data;

Assert.Empty(packages);
}
Expand Down Expand Up @@ -66,8 +66,8 @@ public void WhenPackageIsLatestAndIsUnlistedReturnsHasIsLatestUnlistedAsTrue(boo
var fakeContext = GetFakeContext();
fakeContext.PackageRegistrations.Add(packageRegistration);

var result = CorrectIsLatestController.CorrectIsLatestPackages() as JsonResult;
var correctIsLatestPackages = result.Data as List<CorrectIsLatestPackage>;
var result = (JsonResult)CorrectIsLatestController.CorrectIsLatestPackages();
var correctIsLatestPackages = (List<CorrectIsLatestPackage>)result.Data;

Assert.NotEmpty(correctIsLatestPackages);

Expand Down Expand Up @@ -115,8 +115,8 @@ public void WhenPackageHasMultipleIsLatestReturnSum(bool isLatest, bool isLatest
var fakeContext = GetFakeContext();
fakeContext.PackageRegistrations.Add(packageRegistration);

var result = CorrectIsLatestController.CorrectIsLatestPackages() as JsonResult;
var correctIsLatestPackages = result.Data as List<CorrectIsLatestPackage>;
var result = (JsonResult)CorrectIsLatestController.CorrectIsLatestPackages();
var correctIsLatestPackages = (List<CorrectIsLatestPackage>)result.Data;

Assert.NotEmpty(packages);

Expand Down Expand Up @@ -149,7 +149,7 @@ public class ReflowPackagesMethod : FactsBase
public async Task WhenInvalidReturnsBadRequest(CorrectIsLatestRequest request)
{
// Act
var result = await CorrectIsLatestController.ReflowPackages(request) as JsonResult;
var result = (JsonResult)await CorrectIsLatestController.ReflowPackages(request);

// Assert
Assert.Equal(((int)HttpStatusCode.BadRequest), CorrectIsLatestController.Response.StatusCode);
Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task WhenPackageValidReturnsReflowCount()
};

// Act
var result = await CorrectIsLatestController.ReflowPackages(request) as JsonResult;
var result = (JsonResult)await CorrectIsLatestController.ReflowPackages(request);

// Assert
Assert.Equal(((int)HttpStatusCode.OK), CorrectIsLatestController.Response.StatusCode);
Expand Down Expand Up @@ -207,7 +207,7 @@ public async Task WhenPackageInvalidReturnsReflowCount()
};

// Act
var result = await CorrectIsLatestController.ReflowPackages(request) as JsonResult;
var result = (JsonResult)await CorrectIsLatestController.ReflowPackages(request);

// Assert
Assert.Equal(((int)HttpStatusCode.OK), CorrectIsLatestController.Response.StatusCode);
Expand Down Expand Up @@ -236,7 +236,7 @@ public async Task WhenPackageValidAndInvalidReturnsReflowCount()
};

// Act
var result = await CorrectIsLatestController.ReflowPackages(request) as JsonResult;
var result = (JsonResult)await CorrectIsLatestController.ReflowPackages(request);

// Assert
Assert.Equal(((int)HttpStatusCode.OK), CorrectIsLatestController.Response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1743,8 +1743,7 @@ public async Task WillThrowIfAPackageWithTheIdAndNuGetVersionDoesNotExist()

var result = await controller.DeletePackage("theId", "1.0.42");

Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
var statusCodeResult = Assert.IsType<HttpStatusCodeWithBodyResult>(result);
Assert.Equal(404, statusCodeResult.StatusCode);
Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"), statusCodeResult.StatusDescription);
controller.MockPackageUpdateService.Verify(x => x.MarkPackageUnlistedAsync(It.IsAny<Package>(), true, true), Times.Never());
Expand Down
Loading