Skip to content

[MDAPI-165] [.NET] DxFeed.Graal.Net.Schedules.GetNextSession does not return null if no session exists #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 changes: 2 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* [MDAPI-165] [.NET] DxFeed.Graal.Net.Schedules.GetNextSession does not return null if no session exists

## Version 2.5.1

* [MDAPI-124] [.NET] Remove the ability to pass multiple sources for PriceLeveBookSample
Expand Down
2 changes: 1 addition & 1 deletion src/DxFeed.Graal.Net/DxFeed.Graal.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
Expand Down
18 changes: 9 additions & 9 deletions src/DxFeed.Graal.Net/Schedules/Day.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public Session GetSessionByTime(long time) =>
public bool TryGetFirstSession(SessionFilter filter, out Session session)
{
session = null!;
var first = this.handle.FindFirstSession(filter.Handle);
if (first == null)
var first = handle.FindFirstSession(filter.Handle);
if (first == null || first.IsInvalid)
{
return false;
}
Expand Down Expand Up @@ -216,13 +216,13 @@ public bool TryGetFirstSession(SessionFilter filter, out Session session)
public bool TryGetLastSession(SessionFilter filter, out Session session)
{
session = null!;
var first = this.handle.FindLastSession(filter.Handle);
if (first == null)
var last = handle.FindLastSession(filter.Handle);
if (last == null || last.IsInvalid)
{
return false;
}

session = new Session(Schedule, first);
session = new Session(Schedule, last);
return true;
}

Expand All @@ -248,8 +248,8 @@ public bool TryGetLastSession(SessionFilter filter, out Session session)
public bool TryGetPrevDay(DayFilter filter, out Day day)
{
day = null!;
var prev = this.handle.FindPrevDay(filter.Handle);
if (prev == null)
var prev = handle.FindPrevDay(filter.Handle);
if (prev == null || prev.IsInvalid)
{
return false;
}
Expand Down Expand Up @@ -284,8 +284,8 @@ public bool TryGetPrevDay(DayFilter filter, out Day day)
public bool TryGetNextDay(DayFilter filter, out Day day)
{
day = null!;
var next = this.handle.FindNextDay(filter.Handle);
if (next == null)
var next = handle.FindNextDay(filter.Handle);
if (next == null || next.IsInvalid)
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/DxFeed.Graal.Net/Schedules/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public Day GetDayByYearMonthDay(int yearMonthDay) =>
public bool TryGetNearestSessionByTime(long time, SessionFilter filter, out Session session)
{
session = null!;
var prev = handle.FindNearestSessionByTime(time, filter.Handle);
if (prev == null)
var nearest = handle.FindNearestSessionByTime(time, filter.Handle);
if (nearest == null || nearest.IsInvalid)
{
return false;
}

session = new Session(this, prev);
session = new Session(this, nearest);
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions src/DxFeed.Graal.Net/Schedules/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public bool TryGetPrevSession(SessionFilter filter, out Session session)
{
session = null!;
var prev = handle.FindPrevSession(filter.Handle);
if (prev == null)
if (prev == null || prev.IsInvalid)
{
return false;
}
Expand Down Expand Up @@ -144,13 +144,13 @@ public bool TryGetPrevSession(SessionFilter filter, out Session session)
public bool TryGetNextSession(SessionFilter filter, out Session session)
{
session = null!;
var prev = handle.FindNextSession(filter.Handle);
if (prev == null)
var next = handle.FindNextSession(filter.Handle);
if (next == null || next.IsInvalid)
{
return false;
}

session = new Session(schedule, prev);
session = new Session(schedule, next);
return true;
}

Expand Down
56 changes: 56 additions & 0 deletions tests/DxFeed.Graal.Net.Tests/Schedules/ScheduleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// <copyright file="ScheduleTest.cs" company="Devexperts LLC">
// Copyright © 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// </copyright>

using DxFeed.Graal.Net.Ipf;
using DxFeed.Graal.Net.Schedules;

namespace DxFeed.Graal.Net.Tests.Schedules;

[TestFixture]
public class ScheduleTest
{
private static readonly string TestIpf = Path.Combine(TestContext.CurrentContext.TestDirectory, "ipf.txt");

[Test]
public void Day_ShouldReturnsNullValueForInvalidSession()
{
var profiles = new InstrumentProfileReader().ReadFromFile(TestIpf);
foreach (var profile in profiles) {
var schedule = Schedule.GetInstance(profile);
var day = schedule.GetDayByYearMonthDay(01012024);
var session = day.GetFirstSession(SessionFilter.AFTER_MARKET);
Assert.That(session, Is.Null);
session = day.GetLastSession(SessionFilter.AFTER_MARKET);
Assert.That(session, Is.Null);
Assert.Multiple(() =>
{
Assert.That(day.TryGetFirstSession(SessionFilter.AFTER_MARKET, out session), Is.False);
Assert.That(session, Is.Null);
Assert.That(day.TryGetLastSession(SessionFilter.AFTER_MARKET, out session), Is.False);
Assert.That(session, Is.Null);
});
}
}

[Test]
public void Day_ShouldReturnsNullValueForInvalidDay()
{
var profiles = new InstrumentProfileReader().ReadFromFile(TestIpf);
foreach (var profile in profiles) {
var schedule = Schedule.GetInstance(profile);
var day = schedule.GetDayByYearMonthDay(01011950);
Assert.Multiple(() =>
{
Assert.That(day.GetNextDay(DayFilter.SHORT_DAY), Is.Null);
Assert.That(day.GetPrevDay(DayFilter.SHORT_DAY), Is.Null);
Assert.That(day.TryGetNextDay(DayFilter.SHORT_DAY, out var nextDay), Is.False);
Assert.That(nextDay, Is.Null);
Assert.That(day.TryGetPrevDay(DayFilter.SHORT_DAY, out var prevDay), Is.False);
Assert.That(prevDay, Is.Null);
});
}
}
}