diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs index 76a69cf..d57896b 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs @@ -59,7 +59,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers // Assert Assert.IsType(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); } @@ -70,7 +70,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers var mapper = TestUtils.GetMapper(); var mockService = new Mock(); mockService.Setup(i => i.FindAsync(It.IsAny>(), null, null)) - .ReturnsAsync(new [] {new FeedbackReceiver()}); + .ReturnsAsync(new[] {new FeedbackReceiver()}); // Test var controller = new FeedbackReceiversController(mockService.Object, mapper, null); @@ -78,7 +78,8 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers // Assert Assert.IsType(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(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); } @@ -106,7 +108,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers var mapper = TestUtils.GetMapper(); var mockService = new Mock(); var filterArr = filter as string[] ?? filter.ToArray(); - + // Test var controller = new FeedbackReceiversController(mockService.Object, mapper, null); var result = await controller.List(filterArr, offset, limit); diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs index 9825c16..13effb7 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs @@ -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(); @@ -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>(), It.IsAny()), + i => i.DeleteManyAsync(It.IsAny>(), It.IsAny()), Times.Once()); } diff --git a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs index 9c8de7d..c50d56e 100644 --- a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs +++ b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs @@ -70,8 +70,8 @@ namespace Retroactiune.Controllers /// /// The guid of the item to be deleted. /// A NoContent result. - /// The delete is successful. - /// The delete is unsuccessful. + /// The delete is submitted. + /// The request is invalid. [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)); } + + /// + /// Deletes FeedbackReceiver identified by ids. + /// + /// A list of FeedbackReceiver ids. + /// The request to delete the items has been submitted. + /// The request is invalid. + /// + [HttpDelete] + [ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(BasicResponse),StatusCodes.Status400BadRequest)] + public async Task DeleteTokens([Required] IEnumerable ids) + { + // TODO: Unit test, integration test. + try + { + await _service.DeleteManyAsync(ids); + return NoContent(); + } + catch (GenericServiceException e) + { + return BadRequest(new BasicResponse + { + Message = e.Message + }); + } + } } } \ No newline at end of file diff --git a/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs b/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs index a819b02..a4a6337 100644 --- a/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs +++ b/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs @@ -45,12 +45,12 @@ namespace Retroactiune.Services } } - public async Task DeleteOneAsync(string guid) + public async Task DeleteManyAsync(IEnumerable guids) { try { var filter = new FilterDefinitionBuilder(); - await _collection.DeleteOneAsync(filter.Eq(i => i.Id, guid)); + await _collection.DeleteManyAsync(filter.In(i => i.Id, guids)); } catch (Exception e) { diff --git a/Retroactiune.WebAPI/Services/IFeedbackReceiverService.cs b/Retroactiune.WebAPI/Services/IFeedbackReceiverService.cs index 4399d15..b8c27ab 100644 --- a/Retroactiune.WebAPI/Services/IFeedbackReceiverService.cs +++ b/Retroactiune.WebAPI/Services/IFeedbackReceiverService.cs @@ -6,8 +6,27 @@ namespace Retroactiune.Services { public interface IFeedbackReceiverService { + /// + /// Creates feedback receivers. + /// + /// A collection of feedback receivers. + /// Nothing. public Task CreateManyAsync(IEnumerable items); - public Task DeleteOneAsync(string guid); + + /// + /// Deletes one FeedbackReceiver. + /// + /// A list of FeedbackReceiver guids to delete. + /// Nothing. + public Task DeleteManyAsync(IEnumerable guids); + + /// + /// Finds FeedbackReceivers. + /// + /// A list of guids to filter the FeedbackReceivers. + /// An offset, it skips the specified FeedbackReceivers. + /// A limit for the returned results. + /// A collection of FeedbackReceivers. Task> FindAsync(IEnumerable guid, int? offset = null, int? limit = null); } } \ No newline at end of file