From 64e8bd9c4e6ef29430f441c3dd344e3590bfcbd5 Mon Sep 17 00:00:00 2001 From: tpz Date: Tue, 5 Dec 2023 16:59:57 +0100 Subject: [PATCH] fix: test fixes, gRPC DateTime parsing corrections --- .../DataTypes/EvitaDataTypesConverter.cs | 17 ++++++++++++----- .../Json/Converters/DecimalConverter.cs | 2 +- .../evita-csharp-query-template.txt | 12 ++++++++++-- EvitaDB.Test/SetupFixture.cs | 2 +- EvitaDB.Test/Tests/EvitaClientDemoQueryTest.cs | 2 -- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs index 14884bd..5ccd4aa 100644 --- a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs +++ b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs @@ -653,14 +653,21 @@ public static DateTimeOffset ToDateTimeOffset(GrpcOffsetDateTime offsetDateTimeV TimeSpan.FromHours(int.Parse(offsetDateTimeValue.Offset.Substring(1, 2))); bool add = offsetDateTimeValue.Offset.ElementAt(0) == '+'; TimeSpan offset = add ? hourOffset : hourOffset.Negate(); - return ToDateTimeOffset(offsetDateTimeValue.Timestamp) - .ToOffset(offset); + try + { + // because when max value is present in UTC, we cannot add the offset to it + return ToDateTimeOffset(offsetDateTimeValue.Timestamp) + .ToOffset(offset); + } + catch (Exception) + { + return ToDateTimeOffset(offsetDateTimeValue.Timestamp); + } } private static DateTimeOffset ToDateTimeOffset(Timestamp timestamp) { - int milliseconds = timestamp.Nanos / 1000000; - return DateTimeOffset.UnixEpoch.AddSeconds(timestamp.Seconds).AddMilliseconds(milliseconds); + return timestamp.ToDateTimeOffset(); } public static DateTimeOffset[] ToDateTimeOffsetArray(GrpcOffsetDateTimeArray arrayValue) @@ -1101,4 +1108,4 @@ public static GrpcPredecessor ToGrpcPredecessor(Predecessor predecessor) return predecessor.Head ? Predecessor.Head : predecessor.PredecessorId.HasValue ? new Predecessor(predecessor.PredecessorId.Value) : null; } -} \ No newline at end of file +} diff --git a/EvitaDB.QueryValidator/Serialization/Json/Converters/DecimalConverter.cs b/EvitaDB.QueryValidator/Serialization/Json/Converters/DecimalConverter.cs index 4780d20..69a25fc 100644 --- a/EvitaDB.QueryValidator/Serialization/Json/Converters/DecimalConverter.cs +++ b/EvitaDB.QueryValidator/Serialization/Json/Converters/DecimalConverter.cs @@ -15,7 +15,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { // Implement if needed for deserialization - throw new NotImplementedException(); + throw new NotSupportedException(); } public override bool CanConvert(Type objectType) diff --git a/EvitaDB.QueryValidator/evita-csharp-query-template.txt b/EvitaDB.QueryValidator/evita-csharp-query-template.txt index 58e2f89..aab8c41 100644 --- a/EvitaDB.QueryValidator/evita-csharp-query-template.txt +++ b/EvitaDB.QueryValidator/evita-csharp-query-template.txt @@ -22,8 +22,16 @@ using static EvitaDB.Client.Queries.Requires.EmptyHierarchicalEntityBehaviour; public class DynamicClass { - private static readonly EvitaClientConfiguration EvitaClientConfiguration = new EvitaClientConfiguration.Builder() - .SetHost("#HOST#") + private const string Host = "#HOST#"; + private static readonly EvitaClientConfiguration EvitaClientConfiguration = + Host == "localhost" ? new EvitaClientConfiguration.Builder() + .SetHost(Host) + .SetPort(5556) + .SetUseGeneratedCertificate(true) + .SetUsingTrustedRootCaCertificate(false) + .Build() : + new EvitaClientConfiguration.Builder() + .SetHost(Host) .SetPort(5556) .SetUseGeneratedCertificate(false) .SetUsingTrustedRootCaCertificate(true) diff --git a/EvitaDB.Test/SetupFixture.cs b/EvitaDB.Test/SetupFixture.cs index 9e54ff8..5504e40 100644 --- a/EvitaDB.Test/SetupFixture.cs +++ b/EvitaDB.Test/SetupFixture.cs @@ -158,4 +158,4 @@ public EvitaTestSuite(EvitaClient client, IContainer container) Container = container; } } -} \ No newline at end of file +} diff --git a/EvitaDB.Test/Tests/EvitaClientDemoQueryTest.cs b/EvitaDB.Test/Tests/EvitaClientDemoQueryTest.cs index c4b075d..a12ed18 100644 --- a/EvitaDB.Test/Tests/EvitaClientDemoQueryTest.cs +++ b/EvitaDB.Test/Tests/EvitaClientDemoQueryTest.cs @@ -123,7 +123,6 @@ public void ShouldBeAbleToExecuteComplexQueryAndGetResults() Collection("Product"), FilterBy( Or( - AttributeInSet("visibility", "yes", "no"), EntityLocaleEquals(new CultureInfo("cs-CZ")), HierarchyWithin("categories", null, ExcludingRoot()), Not( @@ -141,7 +140,6 @@ public void ShouldBeAbleToExecuteComplexQueryAndGetResults() PriceBetween(100m, 200.5m), PriceValidInNow() ), - AttributeBetween("frekvence-od", 20m, 95.3m), UserFilter( FacetHaving("variantParameters", EntityPrimaryKeyInSet(1, 2, 3)) )