public async Task GetAdventure_Failed() { _adventureServiceMock.Setup(opp => opp.GetAdventureDetails(1)).ThrowsAsync(new Exception()); var controller = new AdventureController(_adventureServiceMock.Object); var res = await controller.GetAdventure(1); var ObjRes = res.Result as StatusCodeResult; Assert.NotNull(res); Assert.True(ObjRes.StatusCode == 500); }
public async Task GetAdventure_NotFound() { _adventureServiceMock.Setup(adv => adv.GetAdventureDetails(1)).ReturnsAsync(null as Domain.Adventure); var controller = new AdventureController(_adventureServiceMock.Object); var res = await controller.GetAdventure(1); var objResult = res.Result as NotFoundResult; Assert.NotNull(res); Assert.True(objResult.StatusCode == (int)HttpStatusCode.NotFound); }
public async Task GetAdventure_BadRequest() { var result = new Domain.Adventure { AdventureId = 1, FirstPlot = new Domain.Plot(), Title = "abc" }; _adventureServiceMock.Setup(adv => adv.GetAdventureDetails(It.IsAny <int>())).ReturnsAsync(result); var controller = new AdventureController(_adventureServiceMock.Object); var res = await controller.GetAdventure(-1); var ObjRes = res.Result as BadRequestResult; Assert.NotNull(res); Assert.True(ObjRes.StatusCode == 400); }
public async Task GetAdventure_OK() { var result = new Domain.Adventure { AdventureId = 1, FirstPlot = new Domain.Plot(), Title = "abc" }; _adventureServiceMock.Setup(adv => adv.GetAdventureDetails(1)).ReturnsAsync(result); var controller = new AdventureController(_adventureServiceMock.Object); var res = await controller.GetAdventure(1); var objResult = res.Result as ObjectResult; Assert.NotNull(res); Assert.True(objResult.StatusCode == (int)HttpStatusCode.OK); var value = Assert.IsType <Domain.Adventure>(objResult.Value); Assert.Equal(result.AdventureId, value.AdventureId); Assert.Equal(result.Title, value.Title); Assert.Equal(result.FirstPlot.PlotId, value.FirstPlot.PlotId); }