public async Task MasterySuccess() { //Arrange var playerName = "Testing Name"; var playerRegion = "Testing Region"; var championName = "Testing Champion"; var expected = "Mastery"; var mockRiotApiService = new Mock <IRiotApiService>(); mockRiotApiService.Setup(r => r.GetMastery(playerName, playerRegion, championName)).ReturnsAsync(expected); var controller = new PlayerStatsController(mockRiotApiService.Object); //Act var result = await controller.Mastery(playerName, playerRegion, championName); //Assert var actionResult = Assert.IsType <ActionResult <string> >(result); var returnValue = Assert.IsType <string>(actionResult.Value); Assert.Equal(expected, returnValue); }
public async Task MasteryGenericError() { //Arrange var playerName = "Testing Name"; var playerRegion = "Testing Region"; var championName = "Testing Champion"; var expected = "Server error"; var mockRiotApiService = new Mock <IRiotApiService>(); mockRiotApiService.Setup(r => r.GetMastery(playerName, playerRegion, championName)).ThrowsAsync(new Exception()); var controller = new PlayerStatsController(mockRiotApiService.Object); //Act var result = await controller.Mastery(playerName, playerRegion, championName); //Assert var actionResult = Assert.IsType <ActionResult <string> >(result); var objectResult = Assert.IsType <ObjectResult>(actionResult.Result); Assert.Equal(500, objectResult.StatusCode); var returnValue = Assert.IsType <string>(objectResult.Value); Assert.Equal(expected, returnValue); }