diff --git a/Test.GBase/DataHandling/XmlDataHandlerLocalIntegrationTest.cs b/Test.GBase/DataHandling/XmlDataHandlerLocalIntegrationTest.cs new file mode 100644 index 0000000..72f4459 --- /dev/null +++ b/Test.GBase/DataHandling/XmlDataHandlerLocalIntegrationTest.cs @@ -0,0 +1,68 @@ +// Author: Gockner, Simon +// Created: 2020-02-13 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; +using System.Threading; +using System.Threading.Tasks; +using GBase.DataHandling; +using GBase.DataHandling.Cache; +using GBase.DataHandling.Cache.Factories; +using GBase.DataHandling.Factories; +using GBase.Interfaces.DataHandling.Xml; +using Moq; +using NUnit.Framework; + +namespace Test.GBase.DataHandling +{ + [TestFixture] + public class XmlDataHandlerLocalIntegrationTest + { + private string TestProperty { get; set; } //= "SomeTestString"; + private int TestInt { get; set; } + + [Test] + public async Task TestXmlDataHandler() + { + Assert.Pass(); //Remove this assert.pass() if you want to run this test locally + + Mock dataWriterFactoryMock = new Mock(); + dataWriterFactoryMock.Setup(w => w.Create(It.IsAny(), It.IsAny())) + .Returns((string path, string rootElementName) => new XmlDataWriter(path, rootElementName)); + + Mock dataReaderFactoryMock = new Mock(); + dataReaderFactoryMock.Setup(r => r.Create(It.IsAny())) + .Returns((string path) => new XmlDataReader(path)); + + Mock dataHandlerCachePropertyEntryFactoryMock = new Mock(); + dataHandlerCachePropertyEntryFactoryMock.Setup(p => p.Create(It.IsAny(), It.IsAny())) + .Returns((string propertyName, object value) => new XmlDataHandlerCachePropertyEntry(propertyName, value)); + + Mock dataHandlerCacheEntryFactoryMock = new Mock(); + dataHandlerCacheEntryFactoryMock.Setup(e => e.Create(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((Type type, string propertyName, object value) => + new XmlDataHandlerCacheEntry(type, propertyName, value, dataHandlerCachePropertyEntryFactoryMock.Object)); + + Mock dataHandlerCacheFactoryMock = new Mock(); + dataHandlerCacheFactoryMock.Setup(c => c.Create(It.IsAny())) + .Returns((IXmlDataReader xmlDataReader) => + new XmlDataHandlerCache(xmlDataReader, dataHandlerCacheEntryFactoryMock.Object, dataHandlerCachePropertyEntryFactoryMock.Object)); + + IXmlDataHandler xmlDataHandler = new XmlDataHandler("TestXml.xml", "Properties", dataReaderFactoryMock.Object, dataWriterFactoryMock.Object, + dataHandlerCacheFactoryMock.Object); + + await xmlDataHandler.Init(false, new CancellationToken()); + // + //await xmlDataHandler.SetValue(nameof(TestProperty), TestProperty); + //await xmlDataHandler.SetValue(nameof(TestProperty), "empty"); + await xmlDataHandler.SetValue(nameof(TestProperty), "test"); + //await xmlDataHandler.SetValue(nameof(TestProperty), "OverwrittenString"); + // + await xmlDataHandler.SetValue(nameof(TestInt), 1); + //await xmlDataHandler.SetValue(nameof(TestInt), 2); + //await xmlDataHandler.SetValue(nameof(TestInt), 3); + TestProperty = await xmlDataHandler.GetValue(nameof(TestProperty)); + TestInt = await xmlDataHandler.GetValue(nameof(TestInt)); + } + } +} \ No newline at end of file