2021-05-29 18:12:36 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-06-07 19:49:43 +00:00
|
|
|
|
using System.Linq;
|
2021-05-29 18:12:36 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AutoFixture.Xunit2;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Retroactiune.Controllers;
|
2021-06-09 21:03:07 +00:00
|
|
|
|
using Retroactiune.DataTransferObjects;
|
2021-05-29 18:12:36 +00:00
|
|
|
|
using Retroactiune.Models;
|
|
|
|
|
using Retroactiune.Services;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class TestFeedbackReceiverController
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2021-05-30 15:29:30 +00:00
|
|
|
|
public async Task Post_Fail_Creation_No_items()
|
2021-05-29 18:12:36 +00:00
|
|
|
|
{
|
2021-06-02 19:58:46 +00:00
|
|
|
|
// Arrange
|
2021-05-29 18:12:36 +00:00
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
|
|
|
|
|
|
|
|
|
// Test
|
2021-06-01 13:20:31 +00:00
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
2021-06-05 13:03:12 +00:00
|
|
|
|
var result = await controller.Post(new List<FeedbackReceiverInDto>());
|
2021-05-29 18:12:36 +00:00
|
|
|
|
|
|
|
|
|
// Assert, null because we don't have the ApiBehaviourOptions set, which would generate the IActionResult for the invalid input.
|
|
|
|
|
Assert.Null(result);
|
2021-05-30 15:29:30 +00:00
|
|
|
|
mockService.Verify(s => s.CreateManyAsync(It.IsAny<IEnumerable<FeedbackReceiver>>()), Times.Never);
|
2021-05-29 18:12:36 +00:00
|
|
|
|
}
|
2021-05-30 15:29:30 +00:00
|
|
|
|
|
2021-05-29 18:12:36 +00:00
|
|
|
|
[Theory, AutoData]
|
2021-06-05 13:03:12 +00:00
|
|
|
|
public async Task Post_Successful_Creation_Two_items(IEnumerable<FeedbackReceiverInDto> items)
|
2021-05-29 18:12:36 +00:00
|
|
|
|
{
|
2021-06-02 19:58:46 +00:00
|
|
|
|
// Arrange
|
2021-05-29 18:12:36 +00:00
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
|
|
|
|
|
|
|
|
|
// Test
|
2021-06-01 13:20:31 +00:00
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
2021-05-29 18:12:36 +00:00
|
|
|
|
var result = await controller.Post(items);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsType<OkObjectResult>(result);
|
2021-05-30 15:29:30 +00:00
|
|
|
|
mockService.Verify(s => s.CreateManyAsync(It.IsAny<IEnumerable<FeedbackReceiver>>()), Times.Once);
|
2021-05-29 18:12:36 +00:00
|
|
|
|
}
|
2021-06-02 19:58:46 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Delete_Successful()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
|
|
|
|
var result = await controller.Delete("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsType<NoContentResult>(result);
|
|
|
|
|
mockService.Verify(s => s.DeleteOneAsync("bad_guid_but_unit_test_works_cause_validation_doesnt"),
|
|
|
|
|
Times.Once);
|
|
|
|
|
}
|
2021-06-05 14:47:22 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get_Successful()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
2021-06-05 16:39:47 +00:00
|
|
|
|
mockService.Setup(i => i.FindAsync(It.IsAny<IEnumerable<string>>(), null, null))
|
|
|
|
|
.ReturnsAsync(new [] {new FeedbackReceiver()});
|
2021-06-05 14:47:22 +00:00
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
|
|
|
|
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsType<OkObjectResult>(result);
|
2021-06-05 16:39:47 +00:00
|
|
|
|
mockService.Verify(s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
2021-06-05 14:47:22 +00:00
|
|
|
|
Times.Once);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get_NotFound()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
|
|
|
|
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsType<NotFoundObjectResult>(result);
|
2021-06-05 16:39:47 +00:00
|
|
|
|
mockService.Verify(s => s.FindAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}, null, null),
|
2021-06-05 14:47:22 +00:00
|
|
|
|
Times.Once);
|
|
|
|
|
}
|
2021-06-07 19:49:43 +00:00
|
|
|
|
|
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public async Task List_Ok(IEnumerable<string> filter, int offset, int limit)
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var mapper = TestUtils.GetMapper();
|
|
|
|
|
var mockService = new Mock<IFeedbackReceiverService>();
|
|
|
|
|
var filterArr = filter as string[] ?? filter.ToArray();
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
|
|
|
|
var result = await controller.List(filterArr, offset, limit);
|
|
|
|
|
|
|
|
|
|
Assert.IsType<OkObjectResult>(result);
|
|
|
|
|
mockService.Verify(s => s.FindAsync(filterArr, offset, limit), Times.Once);
|
|
|
|
|
}
|
2021-05-29 18:12:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|