Implement DeleteMany in FeedbackReceiversController
This commit is contained in:
parent
097381a75a
commit
2c53668f63
5 changed files with 62 additions and 14 deletions
|
@ -59,7 +59,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
|||
|
||||
// Assert
|
||||
Assert.IsType<NoContentResult>(result);
|
||||
mockService.Verify(s => s.DeleteOneAsync("bad_guid_but_unit_test_works_cause_validation_doesnt"),
|
||||
mockService.Verify(s => s.DeleteManyAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,8 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
|||
|
||||
// Assert
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
mockService.Verify(s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
||||
mockService.Verify(
|
||||
s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
|
@ -95,7 +96,8 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
|||
|
||||
// Assert
|
||||
Assert.IsType<NotFoundObjectResult>(result);
|
||||
mockService.Verify(s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
||||
mockService.Verify(
|
||||
s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_DeleteOneAsync_Ok()
|
||||
public async Task Test_DeleteManyAsync_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var mongoDatabaseMock = new Mock<IMongoDatabase>();
|
||||
|
@ -153,7 +153,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services
|
|||
|
||||
// Test
|
||||
var service = new FeedbackReceiverService(mongoClientMock.Object, mongoSettingsMock.Object);
|
||||
await service.DeleteOneAsync("insert_guid_here");
|
||||
await service.DeleteManyAsync(new []{"insert_guid_here"});
|
||||
|
||||
// Assert
|
||||
mongoClientMock.Verify(i => i.GetDatabase("MyDB", null), Times.Once());
|
||||
|
@ -162,7 +162,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services
|
|||
Times.Once());
|
||||
|
||||
mongoCollectionMock.Verify(
|
||||
i => i.DeleteOneAsync(It.IsAny<FilterDefinition<FeedbackReceiver>>(), It.IsAny<CancellationToken>()),
|
||||
i => i.DeleteManyAsync(It.IsAny<FilterDefinition<FeedbackReceiver>>(), It.IsAny<CancellationToken>()),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ namespace Retroactiune.Controllers
|
|||
/// </summary>
|
||||
/// <param name="guid">The guid of the item to be deleted.</param>
|
||||
/// <returns>A NoContent result.</returns>
|
||||
/// <response code="204">The delete is successful.</response>
|
||||
/// <response code="400">The delete is unsuccessful.</response>
|
||||
/// <response code="204">The delete is submitted.</response>
|
||||
/// <response code="400">The request is invalid.</response>
|
||||
[HttpDelete("{guid}")]
|
||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
|
@ -79,7 +79,7 @@ namespace Retroactiune.Controllers
|
|||
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
|
||||
string guid)
|
||||
{
|
||||
await _service.DeleteOneAsync(guid);
|
||||
await _service.DeleteManyAsync(new [] {guid});
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
@ -132,5 +132,32 @@ namespace Retroactiune.Controllers
|
|||
{
|
||||
return Ok(await _service.FindAsync(filter, offset, limit));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes FeedbackReceiver identified by ids.
|
||||
/// </summary>
|
||||
/// <param name="ids">A list of FeedbackReceiver ids.</param>
|
||||
/// <response code="204">The request to delete the items has been submitted.</response>
|
||||
/// <response code="404">The request is invalid.</response>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(BasicResponse),StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> DeleteTokens([Required] IEnumerable<string> ids)
|
||||
{
|
||||
// TODO: Unit test, integration test.
|
||||
try
|
||||
{
|
||||
await _service.DeleteManyAsync(ids);
|
||||
return NoContent();
|
||||
}
|
||||
catch (GenericServiceException e)
|
||||
{
|
||||
return BadRequest(new BasicResponse
|
||||
{
|
||||
Message = e.Message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,12 +45,12 @@ namespace Retroactiune.Services
|
|||
}
|
||||
}
|
||||
|
||||
public async Task DeleteOneAsync(string guid)
|
||||
public async Task DeleteManyAsync(IEnumerable<string> guids)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = new FilterDefinitionBuilder<FeedbackReceiver>();
|
||||
await _collection.DeleteOneAsync(filter.Eq(i => i.Id, guid));
|
||||
await _collection.DeleteManyAsync(filter.In(i => i.Id, guids));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -6,8 +6,27 @@ namespace Retroactiune.Services
|
|||
{
|
||||
public interface IFeedbackReceiverService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates feedback receivers.
|
||||
/// </summary>
|
||||
/// <param name="items">A collection of feedback receivers.</param>
|
||||
/// <returns>Nothing.</returns>
|
||||
public Task CreateManyAsync(IEnumerable<FeedbackReceiver> items);
|
||||
public Task DeleteOneAsync(string guid);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes one FeedbackReceiver.
|
||||
/// </summary>
|
||||
/// <param name="guids">A list of FeedbackReceiver guids to delete.</param>
|
||||
/// <returns>Nothing.</returns>
|
||||
public Task DeleteManyAsync(IEnumerable<string> guids);
|
||||
|
||||
/// <summary>
|
||||
/// Finds FeedbackReceivers.
|
||||
/// </summary>
|
||||
/// <param name="guid">A list of guids to filter the FeedbackReceivers. </param>
|
||||
/// <param name="offset">An offset, it skips the specified FeedbackReceivers.</param>
|
||||
/// <param name="limit">A limit for the returned results.</param>
|
||||
/// <returns>A collection of FeedbackReceivers.</returns>
|
||||
Task<IEnumerable<FeedbackReceiver>> FindAsync(IEnumerable<string> guid, int? offset = null, int? limit = null);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue