diff --git a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs index 143825b..dc0bcd1 100644 --- a/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs +++ b/EvitaDB.Client/Converters/DataTypes/EvitaDataTypesConverter.cs @@ -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) diff --git a/EvitaDB.Client/Converters/Models/Schema/CatalogSchemaConverter.cs b/EvitaDB.Client/Converters/Models/Schema/CatalogSchemaConverter.cs index 5f5f250..55e72d3 100644 --- a/EvitaDB.Client/Converters/Models/Schema/CatalogSchemaConverter.cs +++ b/EvitaDB.Client/Converters/Models/Schema/CatalogSchemaConverter.cs @@ -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 { diff --git a/EvitaDB.Client/EvitaEntitySchemaCache.cs b/EvitaDB.Client/EvitaEntitySchemaCache.cs index caf82ab..4bed6f5 100644 --- a/EvitaDB.Client/EvitaEntitySchemaCache.cs +++ b/EvitaDB.Client/EvitaEntitySchemaCache.cs @@ -82,7 +82,13 @@ public ISealedCatalogSchema GetLatestCatalogSchema(Func 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() diff --git a/EvitaDB.TestX/BaseTest.cs b/EvitaDB.TestX/BaseTest.cs index 25bbff3..1b42868 100644 --- a/EvitaDB.TestX/BaseTest.cs +++ b/EvitaDB.TestX/BaseTest.cs @@ -5,29 +5,29 @@ namespace EvitaDB.TestX; public abstract class BaseTest : IClassFixture, 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; } } \ No newline at end of file diff --git a/EvitaDB.TestX/EvitaClientReadTest.cs b/EvitaDB.TestX/EvitaClientReadTest.cs index 3f7f54f..d73fe36 100644 --- a/EvitaDB.TestX/EvitaClientReadTest.cs +++ b/EvitaDB.TestX/EvitaClientReadTest.cs @@ -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() ); @@ -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( @@ -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( @@ -68,9 +68,9 @@ public void ShouldNotQueryOneMissingEntity() [Fact] public void ShouldQueryOneSealedEntity() { - IList products = _setupFixture.CreatedEntities[Entities.Product]; + IList 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( @@ -100,7 +100,7 @@ public void ShouldQueryOneSealedEntity() public void ShouldQueryListOfEntityReferences() { int[] requestedIds = { 1, 2, 5 }; - IList entityReferences = _client!.QueryCatalog( + IList entityReferences = Client!.QueryCatalog( Data.TestCatalog, session => session.QueryListOfEntityReferences( Query( @@ -126,8 +126,8 @@ public void ShouldQueryListOfEntityReferences() public void ShouldQueryListOfSealedEntities() { int[] requestedIds = { 1, 2, 5 }; - IList products = _setupFixture.CreatedEntities[Entities.Product]; - IList sealedEntities = _client!.QueryCatalog( + IList products = SetupFixture.CreatedEntities[Entities.Product]; + IList sealedEntities = Client!.QueryCatalog( Data.TestCatalog, session => session.QueryListOfSealedEntities( Query( @@ -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 allPricesForSale = someProductWithCategory!.GetAllPricesForSale(); - EvitaResponse result = _client!.QueryCatalog( + EvitaResponse result = Client!.QueryCatalog( Data.TestCatalog, session => { @@ -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, @@ -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 products = _setupFixture.CreatedEntities[Entities.Product]; - ISealedEntity? sealedEntity = _client!.QueryCatalog( + IList products = SetupFixture.CreatedEntities[Entities.Product]; + ISealedEntity? sealedEntity = Client!.QueryCatalog( Data.TestCatalog, session => session.GetEntity( Entities.Product, @@ -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, @@ -276,8 +276,8 @@ public void ShouldEnrichSingleEntity() [Fact] public void ShouldLimitSingleEntity() { - IList products = _setupFixture.CreatedEntities[Entities.Product]; - ISealedEntity? sealedEntity = _client!.QueryCatalog( + IList products = SetupFixture.CreatedEntities[Entities.Product]; + ISealedEntity? sealedEntity = Client!.QueryCatalog( Data.TestCatalog, session => session.GetEntity( Entities.Product, @@ -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, @@ -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 sealedEntities = _client!.QueryCatalog( + IList sealedEntities = Client!.QueryCatalog( Data.TestCatalog, session => session.QueryListOfSealedEntities( Query( @@ -331,8 +331,8 @@ public void ShouldQueryListOfSealedEntitiesEvenWithoutProperRequirements() [Fact] public void ShouldListCatalogNames() { - ISet catalogNames = ListCatalogNames(_client!); - _outputHelper.WriteLine(string.Join(", ", catalogNames)); + ISet catalogNames = ListCatalogNames(Client!); + OutputHelper.WriteLine(string.Join(", ", catalogNames)); Assert.Equal(1, catalogNames.Count); Assert.Contains(Data.TestCatalog, catalogNames); } @@ -340,9 +340,9 @@ public void ShouldListCatalogNames() [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 ListCatalogNames(EvitaClient client) diff --git a/EvitaDB.TestX/EvitaClientWriteTest.cs b/EvitaDB.TestX/EvitaClientWriteTest.cs index ba2fdaf..776d4ad 100644 --- a/EvitaDB.TestX/EvitaClientWriteTest.cs +++ b/EvitaDB.TestX/EvitaClientWriteTest.cs @@ -32,13 +32,13 @@ public void ShouldBeAbleToCreateCatalogAndEntitySchemaAndInsertNewEntityWithAttr string nonExistingAttribute = "nonExistingAttribute"; // delete test catalog if it exists - _client!.DeleteCatalogIfExists(Data.TestCatalog); + Client!.DeleteCatalogIfExists(Data.TestCatalog); // define new catalog - ICatalogSchema catalogSchema = _client.DefineCatalog(Data.TestCatalog).ToInstance(); + ICatalogSchema catalogSchema = Client.DefineCatalog(Data.TestCatalog).ToInstance(); Assert.Equal(Data.TestCatalog, catalogSchema.Name); - using (EvitaClientSession rwSession = _client.CreateReadWriteSession(Data.TestCatalog)) + using (EvitaClientSession rwSession = Client.CreateReadWriteSession(Data.TestCatalog)) { // create a new entity schema catalogSchema = rwSession.UpdateAndFetchCatalogSchema(new CreateEntitySchemaMutation(testCollection)); @@ -79,7 +79,7 @@ public void ShouldBeAbleToCreateCatalogAndEntitySchemaAndInsertNewEntityWithAttr rwSession.GoLiveAndClose(); } - using EvitaClientSession newSession = _client.CreateReadWriteSession(Data.TestCatalog); + using EvitaClientSession newSession = Client.CreateReadWriteSession(Data.TestCatalog); // insert a new entity with one of attributes defined in the entity schema DateTimeOffset dateTimeNow = DateTimeOffset.Now; @@ -121,14 +121,14 @@ public void ShouldAllowCreatingCatalogAlongWithTheSchema() string someCatalogName = "differentCatalog"; try { - _client!.DefineCatalog(someCatalogName) + Client!.DefineCatalog(someCatalogName) .WithDescription("Some description.") - .UpdateVia(_client.CreateReadWriteSession(someCatalogName)); - Assert.Contains(someCatalogName, _client.GetCatalogNames()); + .UpdateVia(Client.CreateReadWriteSession(someCatalogName)); + Assert.Contains(someCatalogName, Client.GetCatalogNames()); } finally { - _client!.DeleteCatalogIfExists(someCatalogName); + Client!.DeleteCatalogIfExists(someCatalogName); } } @@ -139,11 +139,11 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsInPrototypingMode() CultureInfo locale = Data.EnglishLocale; try { - _client!.DefineCatalog(someCatalogName) + Client!.DefineCatalog(someCatalogName) .WithDescription("This is a tutorial catalog.") - .UpdateViaNewSession(_client); - Assert.Contains(someCatalogName, _client.GetCatalogNames()); - _client.UpdateCatalog( + .UpdateViaNewSession(Client); + Assert.Contains(someCatalogName, Client.GetCatalogNames()); + Client.UpdateCatalog( someCatalogName, session => { @@ -207,7 +207,7 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsInPrototypingMode() } finally { - _client!.DeleteCatalogIfExists(someCatalogName); + Client!.DeleteCatalogIfExists(someCatalogName); } } @@ -217,7 +217,7 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsSchemas() string someCatalogName = "differentCatalog"; try { - _client!.DefineCatalog(someCatalogName) + Client!.DefineCatalog(someCatalogName) .WithDescription("This is a tutorial catalog.") // define brand schema .WithEntitySchema( @@ -267,9 +267,9 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsSchemas() ) ) // and now push all the definitions (mutations) to the server - .UpdateViaNewSession(_client); - Assert.Contains(someCatalogName, _client.GetCatalogNames()); - _client.QueryCatalog(someCatalogName, session => + .UpdateViaNewSession(Client); + Assert.Contains(someCatalogName, Client.GetCatalogNames()); + Client.QueryCatalog(someCatalogName, session => { ISet allEntityTypes = session.GetAllEntityTypes(); Assert.Contains(Entities.Brand, allEntityTypes); @@ -279,7 +279,7 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsSchemas() } finally { - _client!.DeleteCatalogIfExists(someCatalogName); + Client!.DeleteCatalogIfExists(someCatalogName); } } @@ -288,7 +288,7 @@ public void ShouldAllowCreatingCatalogAndEntityCollectionsSchemas() [Fact] public void ShouldBeAbleToFetchNonCachedEntitySchemaFromCatalogSchema() { - EvitaClient clientWithEmptyCache = new EvitaClient(_client!.Configuration); + EvitaClient clientWithEmptyCache = new EvitaClient(Client!.Configuration); clientWithEmptyCache.QueryCatalog( Data.TestCatalog, session => @@ -305,8 +305,8 @@ public void ShouldCreateCatalog() string newCatalogName = "newCatalog"; try { - _client!.DefineCatalog(newCatalogName); - ISet catalogNames = _client.GetCatalogNames(); + Client!.DefineCatalog(newCatalogName); + ISet catalogNames = Client.GetCatalogNames(); Assert.Equal(2 , catalogNames.Count); Assert.Contains(Data.TestCatalog, catalogNames); @@ -314,7 +314,7 @@ public void ShouldCreateCatalog() } finally { - _client!.DeleteCatalogIfExists(newCatalogName); + Client!.DeleteCatalogIfExists(newCatalogName); } } @@ -322,11 +322,11 @@ public void ShouldCreateCatalog() public void ShouldRemoveCatalog() { string newCatalogName = "newCatalog"; - _client!.DefineCatalog(newCatalogName).UpdateViaNewSession(_client); - bool removed = _client.DeleteCatalogIfExists(newCatalogName); + Client!.DefineCatalog(newCatalogName).UpdateViaNewSession(Client); + bool removed = Client.DeleteCatalogIfExists(newCatalogName); Assert.True(removed); - ISet catalogNames = _client.GetCatalogNames(); + ISet catalogNames = Client.GetCatalogNames(); Assert.Equal(1, catalogNames.Count); Assert.Contains(Data.TestCatalog, catalogNames); } @@ -335,21 +335,21 @@ public void ShouldRemoveCatalog() public void ShouldReplaceCatalog() { string newCatalog = "newCatalog"; - _client!.DefineCatalog(newCatalog); + Client!.DefineCatalog(newCatalog); - ISet catalogNames = _client.GetCatalogNames(); + ISet catalogNames = Client.GetCatalogNames(); Assert.Equal(2, catalogNames.Count); Assert.Contains(newCatalog, catalogNames); Assert.Contains(Data.TestCatalog, catalogNames); - int initialSchemaVersion = _client.QueryCatalog(Data.TestCatalog, + int initialSchemaVersion = Client.QueryCatalog(Data.TestCatalog, evitaSessionContract => evitaSessionContract.GetCatalogSchema().Version); - _client.ReplaceCatalog(Data.TestCatalog, newCatalog); + Client.ReplaceCatalog(Data.TestCatalog, newCatalog); - ISet catalogNamesAgain = _client.GetCatalogNames(); + ISet catalogNamesAgain = Client.GetCatalogNames(); Assert.Equal(1, catalogNamesAgain.Count); Assert.Contains(newCatalog, catalogNamesAgain); - Assert.Equal(initialSchemaVersion + 1, _client.QueryCatalog(newCatalog, + Assert.Equal(initialSchemaVersion + 1, Client.QueryCatalog(newCatalog, evitaSessionContract => evitaSessionContract.GetCatalogSchema().Version)); } @@ -358,20 +358,20 @@ public void ShouldRenameCatalog() { string newCatalog = "newCatalog"; - ISet catalogNames = _client!.GetCatalogNames(); + ISet catalogNames = Client!.GetCatalogNames(); Assert.Equal(1, catalogNames.Count); Assert.Contains(Data.TestCatalog, catalogNames); - int initialSchemaVersion = _client.QueryCatalog(Data.TestCatalog, + int initialSchemaVersion = Client.QueryCatalog(Data.TestCatalog, evitaSessionContract => evitaSessionContract.GetCatalogSchema().Version); - _client.RenameCatalog(Data.TestCatalog, newCatalog); + Client.RenameCatalog(Data.TestCatalog, newCatalog); - ISet catalogNamesAgain = _client.GetCatalogNames(); + ISet catalogNamesAgain = Client.GetCatalogNames(); Assert.Equal(1, catalogNamesAgain.Count); Assert.Contains(newCatalog, catalogNamesAgain); - Assert.Equal(initialSchemaVersion + 1, _client.QueryCatalog(newCatalog, + Assert.Equal(initialSchemaVersion + 1, Client.QueryCatalog(newCatalog, evitaSessionContract => evitaSessionContract.GetCatalogSchema().Version)); - _ = _client.DeleteCatalogIfExists(newCatalog); + _ = Client.DeleteCatalogIfExists(newCatalog); } [Fact] @@ -380,7 +380,7 @@ public void ShouldReplaceCollection() string newCollection = "newCollection"; int? productCount = null; int? productSchemaVersion = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -394,13 +394,13 @@ public void ShouldReplaceCollection() productCount = session.GetEntityCollectionSize(Entities.Product); } ); - _client.UpdateCatalog( + Client.UpdateCatalog( Data.TestCatalog, session => session.ReplaceCollection( newCollection, Entities.Product )); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -419,7 +419,7 @@ public void ShouldRenameCollection() string newCollection = "newCollection"; int? productCount = null; int? productSchemaVersion = null; - _client!.QueryCatalog( + Client!.QueryCatalog( Data.TestCatalog, session => { @@ -429,13 +429,13 @@ public void ShouldRenameCollection() productCount = session.GetEntityCollectionSize(Entities.Product); } ); - _client.UpdateCatalog( + Client.UpdateCatalog( Data.TestCatalog, session => session.RenameCollection( Entities.Product, newCollection )); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -452,7 +452,7 @@ public void ShouldRenameCollection() public void ShouldCallTerminationCallbackWhenClientClosesSession() { Guid? terminatedSessionId = null; - EvitaClientSession theSession = _client!.CreateSession( + EvitaClientSession theSession = Client!.CreateSession( new SessionTraits( Data.TestCatalog, session => terminatedSessionId = session.SessionId @@ -466,20 +466,20 @@ public void ShouldCallTerminationCallbackWhenClientClosesSession() public void ShouldCallTerminationCallbackWhenClientIsClosed() { Guid? terminatedSessionId = null; - _client!.CreateSession( + Client!.CreateSession( new SessionTraits( Data.TestCatalog, session => { ModifyGuid(ref terminatedSessionId, session.SessionId); } ) ); - _client.Close(); + Client.Close(); Assert.NotNull(terminatedSessionId); } [Fact] public void ShouldTranslateErrorCorrectlyAndLeaveSessionOpen() { - using EvitaClientSession clientSession = _client!.CreateReadOnlySession(Data.TestCatalog); + using EvitaClientSession clientSession = Client!.CreateReadOnlySession(Data.TestCatalog); try { clientSession.GetEntity("nonExisting", 1, EntityFetchAll().Requirements!); @@ -500,7 +500,7 @@ public void ShouldTranslateErrorCorrectlyAndLeaveSessionOpen() [Fact] public void ShouldReturnEntitySchema() { - EvitaClientSession evitaSession = _client!.CreateReadOnlySession(Data.TestCatalog); + EvitaClientSession evitaSession = Client!.CreateReadOnlySession(Data.TestCatalog); Assert.NotNull(evitaSession.GetEntitySchema(Entities.Product)); Assert.NotNull(evitaSession.GetEntitySchemaOrThrow(Entities.Product)); } @@ -508,7 +508,7 @@ public void ShouldReturnEntitySchema() [Fact] public void ShouldCreateAndDropEntityCollection() { - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -528,7 +528,7 @@ public void ShouldCreateAndDropEntityCollection() public void ShouldUpsertNewEntity() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -540,7 +540,7 @@ public void ShouldUpsertNewEntity() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -553,7 +553,7 @@ public void ShouldUpsertNewEntity() ); // reset data - _client.UpdateCatalog( + Client.UpdateCatalog( Data.TestCatalog, session => { session.DeleteEntity(Entities.Product, newProductId!.Value); } ); @@ -563,7 +563,7 @@ public void ShouldUpsertNewEntity() public void ShouldUpsertAndFetchNewEntity() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -579,7 +579,7 @@ public void ShouldUpsertAndFetchNewEntity() ); // reset data - _client.UpdateCatalog( + Client.UpdateCatalog( Data.TestCatalog, session => { session.DeleteEntity(Entities.Product, newProductId!.Value); } ); @@ -589,7 +589,7 @@ public void ShouldUpsertAndFetchNewEntity() public void ShouldDeleteExistingEntity() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -602,7 +602,7 @@ public void ShouldDeleteExistingEntity() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -618,7 +618,7 @@ public void ShouldDeleteExistingEntity() public void ShouldDeleteAndFetchExistingEntity() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -638,7 +638,7 @@ public void ShouldDeleteAndFetchExistingEntity() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -654,7 +654,7 @@ public void ShouldDeleteAndFetchExistingEntity() public void ShouldDeleteEntityByQuery() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -676,7 +676,7 @@ public void ShouldDeleteEntityByQuery() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -692,7 +692,7 @@ public void ShouldDeleteEntityByQuery() public void ShouldDeleteEntitiesAndFetchByQuery() { int? newProductId = null; - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -716,7 +716,7 @@ public void ShouldDeleteEntitiesAndFetchByQuery() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -731,7 +731,7 @@ public void ShouldDeleteEntitiesAndFetchByQuery() [Fact] public void ShouldDeleteHierarchy() { - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -748,7 +748,7 @@ public void ShouldDeleteHierarchy() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -763,7 +763,7 @@ public void ShouldDeleteHierarchy() [Fact] public void ShouldDeleteHierarchyAndFetchRoot() { - _client!.UpdateCatalog( + Client!.UpdateCatalog( Data.TestCatalog, session => { @@ -784,7 +784,7 @@ public void ShouldDeleteHierarchyAndFetchRoot() } ); - _client.QueryCatalog( + Client.QueryCatalog( Data.TestCatalog, session => { @@ -799,7 +799,7 @@ public void ShouldDeleteHierarchyAndFetchRoot() [Fact] public void ShouldThrowWhenAddingEntityThatViolatesSchema() { - Assert.Throws(() => DataManipulationUtil.CreateProductThatViolatesSchema(_client!, Entities.Product)); + Assert.Throws(() => DataManipulationUtil.CreateProductThatViolatesSchema(Client!, Entities.Product)); } private static void AssertSomeNewProductContent(ISealedEntity loadedEntity) diff --git a/EvitaDB.TestX/SetupFixture.cs b/EvitaDB.TestX/SetupFixture.cs index c5af0c1..5ce33fd 100644 --- a/EvitaDB.TestX/SetupFixture.cs +++ b/EvitaDB.TestX/SetupFixture.cs @@ -22,13 +22,14 @@ public class SetupFixture : IAsyncLifetime private const int SystemApiPort = 5557; private const string Host = "localhost"; private const string ImageName = "evitadb/evitadb:canary"; - + public async Task GetClient() { if (_clients.TryDequeue(out EvitaClient? evitaClient)) { DataManipulationUtil.DeleteCreateAndSetupCatalog(evitaClient, Data.TestCatalog); - return evitaClient; + evitaClient.Close(); + return new EvitaClient(evitaClient.Configuration); } return await InitializeEvitaContainerAndClientClient(); } @@ -82,12 +83,16 @@ public async Task DisposeAsync() { foreach (var suite in _testSuites) { - suite.Client.Dispose(); await suite.Container.StopAsync(); } + + while (_clients.TryDequeue(out EvitaClient? evitaClient)) + { + evitaClient.Close(); + } } - private async Task InitializeEvitaContainerAndClientClient(bool cacheCreatedEntities = false) + private async Task InitializeEvitaContainerAndClientClient(bool cacheCreatedEntitiesAndDestroySetupClient = false) { IContainer container; using (var consumer = Consume.RedirectStdoutAndStderrToConsole()) @@ -119,24 +124,26 @@ await container.StartAsync() } } - // create a evita client configuration the the running instance of evita server EvitaClientConfiguration configuration = new EvitaClientConfiguration.Builder() .SetHost(Host) - .SetPort(container.GetMappedPublicPort(GrpcPort)) - .SetSystemApiPort(container.GetMappedPublicPort(SystemApiPort)) + .SetPort(GrpcPort) + .SetSystemApiPort(SystemApiPort) .Build(); - + // create a new evita client with the specified configuration - EvitaClient evitaClient = new EvitaClient(configuration); - IDictionary> createdData = DataManipulationUtil.DeleteCreateAndSetupCatalog(evitaClient, Data.TestCatalog); - - if (cacheCreatedEntities) + using (EvitaClient setupClient = new EvitaClient(configuration)) { - CreatedEntities = createdData; + if (cacheCreatedEntitiesAndDestroySetupClient) + { + CreatedEntities = DataManipulationUtil.DeleteCreateAndSetupCatalog(setupClient, Data.TestCatalog); + } } + + EvitaClient client = new EvitaClient(configuration); + + _testSuites.Add(new EvitaTestSuite(client, container)); - _testSuites.Add(new EvitaTestSuite(evitaClient, container)); - return evitaClient; + return client; } private class EvitaTestSuite