public void UpdateRow_DatabaseServiceThrowsExceptions_ReturnsValidResults() { // Arrange string dbName = "testDatabase"; string tableName = "testTable"; Row row = new Row { Id = 1 }; Dictionary <Exception, Type> resultsDictionary = new Dictionary <Exception, Type> { { new ArgumentException(), typeof(BadRequestResult) }, { new DatabaseNotFoundException(), typeof(NotFoundResult) }, { new TableNotFoundException(), typeof(NotFoundResult) }, { new RowNotFoundException(), typeof(NotFoundResult) }, { new InvalidRowException(), typeof(BadRequestErrorMessageResult) }, { new DbServiceException(), typeof(InternalServerErrorResult) } }; foreach (KeyValuePair <Exception, Type> result in resultsDictionary) { // Arrange - mock dbService this._dbServiceMock.Setup(s => s.UpdateRow(dbName, tableName, row)) .Throws(result.Key); // Arrange - create target DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object); // Act IHttpActionResult actionResult = target.UpdateRow(dbName, tableName, row); // Assert Assert.IsInstanceOf(result.Value, actionResult); } }
public void UpdateRow_DatabaseServiceUpdatesRow_ReturnsOkResult() { // Arrange string dbName = "testDatabase"; string tableName = "testTable"; Row row = new Row { Id = 1 }; // Arrange - create target DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object); // Act IHttpActionResult actionResult = target.UpdateRow(dbName, tableName, row); // Assert Assert.IsInstanceOf <OkResult>(actionResult); this._dbServiceMock.Verify(s => s.UpdateRow(dbName, tableName, row), Times.Once); }