diff --git a/Retroactiune.Core/Interfaces/ITokensService.cs b/Retroactiune.Core/Interfaces/ITokensService.cs
index 6062263..f57d37f 100644
--- a/Retroactiune.Core/Interfaces/ITokensService.cs
+++ b/Retroactiune.Core/Interfaces/ITokensService.cs
@@ -31,5 +31,12 @@ namespace Retroactiune.Core.Interfaces
/// Filters object for filtering results.
/// A list of tokens matching the filters.
public Task> ListTokens(TokenListFilters filters);
+
+ ///
+ /// Deletes tokens, by their associated FeedbackReceiverId.
+ ///
+ /// A list of FeedbackReceiverIDs.
+ /// The result of the delete operation.
+ public Task DeleteManyByFeedbackReceiverIdAsync(IEnumerable feedbackReceiverIds);
}
}
\ No newline at end of file
diff --git a/Retroactiune.Core/Services/TokenService.cs b/Retroactiune.Core/Services/TokensService.cs
similarity index 84%
rename from Retroactiune.Core/Services/TokenService.cs
rename to Retroactiune.Core/Services/TokensService.cs
index b01b3fe..5257e78 100644
--- a/Retroactiune.Core/Services/TokenService.cs
+++ b/Retroactiune.Core/Services/TokensService.cs
@@ -8,11 +8,11 @@ using Retroactiune.Core.Interfaces;
namespace Retroactiune.Core.Services
{
- public class TokenService : ITokensService
+ public class TokensService : ITokensService
{
private readonly IMongoCollection _collection;
- public TokenService(IMongoClient client, IDatabaseSettings settings)
+ public TokensService(IMongoClient client, IDatabaseSettings settings)
{
var database = client.GetDatabase(settings.DatabaseName);
_collection = database.GetCollection(settings.TokensCollectionName);
@@ -106,5 +106,18 @@ namespace Retroactiune.Core.Services
var results = await _collection.FindAsync(tokensListFilter);
return await results.ToListAsync();
}
+
+ public async Task DeleteManyByFeedbackReceiverIdAsync(IEnumerable feedbackReceiverIds)
+ {
+ try
+ {
+ var filter = new FilterDefinitionBuilder();
+ await _collection.DeleteManyAsync(filter.In(i => i.FeedbackReceiverId, feedbackReceiverIds));
+ }
+ catch (Exception e)
+ {
+ throw new GenericServiceException($"Operation failed: {e.Message} {e.StackTrace}");
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiversController.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiversController.cs
index 55f07f4..f5179a1 100644
--- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiversController.cs
+++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiversController.cs
@@ -124,13 +124,10 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Arrange
await _mongoDb.DropAsync();
var guids = new List();
- byte index = 0;
var feedbackReceivers = items as FeedbackReceiver[] ?? items.ToArray();
foreach (var i in feedbackReceivers)
{
- i.Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, index, 4, 5, 6, 7, 8, 9, index, 11, 14}))
- .ToString();
- index += 1;
+ i.Id = ObjectId.GenerateNewId().ToString();
guids.Add(i.Id);
}
@@ -151,19 +148,49 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
Assert.Equal(0L, docs);
}
+ [Fact]
+ public async Task Test_Delete_OK_With_Tokens()
+ {
+ // Arrange
+ await _mongoDb.DropAsync();
+ var feedbackReceiver = new FeedbackReceiver
+ {
+ Id = ObjectId.GenerateNewId().ToString(),
+ Description = "blam",
+ CreatedAt = DateTime.UtcNow,
+ Name = "test"
+ };
+ await _mongoDb.FeedbackReceiverCollection.InsertOneAsync(feedbackReceiver);
+
+
+ // Test
+ var httpResponse = await _client.DeleteAsync($"/api/v1/FeedbackReceivers/{feedbackReceiver.Id}",
+ CancellationToken.None);
+ await _client.PostAsync("/api/v1/Tokens/",
+ new StringContent($"{{\"numberOfTokens\": 100, \"feedbackReceiverId\": \"{feedbackReceiver.Id}\"}}",
+ Encoding.UTF8,
+ "application/json"));
+
+
+ // Assert
+ Assert.Equal(HttpStatusCode.NoContent, httpResponse.StatusCode);
+ var feedbackReceivers =
+ await _mongoDb.FeedbackReceiverCollection.CountDocumentsAsync(FilterDefinition.Empty);
+ var tokens = await _mongoDb.TokensCollection.CountDocumentsAsync(FilterDefinition.Empty);
+ Assert.Equal(0L, feedbackReceivers);
+ Assert.Equal(0L, tokens);
+ }
+
[Theory, AutoData]
public async Task Test_DeleteMany_OK(IEnumerable items)
{
// Arrange
await _mongoDb.DropAsync();
var guids = new List();
- byte index = 0;
var feedbackReceivers = items as FeedbackReceiver[] ?? items.ToArray();
foreach (var i in feedbackReceivers)
{
- i.Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, index, 4, 5, 6, 7, 8, 9, index, 11, 14}))
- .ToString();
- index += 1;
+ i.Id = ObjectId.GenerateNewId().ToString();
guids.Add(i.Id);
}
@@ -194,7 +221,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
await _mongoDb.DropAsync();
var feedbackReceiver = new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3",
Description = "something",
CreatedAt = DateTime.UnixEpoch
@@ -248,21 +275,21 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
{
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Two",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Three",
Description = "something",
CreatedAt = DateTime.UnixEpoch
@@ -294,21 +321,21 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
{
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Two",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Three",
Description = "something",
CreatedAt = DateTime.UnixEpoch
@@ -344,21 +371,21 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
{
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Two",
Description = "something",
CreatedAt = DateTime.UnixEpoch
},
new FeedbackReceiver
{
- Id = new BsonObjectId(new ObjectId(new byte[] {3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14})).ToString(),
+ Id = ObjectId.GenerateNewId().ToString(),
Name = "N4m3_Three",
Description = "something",
CreatedAt = DateTime.UnixEpoch
diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs
index f81662b..a58e422 100644
--- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs
+++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestTokensController.cs
@@ -116,13 +116,10 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
await _mongoDb.DropAsync();
var guids = new List();
var tokensArr = tokens as Token[] ?? tokens.ToArray();
- byte index = 0;
foreach (var i in tokensArr)
{
- i.Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, index, 4, 5, 6, 7, 8, 9, index, 11, 14}))
- .ToString();
- i.FeedbackReceiverId = i.Id;
- index += 1;
+ i.Id = ObjectId.GenerateNewId().ToString();
+ i.FeedbackReceiverId = ObjectId.GenerateNewId().ToString();
guids.Add(i.Id);
}
@@ -161,13 +158,10 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
await _mongoDb.DropAsync();
var guids = new List();
var tokensArr = tokens as Token[] ?? tokens.ToArray();
- byte index = 0;
foreach (var i in tokensArr)
{
- i.Id = new BsonObjectId(new ObjectId(new byte[] {1, 2, index, 4, 5, 6, 7, 8, 9, index, 11, 14}))
- .ToString();
- i.FeedbackReceiverId = i.Id;
- index += 1;
+ i.Id = ObjectId.GenerateNewId().ToString();
+ i.FeedbackReceiverId = ObjectId.GenerateNewId().ToString();
guids.Add(i.Id);
}
@@ -275,7 +269,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
Assert.Single(items);
Assert.Equal(expectedTokens[0], items[0]);
}
-
+
[Fact]
public async Task Test_ListTokens_Filter_Ids()
{
@@ -303,7 +297,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
Assert.Single(items);
Assert.Equal(expectedTokens[0], items[0]);
}
-
+
[Fact]
public async Task Test_ListTokens_Filter_CreatedRange()
{
diff --git a/Retroactiune.UnitTests/Retroactiune.Core/Services/TestTokensService.cs b/Retroactiune.UnitTests/Retroactiune.Core/Services/TestTokensService.cs
index 9bdbd81..001fec4 100644
--- a/Retroactiune.UnitTests/Retroactiune.Core/Services/TestTokensService.cs
+++ b/Retroactiune.UnitTests/Retroactiune.Core/Services/TestTokensService.cs
@@ -36,7 +36,7 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
.Returns(mongoCollectionMock.Object);
// Test & Assert
- var service = new TokenService(mongoClientMock.Object, mongoSettingsMock.Object);
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
await Assert.ThrowsAsync(async () => { await service.GenerateTokensAsync(-1, ""); });
}
@@ -64,7 +64,7 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
// Test
var expiryTime = DateTime.UtcNow;
- var service = new TokenService(mongoClientMock.Object, mongoSettingsMock.Object);
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
await service.GenerateTokensAsync(3, "Hello", expiryTime);
// Assert
@@ -105,7 +105,7 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
.Returns(mongoCollectionMock.Object);
// Test
- var service = new TokenService(mongoClientMock.Object, mongoSettingsMock.Object);
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
await service.DeleteTokens(new[] {"test_id"});
// Assert
@@ -140,10 +140,11 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
.Returns(mongoCollectionMock.Object);
mongoCollectionMock.Setup(i => i.FindAsync(It.IsAny>(),
- It.IsAny>(), It.IsAny())).ReturnsAsync(mongoCursorMock.Object);
+ It.IsAny>(), It.IsAny()))
+ .ReturnsAsync(mongoCursorMock.Object);
// Test
- var service = new TokenService(mongoClientMock.Object, mongoSettingsMock.Object);
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
var result = await service.ListTokens(new TokenListFilters());
// Assert
@@ -154,7 +155,7 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
It.IsAny>(),
It.IsAny()), Times.Once);
}
-
+
[Fact]
public async Task Test_ListTokens_Filters_Ok()
{
@@ -179,13 +180,14 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
.Returns(mongoCollectionMock.Object);
mongoCollectionMock.Setup(i => i.FindAsync(It.IsAny>(),
- It.IsAny>(), It.IsAny())).ReturnsAsync(mongoCursorMock.Object);
+ It.IsAny>(), It.IsAny()))
+ .ReturnsAsync(mongoCursorMock.Object);
// Test
- var service = new TokenService(mongoClientMock.Object, mongoSettingsMock.Object);
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
var result = await service.ListTokens(new TokenListFilters
{
- Ids = new []{"a", "b"},
+ Ids = new[] {"a", "b"},
FeedbackReceiverId = "abc",
CreatedAfter = DateTime.UtcNow,
CreatedBefore = DateTime.UtcNow,
@@ -201,5 +203,79 @@ namespace Retroactiune.Tests.Retroactiune.Core.Services
It.IsAny>(),
It.IsAny()), Times.Once);
}
+
+ [Fact]
+ public async Task Test_DeleteManyByFeedbackReceiverIdAsync_Ok()
+ {
+ // Setup
+ var mongoDatabaseMock = new Mock();
+ var mongoClientMock = new Mock();
+ var mongoSettingsMock = new Mock();
+ var mongoCollectionMock = new Mock>();
+
+ mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB");
+ mongoSettingsMock.SetupGet(i => i.TokensCollectionName).Returns("tokens");
+
+ mongoClientMock
+ .Setup(stub => stub.GetDatabase(It.IsAny(),
+ It.IsAny()))
+ .Returns(mongoDatabaseMock.Object);
+
+ mongoDatabaseMock
+ .Setup(i => i.GetCollection(It.IsAny(),
+ It.IsAny()))
+ .Returns(mongoCollectionMock.Object);
+
+ // Test
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
+ await service.DeleteManyByFeedbackReceiverIdAsync(new[] {"test_id"});
+
+ // Assert
+ mongoCollectionMock.Verify(
+ i
+ => i.DeleteManyAsync(
+ It.IsAny>(),
+ It.IsAny()), Times.Once);
+ }
+
+ [Fact]
+ public async Task Test_DeleteManyByFeedbackReceiverIdAsync_Exception()
+ {
+ // Setup
+ var mongoDatabaseMock = new Mock();
+ var mongoClientMock = new Mock();
+ var mongoSettingsMock = new Mock();
+ var mongoCollectionMock = new Mock>();
+
+ mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB");
+ mongoSettingsMock.SetupGet(i => i.TokensCollectionName).Returns("tokens");
+
+ mongoClientMock
+ .Setup(stub => stub.GetDatabase(It.IsAny(),
+ It.IsAny()))
+ .Returns(mongoDatabaseMock.Object);
+
+ mongoDatabaseMock
+ .Setup(i => i.GetCollection(It.IsAny(),
+ It.IsAny()))
+ .Returns(mongoCollectionMock.Object);
+
+ mongoCollectionMock.Setup(i =>
+ i.DeleteManyAsync(It.IsAny>(), It.IsAny()))
+ .ThrowsAsync(new GenericServiceException("op failed"));
+ // Test
+ var service = new TokensService(mongoClientMock.Object, mongoSettingsMock.Object);
+ await Assert.ThrowsAsync(async () =>
+ {
+ await service.DeleteManyByFeedbackReceiverIdAsync(new[] {"test_id"});
+ });
+
+ // Assert
+ mongoCollectionMock.Verify(
+ i
+ => i.DeleteManyAsync(
+ It.IsAny>(),
+ It.IsAny()), Times.Once);
+ }
}
}
\ No newline at end of file
diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs
index a51954f..560d502 100644
--- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs
+++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs
@@ -22,10 +22,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.Post(new List());
// Assert, null because we don't have the ApiBehaviourOptions set, which would generate the IActionResult for the invalid input.
@@ -39,10 +41,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.Post(items);
// Assert
@@ -56,16 +60,21 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.Delete("bad_guid_but_unit_test_works_cause_validation_doesnt");
// Assert
Assert.IsType(result);
mockService.Verify(s => s.DeleteManyAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}),
Times.Once);
+ tokensService.Verify(
+ s => s.DeleteManyByFeedbackReceiverIdAsync(new[]
+ {"bad_guid_but_unit_test_works_cause_validation_doesnt"}), Times.Once);
}
[Fact]
@@ -74,10 +83,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var items = new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt", "2", "3"};
var result = await controller.DeleteMany(items);
@@ -85,6 +96,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
Assert.IsType(result);
mockService.Verify(s => s.DeleteManyAsync(items),
Times.Once);
+ tokensService.Verify(s => s.DeleteManyByFeedbackReceiverIdAsync(items), Times.Once);
}
[Fact]
@@ -93,19 +105,21 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
mockService.Setup(i => i.DeleteManyAsync(It.IsAny>()))
.ThrowsAsync(new GenericServiceException("op failed"));
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var items = new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt", "2", "3"};
var result = await controller.DeleteMany(items);
// Assert
Assert.IsType(result);
- mockService.Verify(s => s.DeleteManyAsync(items),
- Times.Once);
+ mockService.Verify(s => s.DeleteManyAsync(items), Times.Once);
+ tokensService.Verify(s => s.DeleteManyByFeedbackReceiverIdAsync(items), Times.Once);
}
[Fact]
@@ -114,12 +128,14 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
mockService.Setup(i => i.FindAsync(It.IsAny>(), null, null))
.ReturnsAsync(new[] {new FeedbackReceiver()});
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
// Assert
@@ -135,10 +151,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
// Assert
@@ -154,11 +172,13 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
// Arrange
var mapper = TestUtils.GetMapper();
var mockService = new Mock();
+ var tokensService = new Mock();
var logger = new Mock>();
var filterArr = filter as string[] ?? filter.ToArray();
// Test
- var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
+ var controller = new FeedbackReceiversController(mockService.Object, tokensService.Object, mapper, null,
+ logger.Object);
var result = await controller.List(filterArr, offset, limit);
Assert.IsType(result);
diff --git a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs
index 16fd295..a101a46 100644
--- a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs
+++ b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs
@@ -20,14 +20,19 @@ namespace Retroactiune.Controllers
public class FeedbackReceiversController : ControllerBase
{
private readonly IOptions _apiBehaviorOptions;
- private readonly IFeedbackReceiverService _service;
+
+ // Note: Probably refactor this to use an Aggregate object, need to learn more about aggregates..
+ private readonly IFeedbackReceiverService _feedbackReceiverService;
+ private readonly ITokensService _tokensService;
private readonly IMapper _mapper;
private readonly ILogger _logger;
- public FeedbackReceiversController(IFeedbackReceiverService service, IMapper mapper,
+ public FeedbackReceiversController(IFeedbackReceiverService feedbackReceiverService,
+ ITokensService tokensService, IMapper mapper,
IOptions apiBehaviorOptions, ILogger logger)
{
- _service = service;
+ _feedbackReceiverService = feedbackReceiverService;
+ _tokensService = tokensService;
_mapper = mapper;
_apiBehaviorOptions = apiBehaviorOptions;
_logger = logger;
@@ -61,7 +66,7 @@ namespace Retroactiune.Controllers
return result;
});
- await _service.CreateManyAsync(mappedItems);
+ await _feedbackReceiverService.CreateManyAsync(mappedItems);
return Ok(new BasicResponse()
{
@@ -83,7 +88,8 @@ namespace Retroactiune.Controllers
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
string guid)
{
- await _service.DeleteManyAsync(new[] {guid});
+ await Task.WhenAll(_feedbackReceiverService.DeleteManyAsync(new[] {guid}),
+ _tokensService.DeleteManyByFeedbackReceiverIdAsync(new[] {guid}));
return NoContent();
}
@@ -103,7 +109,7 @@ namespace Retroactiune.Controllers
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
string guid)
{
- var result = await _service.FindAsync(new[] {guid});
+ var result = await _feedbackReceiverService.FindAsync(new[] {guid});
var feedbackReceivers = result as FeedbackReceiver[] ?? result.ToArray();
if (!feedbackReceivers.Any())
{
@@ -134,7 +140,7 @@ namespace Retroactiune.Controllers
[RangeAttribute(1, 1000, ErrorMessage = "limit is out of range, allowed ranges [1-1000]"), FromQuery]
int limit)
{
- return Ok(await _service.FindAsync(filter, offset, limit));
+ return Ok(await _feedbackReceiverService.FindAsync(filter, offset, limit));
}
///
@@ -151,7 +157,9 @@ namespace Retroactiune.Controllers
{
try
{
- await _service.DeleteManyAsync(ids);
+ var feedbackReceiverIds = ids as string[] ?? ids.ToArray();
+ await Task.WhenAll(_feedbackReceiverService.DeleteManyAsync(feedbackReceiverIds),
+ _tokensService.DeleteManyByFeedbackReceiverIdAsync(feedbackReceiverIds));
return NoContent();
}
catch (GenericServiceException e)
diff --git a/Retroactiune.WebAPI/Startup.cs b/Retroactiune.WebAPI/Startup.cs
index d126034..e5b341b 100644
--- a/Retroactiune.WebAPI/Startup.cs
+++ b/Retroactiune.WebAPI/Startup.cs
@@ -39,7 +39,7 @@ namespace Retroactiune
// Services
services.AddSingleton();
- services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton(i =>
{
var settings = i.GetService>();
diff --git a/Retroactiune.WebAPI/TestingStartup.cs b/Retroactiune.WebAPI/TestingStartup.cs
index ef6cc97..fe53dd3 100644
--- a/Retroactiune.WebAPI/TestingStartup.cs
+++ b/Retroactiune.WebAPI/TestingStartup.cs
@@ -35,7 +35,7 @@ namespace Retroactiune
// Services
services.AddSingleton();
- services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton(i =>
{
var settings = i.GetService>();