Skip to content

Commit

Permalink
parsing default UTC timezone in DataTypesConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
Khertys committed Oct 18, 2023
1 parent a9c7e1c commit 634da71
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 130 deletions.
20 changes: 7 additions & 13 deletions EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,13 @@ public static Currency[] ToCurrencyArray(GrpcCurrencyArray arrayValue)

public static DateTimeOffset ToDateTimeOffset(GrpcOffsetDateTime offsetDateTimeValue)
{
try
{
TimeSpan hourOffset = TimeSpan.FromHours(int.Parse(offsetDateTimeValue.Offset.Substring(1, 2)));
bool add = offsetDateTimeValue.Offset.ElementAt(0) == '+';
TimeSpan offset = add ? hourOffset : hourOffset.Negate();
return DateTimeOffset.FromUnixTimeSeconds(offsetDateTimeValue.Timestamp.Seconds)
.ToOffset(offset);
}
catch (Exception)
{
Console.WriteLine(offsetDateTimeValue.Timestamp + " " +offsetDateTimeValue.Offset);
return DateTimeOffset.Now;
}
TimeSpan hourOffset = offsetDateTimeValue.Offset == "Z" ?
TimeSpan.Zero :
TimeSpan.FromHours(int.Parse(offsetDateTimeValue.Offset.Substring(1, 2)));
bool add = offsetDateTimeValue.Offset.ElementAt(0) == '+';
TimeSpan offset = add ? hourOffset : hourOffset.Negate();
return DateTimeOffset.FromUnixTimeSeconds(offsetDateTimeValue.Timestamp.Seconds)
.ToOffset(offset);
}

public static DateTimeOffset[] ToDateTimeOffsetArray(GrpcOffsetDateTimeArray arrayValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace EvitaDB.Client.Converters.Models.Schema;

public static class CatalogSchemaConverter
{
public static GrpcCatalogSchema Convert(ICatalogSchema catalogSchema)
public static GrpcCatalogSchema Convert(CatalogSchema catalogSchema)
{
return new GrpcCatalogSchema
{
Expand Down
8 changes: 7 additions & 1 deletion EvitaDB.Client/EvitaEntitySchemaCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ public ISealedCatalogSchema GetLatestCatalogSchema(Func<CatalogSchema> schemaAcc

public void SetLatestCatalogSchema(CatalogSchema catalogSchema)
{
CachedSchemas.GetOrAdd(LatestCatalogSchema.Instance, new SchemaWrapper(catalogSchema, CurrentTimeMillis()));
if (!CachedSchemas.ContainsKey(LatestCatalogSchema.Instance))
{
CachedSchemas.AddOrUpdate(
LatestCatalogSchema.Instance,
new SchemaWrapper(catalogSchema, CurrentTimeMillis()),
(_, _) => new SchemaWrapper(catalogSchema, CurrentTimeMillis()));
}
}

public void RemoveLatestCatalogSchema()
Expand Down
16 changes: 8 additions & 8 deletions EvitaDB.TestX/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ namespace EvitaDB.TestX;

public abstract class BaseTest : IClassFixture<SetupFixture>, IAsyncLifetime
{
protected readonly ITestOutputHelper _outputHelper;
protected readonly SetupFixture _setupFixture;
protected readonly ITestOutputHelper OutputHelper;
protected readonly SetupFixture SetupFixture;

protected EvitaClient? _client;
protected EvitaClient? Client;

private const int RandomSeed = 42;
protected static readonly Random Random = new(RandomSeed);
protected const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss zzz";

public BaseTest(ITestOutputHelper outputHelper, SetupFixture setupFixture)
protected BaseTest(ITestOutputHelper outputHelper, SetupFixture setupFixture)
{
_outputHelper = outputHelper;
_setupFixture = setupFixture;
OutputHelper = outputHelper;
SetupFixture = setupFixture;
}

public async Task InitializeAsync()
{
_client = await _setupFixture.GetClient();
Client = await SetupFixture.GetClient();
}

public Task DisposeAsync()
{
_setupFixture.ReturnClient(_client!);
SetupFixture.ReturnClient(Client!);
return Task.CompletedTask;
}
}
50 changes: 25 additions & 25 deletions EvitaDB.TestX/EvitaClientReadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public EvitaClientReadTest(ITestOutputHelper outputHelper, SetupFixture setupFix
[Fact]
public void ShouldQueryCatalog()
{
ICatalogSchema catalogSchema = _client!.QueryCatalog(
ICatalogSchema catalogSchema = Client!.QueryCatalog(
Data.TestCatalog,
x => x.GetCatalogSchema()
);
Expand All @@ -34,7 +34,7 @@ public void ShouldQueryCatalog()
[Fact]
public void ShouldQueryOneEntityReference()
{
EntityReference entityReference = _client!.QueryCatalog(
EntityReference entityReference = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryOneEntityReference(
Query(
Expand All @@ -52,7 +52,7 @@ public void ShouldQueryOneEntityReference()
[Fact]
public void ShouldNotQueryOneMissingEntity()
{
EntityReference? entityReference = _client!.QueryCatalog(
EntityReference? entityReference = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryOneEntityReference(
Query(
Expand All @@ -68,9 +68,9 @@ public void ShouldNotQueryOneMissingEntity()
[Fact]
public void ShouldQueryOneSealedEntity()
{
IList<ISealedEntity> products = _setupFixture.CreatedEntities[Entities.Product];
IList<ISealedEntity> products = SetupFixture.CreatedEntities[Entities.Product];
int primaryKey = products.ElementAt(Random.Next(products.Count)).PrimaryKey!.Value;
ISealedEntity sealedEntity = _client!.QueryCatalog(
ISealedEntity sealedEntity = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryOneSealedEntity(
Query(
Expand Down Expand Up @@ -100,7 +100,7 @@ public void ShouldQueryOneSealedEntity()
public void ShouldQueryListOfEntityReferences()
{
int[] requestedIds = { 1, 2, 5 };
IList<EntityReference> entityReferences = _client!.QueryCatalog(
IList<EntityReference> entityReferences = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryListOfEntityReferences(
Query(
Expand All @@ -126,8 +126,8 @@ public void ShouldQueryListOfEntityReferences()
public void ShouldQueryListOfSealedEntities()
{
int[] requestedIds = { 1, 2, 5 };
IList<ISealedEntity> products = _setupFixture.CreatedEntities[Entities.Product];
IList<ISealedEntity> sealedEntities = _client!.QueryCatalog(
IList<ISealedEntity> products = SetupFixture.CreatedEntities[Entities.Product];
IList<ISealedEntity> sealedEntities = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryListOfSealedEntities(
Query(
Expand Down Expand Up @@ -156,11 +156,11 @@ public void ShouldQueryListOfSealedEntities()
[Fact]
public void ShouldGetListWithExtraResults()
{
ISealedEntity? someProductWithCategory = _setupFixture.CreatedEntities[Entities.Product]
ISealedEntity? someProductWithCategory = SetupFixture.CreatedEntities[Entities.Product]
.Where(it => it.GetReferences(Data.ReferenceCategories).Any())
.FirstOrDefault(it => it.GetAllPricesForSale().Count > 0);
IList<IPrice> allPricesForSale = someProductWithCategory!.GetAllPricesForSale();
EvitaResponse<ISealedEntity> result = _client!.QueryCatalog(
EvitaResponse<ISealedEntity> result = Client!.QueryCatalog(
Data.TestCatalog,
session =>
{
Expand Down Expand Up @@ -226,7 +226,7 @@ public void ShouldGetListWithExtraResults()
[Fact]
public void ShouldGetSingleEntity()
{
ISealedEntity? sealedEntity = _client!.QueryCatalog(
ISealedEntity? sealedEntity = Client!.QueryCatalog(
Data.TestCatalog,
session => session.GetEntity(
Entities.Product,
Expand All @@ -238,14 +238,14 @@ public void ShouldGetSingleEntity()

Assert.Equal(Entities.Product, sealedEntity.Type);
Assert.Equal(7, sealedEntity.PrimaryKey);
Assert.Equal(_setupFixture.CreatedEntities[Entities.Product].Single(x => x.PrimaryKey == 7), sealedEntity);
Assert.Equal(SetupFixture.CreatedEntities[Entities.Product].Single(x => x.PrimaryKey == 7), sealedEntity);
}

[Fact]
public void ShouldEnrichSingleEntity()
{
IList<ISealedEntity> products = _setupFixture.CreatedEntities[Entities.Product];
ISealedEntity? sealedEntity = _client!.QueryCatalog(
IList<ISealedEntity> products = SetupFixture.CreatedEntities[Entities.Product];
ISealedEntity? sealedEntity = Client!.QueryCatalog(
Data.TestCatalog,
session => session.GetEntity(
Entities.Product,
Expand All @@ -257,7 +257,7 @@ public void ShouldEnrichSingleEntity()
Assert.Equal(7, sealedEntity.PrimaryKey);
products.Single(x => x.PrimaryKey == 7).Should().NotBeEquivalentTo(sealedEntity, options => options.Excluding(x=>x.ParentEntity).Excluding(x=>x.Parent));

ISealedEntity? enrichedEntity = _client.QueryCatalog(
ISealedEntity? enrichedEntity = Client.QueryCatalog(
Data.TestCatalog,
session => session.GetEntity(
Entities.Product,
Expand All @@ -276,8 +276,8 @@ public void ShouldEnrichSingleEntity()
[Fact]
public void ShouldLimitSingleEntity()
{
IList<ISealedEntity> products = _setupFixture.CreatedEntities[Entities.Product];
ISealedEntity? sealedEntity = _client!.QueryCatalog(
IList<ISealedEntity> products = SetupFixture.CreatedEntities[Entities.Product];
ISealedEntity? sealedEntity = Client!.QueryCatalog(
Data.TestCatalog,
session => session.GetEntity(
Entities.Product,
Expand All @@ -289,7 +289,7 @@ public void ShouldLimitSingleEntity()
Assert.Equal(7, sealedEntity.PrimaryKey);
products.Single(x => x.PrimaryKey == 7).Should().BeEquivalentTo(sealedEntity, options => options.Excluding(x=>x.ParentEntity).Excluding(x=>x.Parent));

ISealedEntity? limitedEntity = _client.QueryCatalog(
ISealedEntity? limitedEntity = Client.QueryCatalog(
Data.TestCatalog,
session => session.GetEntity(
Entities.Product,
Expand All @@ -305,17 +305,17 @@ public void ShouldLimitSingleEntity()
[Fact]
public void ShouldRetrieveCollectionSize()
{
int productCount = _client!.QueryCatalog(
int productCount = Client!.QueryCatalog(
Data.TestCatalog,
session => session.GetEntityCollectionSize(Entities.Product));

Assert.Equal(_setupFixture.CreatedEntities[Entities.Product].Count, productCount);
Assert.Equal(SetupFixture.CreatedEntities[Entities.Product].Count, productCount);
}

[Fact]
public void ShouldQueryListOfSealedEntitiesEvenWithoutProperRequirements()
{
IList<ISealedEntity> sealedEntities = _client!.QueryCatalog(
IList<ISealedEntity> sealedEntities = Client!.QueryCatalog(
Data.TestCatalog,
session => session.QueryListOfSealedEntities(
Query(
Expand All @@ -331,18 +331,18 @@ public void ShouldQueryListOfSealedEntitiesEvenWithoutProperRequirements()
[Fact]
public void ShouldListCatalogNames()
{
ISet<string> catalogNames = ListCatalogNames(_client!);
_outputHelper.WriteLine(string.Join(", ", catalogNames));
ISet<string> catalogNames = ListCatalogNames(Client!);
OutputHelper.WriteLine(string.Join(", ", catalogNames));
Assert.Equal(1, catalogNames.Count);
Assert.Contains(Data.TestCatalog, catalogNames);
}

[Fact]
public void ShouldBeAbleToRunParallelClients()
{
EvitaClient anotherParallelClient = new EvitaClient(_client!.Configuration);
EvitaClient anotherParallelClient = new EvitaClient(Client!.Configuration);
_ = ListCatalogNames(anotherParallelClient);
_ = ListCatalogNames(_client);
_ = ListCatalogNames(Client);
}

private static ISet<string> ListCatalogNames(EvitaClient client)
Expand Down
Loading

0 comments on commit 634da71

Please sign in to comment.