public void GetTableProjection_DatabaseServiceThrowsExceptions_ReturnsValidResults() { // Arrange string dbName = "testDatabase"; string tableName = "testTable"; string[] attributesNames = { "firstAttribute" }; Dictionary <Exception, Type> resultsDictionary = new Dictionary <Exception, Type> { { new ArgumentException(), typeof(BadRequestResult) }, { new AttributeNotFoundException(), typeof(BadRequestErrorMessageResult) }, { new DatabaseNotFoundException(), typeof(NotFoundResult) }, { new DbServiceException(), typeof(InternalServerErrorResult) } }; foreach (KeyValuePair <Exception, Type> result in resultsDictionary) { // Arrange - mock dbService this._dbServiceMock.Setup(s => s.GetTableProjection(dbName, tableName, attributesNames)) .Throws(result.Key); // Arrange - create target DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object); // Act IHttpActionResult actionResult = target.GetTableProjection(dbName, tableName, attributesNames); // Assert Assert.IsInstanceOf(result.Value, actionResult); } }
public void GetTableProjection_DatabaseServiceReturnsNull_ReturnsNotFoundResult() { // Arrange string dbName = "testDatabase"; string tableName = "testTable"; string[] attributesNames = { "firstAttribute" }; // Arrange - mock dbService this._dbServiceMock.Setup(s => s.GetTableProjection(dbName, tableName, attributesNames)) .Returns((Table)null); // Arrange - create target DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object); // Act IHttpActionResult actionResult = target.GetTableProjection(dbName, tableName, attributesNames); // Assert Assert.IsInstanceOf <NotFoundResult>(actionResult); }
public void GetTableProjection_DatabaseServiceReturnsTable_ReturnsTableDto() { // Arrange string dbName = "testDatabase"; string[] attributesNames = { "firstAttribute" }; Table table = new Table { Name = "testTable", Attributes = { new Domain.Models.Attribute { Name = attributesNames.First(), Type = "someType" } }, Rows = { { 0, new Row { Id = 0, Value ={ "firstValue" } } } } }; TableDto tableDto = new TableDto { Name = table.Name, Attributes = table.Attributes, Rows = table.Rows.Values }; // Arrange - mock dbService this._dbServiceMock.Setup(s => s.GetTableProjection(dbName, table.Name, attributesNames)) .Returns(table); // Arrange - create target DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object); // Act IHttpActionResult actionResult = target.GetTableProjection(dbName, table.Name, attributesNames); OkNegotiatedContentResult <TableDto> contentResult = actionResult as OkNegotiatedContentResult <TableDto>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(tableDto.Name, contentResult.Content.Name); Assert.AreEqual(tableDto.Attributes, contentResult.Content.Attributes); Assert.AreEqual(tableDto.Rows, contentResult.Content.Rows); }