public void GetSystemStatistics_HappyPathTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var createdDate = DateTime.UtcNow.ToString(); var systemStatisticsToReturn = new List <SystemStatistic>(); systemStatisticsToReturn.Add(new SystemStatistic() { WebSiteIsUp = true, DatabaseIsUp = true, AzureFunctionIsUp = true, Created = createdDate, }); tgimbaService.Setup(x => x.GetSystemStatistics(It.IsAny <string>(), It.IsAny <string>())) .Returns(systemStatisticsToReturn); IActionResult result = tgimbaApi.GetSystemStatistics("encodedUser", "encodedToken"); OkObjectResult requestResult = (OkObjectResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(200, requestResult.StatusCode); tgimbaService.Verify(x => x.GetSystemStatistics(It.IsAny <string>(), It.IsAny <string>()) , Times.Once); var systemStatistics = (List <SystemStatistic>)requestResult.Value; Assert.AreEqual(1, systemStatistics.Count); Assert.AreEqual(systemStatisticsToReturn, systemStatistics); }
public void GetSystemStatistics_GeneralErrorTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var exception = "I am an exception"; tgimbaService.Setup(x => x.GetSystemStatistics(It.IsAny <string>(), It.IsAny <string>())) .Throws(new Exception(exception)); IActionResult result = tgimbaApi.GetSystemStatistics("encodedUser", "encodedToken"); StatusCodeResult requestResult = (StatusCodeResult)result; tgimbaService.Verify(x => x.Log(It.Is <string>(s => s == exception)), Times.Once); Assert.IsNotNull(requestResult); Assert.AreEqual(500, requestResult.StatusCode); }
public void GetSystemStatistics_NoResultEmptyCollection() { var tgimbaService = new Mock <ITgimbaService>(); var validationHelper = new Mock <IValidationHelper>(); var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var systemStatisticsToReturn = new List <SystemStatistic>(); tgimbaService.Setup(x => x.GetSystemStatistics(It.IsAny <string>(), It.IsAny <string>())) .Returns(systemStatisticsToReturn); IActionResult result = tgimbaApi.GetSystemStatistics("encodedUser", "encodedToken"); StatusCodeResult requestResult = (StatusCodeResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(404, requestResult.StatusCode); }