Skip to content

Commit

Permalink
Api2 first commit (#131)
Browse files Browse the repository at this point in the history
* V2 Moderator Front End. This check in is the new API.

* Added new schema document

* Hydrophones now come from the external service and not appsettings.json

---------

Co-authored-by: catskids3 <catskids3@gmail.com>
  • Loading branch information
micowan and catskids3 committed Sep 18, 2023
1 parent 2bd47e6 commit 72fe3d5
Show file tree
Hide file tree
Showing 235 changed files with 10,169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class CommentsControllerTests
{
[TestMethod]
public async Task Default_GetGetPaginatedNegativeAndUnknownCommentsForGivenTimeframeAsync_Expect_DetectionListResponse()
{
CommentListResponse response = new()
{
Count = 2,
FromDate = DateTime.Now,
ToDate = DateTime.Now.AddDays(1),
Comments = new List<Comment> { new() }
};

_orchestrationServiceMock.Setup(service =>
service.RetrieveNegativeAndUnknownCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()))
.ReturnsAsync(response);

ActionResult<CommentListResponse> actionResult =
await _controller.GetPaginatedNegativeAndUnknownCommentsForGivenTimeframeAsync(DateTime.Now, DateTime.Now.AddDays(1), 1, 10);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.AreEqual(response.Comments.Count(),
((CommentListResponse)contentResult.Value).Comments.Count());

_orchestrationServiceMock.Verify(service =>
service.RetrieveNegativeAndUnknownCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class CommentsControllerTests
{
[TestMethod]
public async Task Default_GetGetPaginatedPositiveCommentsForGivenTimeframeAsync_Expect_DetectionListResponse()
{
CommentListResponse response = new()
{
Count = 2,
FromDate = DateTime.Now,
ToDate = DateTime.Now.AddDays(1),
Comments = new List<Comment> { new() }
};

_orchestrationServiceMock.Setup(service =>
service.RetrievePositiveCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()))
.ReturnsAsync(response);

ActionResult<CommentListResponse> actionResult =
await _controller.GetPaginatedPositiveCommentsForGivenTimeframeAsync(DateTime.Now, DateTime.Now.AddDays(1), 1, 10);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.AreEqual(response.Comments.Count(),
((CommentListResponse)contentResult.Value).Comments.Count());

_orchestrationServiceMock.Verify(service =>
service.RetrievePositiveCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
[ExcludeFromCodeCoverage]
[TestClass]
public partial class CommentsControllerTests
{
private readonly Mock<ICommentOrchestrationService> _orchestrationServiceMock;
private readonly CommentsController _controller;

public CommentsControllerTests()
{
_orchestrationServiceMock = new Mock<ICommentOrchestrationService>();

_controller = new CommentsController(
commentOrchestrationService: _orchestrationServiceMock.Object);
}

[TestCleanup]
public void TestTeardown()
{
_orchestrationServiceMock.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class CommentsControllerTests
{
[TestMethod]
public async Task TryCatch_GetPaginatedNegativeAndUnknownCommentsForGivenTimeframeAsync_Expect_Exception()
{
_orchestrationServiceMock
.SetupSequence(p => p.RetrieveNegativeAndUnknownCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()))

.Throws(new CommentOrchestrationValidationException(new Exception()))
.Throws(new CommentOrchestrationDependencyValidationException(new Exception()))

.Throws(new CommentOrchestrationDependencyException(new Exception()))
.Throws(new CommentOrchestrationServiceException(new Exception()))

.Throws(new Exception());

await ExecuteRetrieveNegativeComments(2, StatusCodes.Status400BadRequest);
await ExecuteRetrieveNegativeComments(3, StatusCodes.Status500InternalServerError);

_orchestrationServiceMock
.Verify(service => service
.RetrieveNegativeAndUnknownCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Exactly(5));

}

private async Task ExecuteRetrieveNegativeComments(int count, int statusCode)
{
for (int x = 0; x < count; x++)
{
ActionResult<CommentListResponse> actionResult =
await _controller.GetPaginatedNegativeAndUnknownCommentsForGivenTimeframeAsync(DateTime.Now, DateTime.Now.AddDays(1), 1, 10);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(statusCode, contentResult.StatusCode);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class CommentsControllerTests
{
[TestMethod]
public async Task TryCatch_GetPaginatedPositiveCommentsForGivenTimeframeAsync_Expect_Exception()
{
_orchestrationServiceMock
.SetupSequence(p => p.RetrievePositiveCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()))

.Throws(new CommentOrchestrationValidationException(new Exception()))
.Throws(new CommentOrchestrationDependencyValidationException(new Exception()))

.Throws(new CommentOrchestrationDependencyException(new Exception()))
.Throws(new CommentOrchestrationServiceException(new Exception()))

.Throws(new Exception());

await ExecuteRetrieveComments(2, StatusCodes.Status400BadRequest);
await ExecuteRetrieveComments(3, StatusCodes.Status500InternalServerError);

_orchestrationServiceMock
.Verify(service => service
.RetrievePositiveCommentsForGivenTimeframeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Exactly(5));

}

private async Task ExecuteRetrieveComments(int count, int statusCode)
{
for (int x = 0; x < count; x++)
{
ActionResult<CommentListResponse> actionResult =
await _controller.GetPaginatedPositiveCommentsForGivenTimeframeAsync(DateTime.Now, DateTime.Now.AddDays(1), 1, 10);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(statusCode, contentResult.StatusCode);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class DetectionsControllerTests
{

[TestMethod]
public async Task Default_GetDetectionByIdAsync_Expect_Detection()
{
Detection expectedResult = new();

_orchestrationServiceMock.Setup(service =>
service.RetrieveDetectionByIdAsync(It.IsAny<string>()))
.ReturnsAsync(expectedResult);

ActionResult<Detection> actionResult =
await _controller.GetDetectionByIdAsync(Guid.NewGuid().ToString());


var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.IsNotNull((Detection)contentResult.Value);

_orchestrationServiceMock.Verify(service =>
service.RetrieveDetectionByIdAsync(It.IsAny<string>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class DetectionsControllerTests
{
[TestMethod]
public async Task Default_GetDetectionsForGivenInterestLabelAsyncc_Expect_DetectionListForInterestLabelResponse()
{
DetectionListForInterestLabelResponse response = new()
{
TotalCount = 1,
Detections = new List<Detection> { new Detection() },
InterestLabel = "test"
};

_orchestrationServiceMock.Setup(service =>
service.RetrieveDetectionsForGivenInterestLabelAsync(It.IsAny<string>()))
.ReturnsAsync(response);

ActionResult<DetectionListForInterestLabelResponse> actionResult =
await _controller.GetDetectionsForGivenInterestLabelAsync("test");

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.AreEqual(response.Detections.Count(),
((DetectionListForInterestLabelResponse)contentResult.Value).Detections.Count());

_orchestrationServiceMock.Verify(service =>
service.RetrieveDetectionsForGivenInterestLabelAsync(It.IsAny<string>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class DetectionsControllerTests
{
[TestMethod]
public async Task Default_GetPaginatedDetectionsAsync_Expect_DetectionListResponse()
{
DetectionListResponse response = new()
{
Count = 2,
FromDate = DateTime.Now,
ToDate = DateTime.Now.AddDays(1),
Detections = new List<Detection> { new() },
State = "Positive",
SortBy = "timestamp",
SortOrder = "desc",
Location = "location"
};

_orchestrationServiceMock.Setup(service =>
service.RetrieveFilteredDetectionsAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.ReturnsAsync(response);

ActionResult<DetectionListResponse> actionResult =
await _controller.GetPaginatedDetectionsAsync("Positive", DateTime.Now, DateTime.Now.AddDays(1), "timestamp", true, 1, 10, null);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.AreEqual(response.Detections.Count(),
((DetectionListResponse)contentResult.Value).Detections.Count());

_orchestrationServiceMock.Verify(service =>
service.RetrieveFilteredDetectionsAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class DetectionsControllerTests
{
[TestMethod]
public async Task Default_GetPaginatedDetectionsForGivenTimeframeAndTagAsync_Expect_DetectionListResponse()
{
DetectionListForTagResponse response = new()
{
Count = 2,
FromDate = DateTime.Now,
ToDate = DateTime.Now.AddDays(1),
Detections = new List<Detection> { new Detection() }
};

_orchestrationServiceMock.Setup(service =>
service.RetrieveDetectionsForGivenTimeframeAndTagAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.ReturnsAsync(response);

ActionResult<DetectionListForTagResponse> actionResult =
await _controller.GetPaginatedDetectionsForGivenTimeframeAndTagAsync("tag", DateTime.Now, DateTime.Now.AddDays(1), 1, 10);

var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.AreEqual(response.Detections.Count,
((DetectionListForTagResponse)contentResult.Value).Detections.Count);

_orchestrationServiceMock.Verify(service =>
service.RetrieveDetectionsForGivenTimeframeAndTagAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace OrcaHello.Web.Api.Tests.Unit.Controllers
{
public partial class DetectionsControllerTests
{

[TestMethod]
public async Task Default_PutModeratedInfoAsync_Expect_Detection()
{
Detection expectedResult = new();

_orchestrationServiceMock.Setup(service =>
service.ModerateDetectionByIdAsync(It.IsAny<string>(), It.IsAny<ModerateDetectionRequest>()))
.ReturnsAsync(expectedResult);

ModerateDetectionRequest request = new()
{
Id = Guid.NewGuid().ToString(),
Moderator = "Ira M. Goober",
DateModerated = DateTime.UtcNow,
Comments = "Comments",
Tags = new List<string>() { "Tag1" }
};

ActionResult<Detection> actionResult =
await _controller.PutModeratedInfoAsync(Guid.NewGuid().ToString(), request);


var contentResult = actionResult.Result as ObjectResult;
Assert.IsNotNull(contentResult);
Assert.AreEqual(200, contentResult.StatusCode);

Assert.IsNotNull((Detection)contentResult.Value);

_orchestrationServiceMock.Verify(service =>
service.ModerateDetectionByIdAsync(It.IsAny<string>(), It.IsAny<ModerateDetectionRequest>()),
Times.Once);
}
}
}
Loading

0 comments on commit 72fe3d5

Please sign in to comment.