// Author: Gockner, Simon // Created: 2020-03-09 // Copyright(c) 2020 SimonG. All Rights Reserved. using System; using System.Threading; using GBase; using GBase.Factories; using GBase.FileHandling.Factories; using GBase.Interfaces; using GBase.Interfaces.DataHandling.Pool; using GBase.Interfaces.FileHandling; using Moq; using NUnit.Framework; using Test.GBase.TestClasses; namespace Test.GBase { [TestFixture] public class GBaseTableIntegrationTest { [Test] public void TestEntryHandling() { Mock fileHandlerFactoryMock = new Mock(); fileHandlerFactoryMock.Setup(f => f.Create()).Returns(new Mock().Object); IGBaseColumn gBaseColumn = null; Mock gBaseColumnFactoryMock = new Mock(); gBaseColumnFactoryMock.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((name, type, isKey) => { gBaseColumn = new GBaseColumn(name, type, isKey); }) .Returns(gBaseColumn); Mock dataHandlerPoolMock = new Mock(); IGBaseTable table = new GBaseTable(fileHandlerFactoryMock.Object, dataHandlerPoolMock.Object, gBaseColumnFactoryMock.Object); table.Init(typeof(Foo), "", "", CancellationToken.None); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); Foo foo = new Foo("Test"); table.AddEntry(foo, cancellationTokenSource.Token); Foo foo2 = new Foo("Test2"); table.AddEntry(foo2, cancellationTokenSource.Token); foo.Name = "Foo - ex Test"; foo2.Name = "Some Name"; Assert.AreEqual(foo.Name, ((Foo) table.Entries[0]).Name); Assert.AreEqual(foo2.Name, ((Foo) table.Entries[1]).Name); } } }