Skip to content

Commit

Permalink
Add error test, and moved test for analysis date
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko Petrelli committed Aug 21, 2024
1 parent 3de046f commit 62ba407
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
53 changes: 47 additions & 6 deletions Artesian/Artesian.SDK.Tests/VersionedTimeSerieQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,8 @@ public void Ver_PeriodRelativeIntervalChange()
}
}


[Test]
public void Ver_RelativePeriodExtractionWindowChange()
{
using (var httpTest = new HttpTest())
Expand Down Expand Up @@ -2650,18 +2652,57 @@ public void Ver_RelativePeriodExtractionWindowChange()
.WithQueryParam("id", 100000001)
.WithVerb(HttpMethod.Get)
.Times(1);
}
}

var test4 = partialQuery
[Test]
public void Ver_RelativePeriodForAnalysisDate()
{
using (var httpTest = new HttpTest())
{
var qs = new QueryService(_cfg);

var partialQuery = qs.CreateVersioned()
.ForMarketData(new [] { 100000001 })
.InGranularity(Granularity.Hour)
.ForMUV()
.InRelativePeriod(Period.FromDays(5));

var test = partialQuery
.ForAnalysisDate(new LocalDate(2018, 07, 19))
.ExecuteAsync().Result;

httpTest.ShouldHaveCalledPath($"{_cfg.BaseAddress}query/v1.0/vts/MUV/Day/P5D")
.WithQueryParam("ad", "2018-07-19")
.WithVerb(HttpMethod.Get)
.Times(1);

httpTest.ShouldHaveCalledPath($"{_cfg.BaseAddress}query/v1.0/vts/MUV/Hour/P5D")
.WithQueryParam("id", 100000001)
.WithQueryParam("ad", "2018-07-19")
.WithVerb(HttpMethod.Get)
.Times(1);
}
}

[Test]
public void Ver_RelativePeriodExtractionWindowFail()
{
var qs = new QueryService(_cfg);

var query = qs.CreateVersioned()
.ForMarketData(new [] {100000001})
.InGranularity(Granularity.Day)
.ForLastNVersions(3)
.InAbsoluteDateRange(
new LocalDate(2018, 07, 15),
new LocalDate(2018, 07, 20)
)
.ForAnalysisDate(new LocalDate(2018, 07, 19))
;

Assert.Throws<ArtesianSdkClientException>(
() => {
query.ExecuteAsync().ConfigureAwait(true).GetAwaiter().GetResult();
}
);
}

#endregion

#region Filler
Expand Down
12 changes: 7 additions & 5 deletions Artesian/Artesian.SDK/Service/Query/VersionedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NodaTime;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -425,10 +426,7 @@ protected override void _validateQuery()
}
}

if (
( _queryParamaters.ExtractionRangeSelectionConfig.DateStart != null || _queryParamaters.ExtractionRangeSelectionConfig.DateEnd != null )
&& _queryParamaters.AnalysisDate != null
)
if (_queryParamaters.ExtractionRangeType == ExtractionRangeType.DateRange && _queryParamaters.AnalysisDate != null)
throw new ArtesianSdkClientException("Analysis should be related to a Period. Provide a period or remove analysis date.");
}

Expand Down Expand Up @@ -507,7 +505,11 @@ private List<string> _buildRequest()
.SetQueryParam("fillerK", qp.FillerKindType)
.SetQueryParam("fillerDV", qp.FillerConfig.FillerTimeSeriesDV)
.SetQueryParam("fillerP", qp.FillerConfig.FillerPeriod)
.SetQueryParam("ad", qp.AnalysisDate)
.SetQueryParam("ad",
qp.AnalysisDate.HasValue
? qp.AnalysisDate.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
: null
)
.ToString())
.ToList();

Expand Down

0 comments on commit 62ba407

Please sign in to comment.