Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TickerQ.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Project Path="hub/sdks/dotnet/TickerQ.SDK/TickerQ.SDK.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/TickerQ.Caching.StackExchangeRedis.Tests/TickerQ.Caching.StackExchangeRedis.Tests.csproj" />
<Project Path="tests/TickerQ.EntityFrameworkCore.Tests/TickerQ.EntityFrameworkCore.Tests.csproj" />
<Project Path="tests/TickerQ.Tests/TickerQ.Tests.csproj" />
</Folder>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Version>10.2.5</Version>
<Version>10.2.5-beta</Version>
<DotNetVersion>[10.0.0,11.0.0)</DotNetVersion>
<DotNetAbstractionsVersion>[10.0.0,11.0.0)</DotNetAbstractionsVersion>
<RepositoryUrl>https://github.com/arcenox-co/TickerQ</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using static TickerQ.Caching.StackExchangeRedis.DependencyInjection.ServiceExtension;
Expand Down Expand Up @@ -32,6 +27,38 @@ public TickerRedisPersistenceProvider(
ILogger<TickerRedisPersistenceProvider<TTimeTicker, TCronTicker>> logger)
: base(db, clock, optionsBuilder, redisOptions, logger) { }

#region Queryable_Methods
public ITickerQueryable<TTimeTicker> TimeTickersQuery()
{
return new InMemoryTickerQueryable<TTimeTicker>(async ct =>
{
var list = await Serializer.LoadAllFromSetAsync<TTimeTicker>(
TimeTickerIdsKey, TimeTickerKey, ct).ConfigureAwait(false);
return list;
});
}

public ITickerQueryable<TCronTicker> CronTickersQuery()
{
return new InMemoryTickerQueryable<TCronTicker>(async ct =>
{
var list = await Serializer.LoadAllFromSetAsync<TCronTicker>(
CronIdsKey, CronKey, ct).ConfigureAwait(false);
return list;
});
}

public ITickerQueryable<CronTickerOccurrenceEntity<TCronTicker>> CronTickerOccurrencesQuery()
{
return new InMemoryTickerQueryable<CronTickerOccurrenceEntity<TCronTicker>>(async ct =>
{
var list = await Serializer.LoadAllFromSetAsync<CronTickerOccurrenceEntity<TCronTicker>>(
CronOccurrenceIdsKey, CronOccurrenceKey, ct).ConfigureAwait(false);
return list;
});
}
#endregion

#region Time_Ticker_Shared_Methods
public async Task<TTimeTicker> GetTimeTickerById(Guid id, CancellationToken cancellationToken = default)
{
Expand Down
6 changes: 4 additions & 2 deletions src/TickerQ.Dashboard/Endpoints/DashboardEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
Expand Down Expand Up @@ -268,10 +269,11 @@ private static async Task ValidateAuth(HttpContext context)

if (dashboardOptions.Auth.Mode == AuthMode.Host)
{
return Results.Challenge();
await context.ChallengeAsync();
return;
}

return Results.Unauthorized();
context.Response.StatusCode = 401;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(DotNetVersion)" />
<PackageReference Include="TickerQ.Utilities" Version="$(Version)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
<ItemGroup>
<PackageReference Include="TickerQ.Utilities" Version="$(Version)" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/TickerQ.SourceGenerator/TickerQ.SourceGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="[4.10.0,)"/>
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

</Project>
43 changes: 23 additions & 20 deletions tests/TickerQ.Tests/JsonExampleGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace TickerQ.Tests;

public class JsonExampleGeneratorTests
{
private static readonly JsonSerializerOptions DeserializeOptions = new()
{
PropertyNameCaseInsensitive = true
};

public JsonExampleGeneratorTests()
{
TickerHelper.RequestJsonSerializerOptions = new JsonSerializerOptions
Expand Down Expand Up @@ -70,7 +75,7 @@ public void TryGenerateExampleJson_WithDecimal_ReturnsValidJson()
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<decimal>(json);
Assert.Equal(decimal.Zero, value);
Assert.Equal(123.45m, value);
}

[Fact]
Expand All @@ -81,7 +86,7 @@ public void TryGenerateExampleJson_WithDateTime_ReturnsValidJson()
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<DateTime>(json);
Assert.Equal(DateTime.MinValue, value);
Assert.Equal(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), value);
}

[Fact]
Expand Down Expand Up @@ -125,7 +130,7 @@ public void TryGenerateExampleJson_WithByte_ReturnsValidJson()
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<byte>(json);
Assert.Equal((byte)1, value);
Assert.Equal((byte)123, value);
}

[Fact]
Expand All @@ -136,7 +141,7 @@ public void TryGenerateExampleJson_WithShort_ReturnsValidJson()
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<short>(json);
Assert.Equal((short)1, value);
Assert.Equal((short)123, value);
}

[Fact]
Expand Down Expand Up @@ -191,7 +196,7 @@ public void TryGenerateExampleJson_WithNullableDateTime_ReturnsValidJson()
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<DateTime?>(json);
Assert.Equal(DateTime.MinValue, value);
Assert.Equal(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), value);
}

[Fact]
Expand Down Expand Up @@ -266,7 +271,7 @@ public void TryGenerateExampleJson_WithSimpleClass_ReturnsValidJson()

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<SimpleTestClass>(json);
var value = JsonSerializer.Deserialize<SimpleTestClass>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.Equal(123, value!.Id);
Assert.Equal("string", value.Name);
Expand All @@ -280,7 +285,7 @@ public void TryGenerateExampleJson_WithNestedClass_ReturnsValidJson()

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<NestedTestClass>(json);
var value = JsonSerializer.Deserialize<NestedTestClass>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.Equal(123, value!.Id);
Assert.NotNull(value.Child);
Expand All @@ -295,7 +300,7 @@ public void TryGenerateExampleJson_WithClassContainingList_ReturnsValidJson()

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<ClassWithList>(json);
var value = JsonSerializer.Deserialize<ClassWithList>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.NotNull(value!.Items);
Assert.Single(value.Items);
Expand All @@ -309,7 +314,7 @@ public void TryGenerateExampleJson_WithClassContainingArray_ReturnsValidJson()

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<ClassWithArray>(json);
var value = JsonSerializer.Deserialize<ClassWithArray>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.NotNull(value!.Numbers);
Assert.Single(value.Numbers);
Expand All @@ -323,7 +328,7 @@ public void TryGenerateExampleJson_WithStruct_ReturnsValidJson()

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<TestStruct>(json);
var value = JsonSerializer.Deserialize<TestStruct>(json, DeserializeOptions);
Assert.Equal(123, value.X);
Assert.Equal(123, value.Y);
}
Expand All @@ -335,28 +340,27 @@ public void TryGenerateExampleJson_WithReadOnlyProperty_OnlyGeneratesWritablePro

Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<ClassWithReadOnlyProperty>(json);
var value = JsonSerializer.Deserialize<ClassWithReadOnlyProperty>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.Equal(123, value!.WritableProperty);
}

[Fact]
public void TryGenerateExampleJson_WithTypeWithoutParameterlessConstructor_ReturnsFalse()
public void TryGenerateExampleJson_WithTypeWithoutParameterlessConstructor_ReturnsValidJson()
{
var result = JsonExampleGenerator.TryGenerateExampleJson(typeof(ClassWithoutParameterlessConstructor), out var json);

Assert.False(result);
Assert.True(string.IsNullOrEmpty(json));
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
}

[Fact]
public void TryGenerateExampleJson_ReturnsIndentedJson()
public void TryGenerateExampleJson_ReturnsCompactJson()
{
var result = JsonExampleGenerator.TryGenerateExampleJson(typeof(SimpleTestClass), out var json);

Assert.True(result);
Assert.Contains("\n", json);
Assert.Contains(" ", json);
Assert.DoesNotContain("\n", json);
}

[Fact]
Expand All @@ -365,10 +369,9 @@ public void TryGenerateExampleJson_WithClassHierarchy_ReturnsValidJson()
var result = JsonExampleGenerator.TryGenerateExampleJson(typeof(ClassWithHierarchy), out var json);
Assert.True(result);
Assert.False(string.IsNullOrEmpty(json));
var value = JsonSerializer.Deserialize<ClassWithHierarchy>(json);
var value = JsonSerializer.Deserialize<ClassWithHierarchy>(json, DeserializeOptions);
Assert.NotNull(value);
Assert.NotNull(value!.Child);
Assert.Null(value.Child!.Child); // Ensure it doesn't go infinitely deep
Assert.Null(value.Child); // Circular reference detection returns null for self-referencing types
}

public class SimpleTestClass
Expand Down
Loading