// 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()) .Returns(new XmlDataWriter()); 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", 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(TODO, nameof(TestProperty), "test", TODO); //await xmlDataHandler.SetValue(nameof(TestProperty), "OverwrittenString"); // await xmlDataHandler.SetValue(TODO, nameof(TestInt), 1, TODO); //await xmlDataHandler.SetValue(nameof(TestInt), 2); //await xmlDataHandler.SetValue(nameof(TestInt), 3); TestProperty = await xmlDataHandler.GetValue(nameof(TestProperty)); TestInt = await xmlDataHandler.GetValue(nameof(TestInt)); } } }