Change endpoint for FeedbackReceiversController.cs

This commit is contained in:
Denis-Cosmin Nutiu 2021-07-04 17:19:12 +03:00
parent 901d495bff
commit b89d2b5f9f
3 changed files with 50 additions and 15 deletions

View file

@ -41,7 +41,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
public async Task Test_Create_NoContent() public async Task Test_Create_NoContent()
{ {
await _mongoDb.DropAsync(); await _mongoDb.DropAsync();
var httpResponse = await _client.PostAsync("/api/v1/FeedbackReceivers/", var httpResponse = await _client.PostAsync("/api/v1/feedback_receivers/",
new StringContent("[]", Encoding.UTF8, "application/json")); new StringContent("[]", Encoding.UTF8, "application/json"));
Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode); Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode);
} }
@ -58,7 +58,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
var jsonContent = JsonSerializer.Serialize(new List<FeedbackReceiverInDto> {item}); var jsonContent = JsonSerializer.Serialize(new List<FeedbackReceiverInDto> {item});
// Test // Test
var httpResponse = await _client.PostAsync("/api/v1/FeedbackReceivers/", var httpResponse = await _client.PostAsync("/api/v1/feedback_receivers/",
new StringContent(jsonContent, Encoding.UTF8, "application/json")); new StringContent(jsonContent, Encoding.UTF8, "application/json"));
// Assert // Assert
@ -77,7 +77,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
var jsonContent = JsonSerializer.Serialize(new List<FeedbackReceiverInDto> {item}); var jsonContent = JsonSerializer.Serialize(new List<FeedbackReceiverInDto> {item});
// Test // Test
var httpResponse = await _client.PostAsync("/api/v1/FeedbackReceivers/", var httpResponse = await _client.PostAsync("/api/v1/feedback_receivers/",
new StringContent(jsonContent, Encoding.UTF8, "application/json")); new StringContent(jsonContent, Encoding.UTF8, "application/json"));
// Assert // Assert
@ -93,7 +93,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
var jsonContent = JsonSerializer.Serialize(feedbackReceiversDto); var jsonContent = JsonSerializer.Serialize(feedbackReceiversDto);
// Test // Test
var httpResponse = await _client.PostAsync("/api/v1/FeedbackReceivers/", var httpResponse = await _client.PostAsync("/api/v1/feedback_receivers/",
new StringContent(jsonContent, Encoding.UTF8, "application/json")); new StringContent(jsonContent, Encoding.UTF8, "application/json"));
// Assert // Assert
@ -112,7 +112,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var httpResponse = var httpResponse =
await _client.DeleteAsync("/api/v1/FeedbackReceivers/abc_not_guid", CancellationToken.None); await _client.DeleteAsync("/api/v1/feedback_receivers/abc_not_guid", CancellationToken.None);
// Assert // Assert
Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode); Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode);
@ -138,7 +138,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
foreach (var guid in guids) foreach (var guid in guids)
{ {
var httpResponse = var httpResponse =
await _client.DeleteAsync($"/api/v1/FeedbackReceivers/{guid}", CancellationToken.None); await _client.DeleteAsync($"/api/v1/feedback_receivers/{guid}", CancellationToken.None);
Assert.Equal(HttpStatusCode.NoContent, httpResponse.StatusCode); Assert.Equal(HttpStatusCode.NoContent, httpResponse.StatusCode);
} }
@ -164,7 +164,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var httpResponse = await _client.DeleteAsync($"/api/v1/FeedbackReceivers/{feedbackReceiver.Id}", var httpResponse = await _client.DeleteAsync($"/api/v1/feedback_receivers/{feedbackReceiver.Id}",
CancellationToken.None); CancellationToken.None);
await _client.PostAsync("/api/v1/Tokens/", await _client.PostAsync("/api/v1/Tokens/",
new StringContent($"{{\"numberOfTokens\": 100, \"feedbackReceiverId\": \"{feedbackReceiver.Id}\"}}", new StringContent($"{{\"numberOfTokens\": 100, \"feedbackReceiverId\": \"{feedbackReceiver.Id}\"}}",
@ -201,7 +201,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
var request = new HttpRequestMessage var request = new HttpRequestMessage
{ {
Method = HttpMethod.Delete, Method = HttpMethod.Delete,
RequestUri = new Uri($"{_client.BaseAddress.AbsoluteUri}api/v1/FeedbackReceivers"), RequestUri = new Uri($"{_client.BaseAddress.AbsoluteUri}api/v1/feedback_receivers"),
// ReSharper disable once MethodHasAsyncOverload // ReSharper disable once MethodHasAsyncOverload
Content = new StringContent(JsonConvert.SerializeObject(guids), Encoding.UTF8, "application/json") Content = new StringContent(JsonConvert.SerializeObject(guids), Encoding.UTF8, "application/json")
}; };
@ -231,7 +231,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var httpResponse = var httpResponse =
await _client.GetAsync($"/api/v1/FeedbackReceivers/{feedbackReceiver.Id}", CancellationToken.None); await _client.GetAsync($"/api/v1/feedback_receivers/{feedbackReceiver.Id}", CancellationToken.None);
var item = JsonSerializer.Deserialize<FeedbackReceiver>( var item = JsonSerializer.Deserialize<FeedbackReceiver>(
await httpResponse.Content.ReadAsStringAsync()); await httpResponse.Content.ReadAsStringAsync());
@ -246,7 +246,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
await _mongoDb.DropAsync(); await _mongoDb.DropAsync();
// Test // Test
var httpResponse = await _client.GetAsync("/api/v1/FeedbackReceivers/0102030405060708090a0b0e", var httpResponse = await _client.GetAsync("/api/v1/feedback_receivers/0102030405060708090a0b0e",
CancellationToken.None); CancellationToken.None);
// Assert // Assert
@ -260,7 +260,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
await _mongoDb.DropAsync(); await _mongoDb.DropAsync();
// Test // Test
var httpResponse = await _client.GetAsync("/api/v1/FeedbackReceivers/xxx", CancellationToken.None); var httpResponse = await _client.GetAsync("/api/v1/feedback_receivers/xxx", CancellationToken.None);
// Assert // Assert
Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode); Assert.Equal(HttpStatusCode.BadRequest, httpResponse.StatusCode);
@ -300,7 +300,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var httpResponse = await _client.GetAsync("/api/v1/FeedbackReceivers/", CancellationToken.None); var httpResponse = await _client.GetAsync("/api/v1/feedback_receivers/", CancellationToken.None);
var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>( var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>(
await httpResponse.Content.ReadAsStringAsync()); await httpResponse.Content.ReadAsStringAsync());
@ -348,7 +348,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var qb = new QueryBuilder {{"filter", new[] {feedbackReceivers[0].Id, feedbackReceivers[1].Id}}}; var qb = new QueryBuilder {{"filter", new[] {feedbackReceivers[0].Id, feedbackReceivers[1].Id}}};
var httpResponse = var httpResponse =
await _client.GetAsync("/api/v1/FeedbackReceivers/" + qb, await _client.GetAsync("/api/v1/feedback_receivers/" + qb,
CancellationToken.None); CancellationToken.None);
var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>( var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>(
await httpResponse.Content.ReadAsStringAsync()); await httpResponse.Content.ReadAsStringAsync());
@ -397,7 +397,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
// Test // Test
var qb = new QueryBuilder {{"offset", "1"}, {"limit", "1"}}; var qb = new QueryBuilder {{"offset", "1"}, {"limit", "1"}};
var httpResponse = await _client.GetAsync("/api/v1/FeedbackReceivers/" + qb, CancellationToken.None); var httpResponse = await _client.GetAsync("/api/v1/feedback_receivers/" + qb, CancellationToken.None);
var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>( var items = JsonSerializer.Deserialize<List<FeedbackReceiver>>(
await httpResponse.Content.ReadAsStringAsync()); await httpResponse.Content.ReadAsStringAsync());

View file

@ -16,7 +16,7 @@ using Retroactiune.DataTransferObjects;
namespace Retroactiune.Controllers namespace Retroactiune.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v1/[controller]")] [Route("api/v1/feedback_receivers")]
public class FeedbackReceiversController : ControllerBase public class FeedbackReceiversController : ControllerBase
{ {
private readonly IOptions<ApiBehaviorOptions> _apiBehaviorOptions; private readonly IOptions<ApiBehaviorOptions> _apiBehaviorOptions;

View file

@ -0,0 +1,35 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Retroactiune.DataTransferObjects
{
/// <summary>
/// FeedbackInDto is used by users for submitting feedback.
/// </summary>
public class FeedbackInDto
{
private uint _rating;
[Required, StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
public string FeedbackReceiverId { get; set; }
[Required]
public uint Rating
{
get => _rating;
set
{
if (value <= 5)
{
_rating = value;
}
else
{
throw new ArgumentException();
}
}
}
[Required] public string Description { get; set; }
}
}