#25: adapt integration test

pull/27/head
Simon G 5 years ago
parent 225f10d1a0
commit 90242543c7
  1. 56
      Test.GBase/GBaseIntegrationTest/GBaseIntegrationTest.cs
  2. 13
      Test.GBase/GBaseIntegrationTest/Group.cs
  3. 3
      Test.GBase/GBaseIntegrationTest/IGroup.cs
  4. 5
      Test.GBase/GBaseIntegrationTest/IItem.cs
  5. 23
      Test.GBase/GBaseIntegrationTest/Item.cs
  6. 17
      Test.GBase/GBaseIntegrationTest/Model.cs
  7. 4
      Test.GBase/GBaseIntegrationTest/Settings.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<IGBaseFactory>();
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);
}
}
}

@ -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<IItem>();
}
[GBaseColumn]
public int Key { get; private set; }
public List<IItem> Items { get; }
public override string ToString() => $"{Key}";
public void InitializeFromString(string @string) => Key = int.Parse(@string);
}
}

@ -7,8 +7,9 @@ using GBase.Api;
namespace Test.GBase.GBaseIntegrationTest
{
public interface IGroup : INotifyGBaseEntryChanged
public interface IGroup : IGBaseObject //: INotifyGBaseEntryChanged
{
int Key { get; }
List<IItem> Items { get; }
}
}

@ -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; }
}
}

@ -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];
}
}
}

@ -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<IItem> itemsTable = _gBase.GetTable<IItem>();
Items = itemsTable.Entries;
IGBaseTable<IGroup> groupsTable = _gBase.GetTable<IGroup>();
Groups = groupsTable.Entries;
// IGBaseTable<Item> itemsTable = _gBase.GetTable<Item>();
// Items = itemsTable.Entries.Cast<IItem>().ToList();
Items = (await _gBase.GetValues<Model, Item>(this, nameof(Items), cancellationToken)).Cast<IItem>().ToList();
// IGBaseTable<Group> groupsTable = _gBase.GetTable<Group>();
// Groups = groupsTable.Entries.Cast<IGroup>().ToList();
Groups = (await _gBase.GetValues<Model, Group>(this, nameof(Groups), cancellationToken)).Cast<IGroup>().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);

@ -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");
}
}
Loading…
Cancel
Save