diff --git a/NightScout.Raccoon.sln b/NightScout.Raccoon.sln index 7b6f808..b9b32d7 100644 --- a/NightScout.Raccoon.sln +++ b/NightScout.Raccoon.sln @@ -42,6 +42,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "97. Pipelines", "97. Pipeli EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raccoon.Ninja.AzFn.ScheduledTasks.Tests", "Raccoon.Ninja.AzFn.ScheduledTasks.Tests\Raccoon.Ninja.AzFn.ScheduledTasks.Tests.csproj", "{D4D62A6B-724A-4499-B462-A9E95E7896CD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raccoon.Ninja.AzFn.DataApi.Tests", "Raccoon.Ninja.AzFn.DataApi.Tests\Raccoon.Ninja.AzFn.DataApi.Tests.csproj", "{A4B79A3C-396D-429F-BC30-012DF68C690A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -88,6 +90,10 @@ Global {D4D62A6B-724A-4499-B462-A9E95E7896CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4D62A6B-724A-4499-B462-A9E95E7896CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4D62A6B-724A-4499-B462-A9E95E7896CD}.Release|Any CPU.Build.0 = Release|Any CPU + {A4B79A3C-396D-429F-BC30-012DF68C690A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4B79A3C-396D-429F-BC30-012DF68C690A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4B79A3C-396D-429F-BC30-012DF68C690A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4B79A3C-396D-429F-BC30-012DF68C690A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {2B19A689-B703-450C-9E06-DFD0BE969053} = {11F72AFB-B94A-4E9A-8817-F1FB60E9DF6D} @@ -100,5 +106,6 @@ Global {7BC539F4-D458-40C0-8277-0E6D24416E8C} = {0F4894B1-AE2F-4119-94D4-82B7B33A7C39} {1CAC242F-719D-4E31-BEF8-7E3972F12482} = {11F72AFB-B94A-4E9A-8817-F1FB60E9DF6D} {D4D62A6B-724A-4499-B462-A9E95E7896CD} = {BC1845AD-353C-4548-A86D-80A7EBC55C34} + {A4B79A3C-396D-429F-BC30-012DF68C690A} = {BC1845AD-353C-4548-A86D-80A7EBC55C34} EndGlobalSection EndGlobal diff --git a/Raccoon.Ninja.AzFn.DataApi.Tests/ExtensionMethods/HttpRequestExtensionsTests.cs b/Raccoon.Ninja.AzFn.DataApi.Tests/ExtensionMethods/HttpRequestExtensionsTests.cs new file mode 100644 index 0000000..4f61e2a --- /dev/null +++ b/Raccoon.Ninja.AzFn.DataApi.Tests/ExtensionMethods/HttpRequestExtensionsTests.cs @@ -0,0 +1,77 @@ +using FluentAssertions; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Primitives; +using Raccoon.Ninja.AzFn.DataApi.ExtensionMethods; + +namespace Raccoon.Ninja.AzFn.DataApi.Tests.ExtensionMethods; + +public class HttpRequestExtensionsTests +{ + [Fact] + public void TryGetReadSinceParam_NoParameter_ReturnsNull() + { + // Arrange + var context = new DefaultHttpContext(); + var request = context.Request; + + // Act + var result = request.TryGetReadSinceParam(); + + // Assert + result.Should().BeNull(); + } + + [Fact] + public void TryGetReadSinceParam_InvalidParameter_ReturnsNull() + { + // Arrange + var context = new DefaultHttpContext(); + var request = context.Request; + request.QueryString = new QueryString("?readSince=notANumber"); + + // Act + var result = request.TryGetReadSinceParam(); + + // Assert + result.Should().BeNull(); + } + + [Fact] + public void TryGetReadSinceParam_ValidParameter_ReturnsLongValue() + { + // Arrange + var context = new DefaultHttpContext(); + var request = context.Request; + request.QueryString = new QueryString("?readSince=123456"); + + // Act + var result = request.TryGetReadSinceParam(); + + // Assert + result.Should().NotBeNull(); + result.Should().Be(123456L); + } + + [Fact] + public void TryGetReadSinceParam_ValidParameterSetThroughQueryProperty_ReturnsLongValue() + { + // Arrange + var context = new DefaultHttpContext(); + var request = context.Request; + + // Setting Query directly using a dictionary. + // Although Query is read-only, we can reassign it using the constructor of QueryCollection. + var queryDictionary = new Dictionary + { + { "readSince", "987654" } + }; + request.QueryString = QueryString.Create(queryDictionary); + + // Act + var result = request.TryGetReadSinceParam(); + + // Assert + result.Should().NotBeNull(); + result.Should().Be(987654L); + } +} \ No newline at end of file diff --git a/Raccoon.Ninja.AzFn.DataApi.Tests/Raccoon.Ninja.AzFn.DataApi.Tests.csproj b/Raccoon.Ninja.AzFn.DataApi.Tests/Raccoon.Ninja.AzFn.DataApi.Tests.csproj new file mode 100644 index 0000000..e21ef52 --- /dev/null +++ b/Raccoon.Ninja.AzFn.DataApi.Tests/Raccoon.Ninja.AzFn.DataApi.Tests.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + diff --git a/Raccoon.Ninja.AzFn.DataApi/DataApiFunc.cs b/Raccoon.Ninja.AzFn.DataApi/DataApiFunc.cs index f375d77..6175bf2 100644 --- a/Raccoon.Ninja.AzFn.DataApi/DataApiFunc.cs +++ b/Raccoon.Ninja.AzFn.DataApi/DataApiFunc.cs @@ -16,6 +16,7 @@ namespace Raccoon.Ninja.AzFn.DataApi; public class DataApiFunc { + private const int maxItems = 1; private readonly ILogger _logger; public DataApiFunc(ILogger logger) @@ -69,6 +70,7 @@ public async Task RunAsync( new QueryDefinition("SELECT TOP 1 * FROM c ORDER BY c.readAt DESC") ); + var docsFetched = 0; while (iteratorLatestReading.HasMoreResults) { var response = await iteratorLatestReading.ReadNextAsync(); @@ -80,7 +82,9 @@ public async Task RunAsync( return new OkObjectResult(results); } - break; + docsFetched++; + if (docsFetched >= maxItems) + break; } return new NoContentResult(); diff --git a/Raccoon.Ninja.AzFn.ScheduledTasks.Tests/Raccoon.Ninja.AzFn.ScheduledTasks.Tests.csproj b/Raccoon.Ninja.AzFn.ScheduledTasks.Tests/Raccoon.Ninja.AzFn.ScheduledTasks.Tests.csproj index 469a027..c41f0f7 100644 --- a/Raccoon.Ninja.AzFn.ScheduledTasks.Tests/Raccoon.Ninja.AzFn.ScheduledTasks.Tests.csproj +++ b/Raccoon.Ninja.AzFn.ScheduledTasks.Tests/Raccoon.Ninja.AzFn.ScheduledTasks.Tests.csproj @@ -10,9 +10,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -24,8 +24,8 @@ - - + + diff --git a/Raccoon.Ninja.Domain.Core.Tests/Raccoon.Ninja.Domain.Core.Tests.csproj b/Raccoon.Ninja.Domain.Core.Tests/Raccoon.Ninja.Domain.Core.Tests.csproj index 78befaa..c150cf7 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Raccoon.Ninja.Domain.Core.Tests.csproj +++ b/Raccoon.Ninja.Domain.Core.Tests/Raccoon.Ninja.Domain.Core.Tests.csproj @@ -1,26 +1,26 @@ - - net8.0 - enable - disable - false - true - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - + + net8.0 + enable + disable + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + \ No newline at end of file