public void LogMessage_HappyPathTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var request = GetLogMessageRequest(); IActionResult result = tgimbaApi.Log(request); OkResult requestResult = (OkResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(200, requestResult.StatusCode); tgimbaService.Verify(x => x.Log(It.IsAny <string>()), Times.Never); tgimbaService.Verify(x => x.LogAuthenticated(It.Is <string>(s => s == request.Message), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void LogMessage_ValidationError() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var request = GetLogMessageRequest(); validationHelper.Setup(x => x.IsValidRequest (It.IsAny <LogMessageRequest>())) .Throws(new ArgumentNullException("")); IActionResult result = tgimbaApi.Log(request); Assert.IsNotNull(result); Assert.AreEqual(500, Convert.ToInt32(System.Net.HttpStatusCode.InternalServerError)); tgimbaService.Verify(x => x.Log(It.IsAny <string>()), Times.Never); tgimbaService.Verify(x => x.LogAuthenticated(It.Is <string>(s => s == request.Message), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void Log_HappyPathTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); var request = new LogMessageRequest() { Token = new TokenRequest() { EncodedUserName = "******", EncodedToken = "encodedToken" }, Message = "IAmALogMessage" }; IActionResult result = tgimbaApi.Log(request); OkResult requestResult = (OkResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(200, requestResult.StatusCode); tgimbaService.Verify(x => x.LogAuthenticated(It.Is <string>(s => s == request.Message), It.IsAny <string>(), It.IsAny <string>()) , Times.Once); }
public void Log_GeneralErrorTest() { var tgimbaApi = new SharedTgimbaApiController(this.tgimbaService.Object, this.validationHelper.Object); tgimbaService.Setup(x => x.LogAuthenticated(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Throws(new Exception("I am an exception")); var request = new LogMessageRequest() { Token = new TokenRequest() { EncodedUserName = "******", EncodedToken = "encodedToken" }, Message = "IAmALogMessage" }; IActionResult result = tgimbaApi.Log(request); StatusCodeResult requestResult = (StatusCodeResult)result; Assert.IsNotNull(requestResult); Assert.AreEqual(500, requestResult.StatusCode); }