diff --git a/Test.GBase/GBaseIntegrationTest/GBaseIntegrationTest.cs b/Test.GBase/GBaseIntegrationTest/GBaseIntegrationTest.cs new file mode 100644 index 0000000..50a8541 --- /dev/null +++ b/Test.GBase/GBaseIntegrationTest/GBaseIntegrationTest.cs @@ -0,0 +1,56 @@ +// Author: Gockner, Simon +// Created: 2020-11-11 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System.Threading; +using System.Threading.Tasks; +using GBase.Factories; +using GBase.Installers; +using LightweightIocContainer; +using LightweightIocContainer.Interfaces; +using NUnit.Framework; + +namespace Test.GBase.GBaseIntegrationTest +{ + [TestFixture] + public class GBaseIntegrationTest + { + private CancellationTokenSource _cancellationTokenSource; + private IIocContainer _iocContainer; + + [SetUp] + public void SetUp() + { + _cancellationTokenSource = new CancellationTokenSource(); + + _iocContainer = new IocContainer(); + _iocContainer.Install(new GBaseInstaller(), + new DataHandlingInstaller(), + new FileHandlingInstaller()); + } + + [TearDown] + public void TearDown() + { + _cancellationTokenSource.Dispose(); + _iocContainer.Dispose(); + } + + [Test] + public async Task TestGBase() + { + IGBaseFactory gBaseFactory = _iocContainer.Resolve(); + Model model = new Model(gBaseFactory); + + await model.Initialize(_cancellationTokenSource.Token); + + await model.AddItem(new Item("Item 1", 1), _cancellationTokenSource.Token); + await model.AddItem(new Item("Item 2", 2), _cancellationTokenSource.Token); + await model.AddItem(new Item("Item 3", 3), _cancellationTokenSource.Token); + + await model.AddGroup(new Group(1), _cancellationTokenSource.Token); + await model.AddGroup(new Group(2), _cancellationTokenSource.Token); + await model.AddGroup(new Group(3), _cancellationTokenSource.Token); + } + } +} \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/Group.cs b/Test.GBase/GBaseIntegrationTest/Group.cs index 24a77de..b9587af 100644 --- a/Test.GBase/GBaseIntegrationTest/Group.cs +++ b/Test.GBase/GBaseIntegrationTest/Group.cs @@ -3,19 +3,24 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System.Collections.Generic; -using GBase.Api; using GBase.Attributes; namespace Test.GBase.GBaseIntegrationTest { [GBaseTable("Groups")] - public class Group : NotifyGBaseEntryChanged, IGroup + public class Group : IGroup { - public Group() + public Group(int key) { + Key = key; Items = new List(); } - + + [GBaseColumn] + public int Key { get; private set; } public List Items { get; } + + public override string ToString() => $"{Key}"; + public void InitializeFromString(string @string) => Key = int.Parse(@string); } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/IGroup.cs b/Test.GBase/GBaseIntegrationTest/IGroup.cs index 966eac8..1957f03 100644 --- a/Test.GBase/GBaseIntegrationTest/IGroup.cs +++ b/Test.GBase/GBaseIntegrationTest/IGroup.cs @@ -7,8 +7,9 @@ using GBase.Api; namespace Test.GBase.GBaseIntegrationTest { - public interface IGroup : INotifyGBaseEntryChanged + public interface IGroup : IGBaseObject //: INotifyGBaseEntryChanged { + int Key { get; } List Items { get; } } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/IItem.cs b/Test.GBase/GBaseIntegrationTest/IItem.cs index 5d4fe77..8aaea05 100644 --- a/Test.GBase/GBaseIntegrationTest/IItem.cs +++ b/Test.GBase/GBaseIntegrationTest/IItem.cs @@ -6,8 +6,9 @@ using GBase.Api; namespace Test.GBase.GBaseIntegrationTest { - public interface IItem : INotifyGBaseEntryChanged + public interface IItem : IGBaseObject //: INotifyGBaseEntryChanged { - + string Name { get; } + int Key { get; } } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/Item.cs b/Test.GBase/GBaseIntegrationTest/Item.cs index 5eaecc7..e49acd8 100644 --- a/Test.GBase/GBaseIntegrationTest/Item.cs +++ b/Test.GBase/GBaseIntegrationTest/Item.cs @@ -2,14 +2,33 @@ // Created: 2020-09-18 // Copyright(c) 2020 SimonG. All Rights Reserved. -using GBase.Api; using GBase.Attributes; namespace Test.GBase.GBaseIntegrationTest { [GBaseTable("Items")] - public class Item : NotifyGBaseEntryChanged, IItem + public class Item : IItem { + public Item(string name, int key) + { + Name = name; + Key = key; + } + + [GBaseColumn] + public string Name { get; private set; } + [GBaseColumn] + public int Key { get; private set; } + + public override string ToString() => $"{Name}"; + + public void InitializeFromString(string @string) + { + string[] properties = @string.Split('/'); + + Key = int.Parse(properties[0]); + Name = properties[1]; + } } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/Model.cs b/Test.GBase/GBaseIntegrationTest/Model.cs index 31d6e1a..0b608a7 100644 --- a/Test.GBase/GBaseIntegrationTest/Model.cs +++ b/Test.GBase/GBaseIntegrationTest/Model.cs @@ -3,6 +3,7 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -29,20 +30,22 @@ namespace Test.GBase.GBaseIntegrationTest { await _gBase.Init("DB", Assembly.GetExecutingAssembly(), cancellationToken); - IGBaseTable itemsTable = _gBase.GetTable(); - Items = itemsTable.Entries; - - IGBaseTable groupsTable = _gBase.GetTable(); - Groups = groupsTable.Entries; + // IGBaseTable itemsTable = _gBase.GetTable(); + // Items = itemsTable.Entries.Cast().ToList(); + Items = (await _gBase.GetValues(this, nameof(Items), cancellationToken)).Cast().ToList(); + + // IGBaseTable groupsTable = _gBase.GetTable(); + // Groups = groupsTable.Entries.Cast().ToList(); + Groups = (await _gBase.GetValues(this, nameof(Groups), cancellationToken)).Cast().ToList(); } - public async Task AddItem(IItem item, CancellationToken cancellationToken) + public async Task AddItem(Item item, CancellationToken cancellationToken) { Items.Add(item); await _gBase.AddEntry(item, cancellationToken); } - public async Task AddGroup(IGroup group, CancellationToken cancellationToken) + public async Task AddGroup(Group group, CancellationToken cancellationToken) { Groups.Add(group); await _gBase.AddEntry(group, cancellationToken); diff --git a/Test.GBase/GBaseIntegrationTest/Settings.cs b/Test.GBase/GBaseIntegrationTest/Settings.cs index 8335033..9040384 100644 --- a/Test.GBase/GBaseIntegrationTest/Settings.cs +++ b/Test.GBase/GBaseIntegrationTest/Settings.cs @@ -2,12 +2,14 @@ // Created: 2020-09-18 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System; +using System.IO; using GBase.Interfaces.Settings; namespace Test.GBase.GBaseIntegrationTest { public class Settings : IGBaseSettings { - public string DatabasePath => ""; + public string DatabasePath => Path.Combine(Environment.CurrentDirectory, "DB"); } } \ No newline at end of file