// Author: Gockner, Simon // Created: 2020-02-13 // Copyright(c) 2020 SimonG. All Rights Reserved. using System; using System.IO; 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()) .Returns(new XmlDataReader()); 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(dataReaderFactoryMock.Object, dataWriterFactoryMock.Object, dataHandlerCacheFactoryMock.Object); xmlDataHandler.Init(false); FileStream file = null; //FixMe: init this correctly if you want to run this test //await xmlDataHandler.SetValue(nameof(TestProperty), TestProperty); //await xmlDataHandler.SetValue(nameof(TestProperty), "empty"); await xmlDataHandler.SetValue(file, nameof(TestProperty), "test", new CancellationToken()); //await xmlDataHandler.SetValue(nameof(TestProperty), "OverwrittenString"); // await xmlDataHandler.SetValue(file, nameof(TestInt), 1, new CancellationToken()); //await xmlDataHandler.SetValue(nameof(TestInt), 2); //await xmlDataHandler.SetValue(nameof(TestInt), 3); TestProperty = await xmlDataHandler.GetValue(file, nameof(TestProperty), new CancellationToken()); TestInt = await xmlDataHandler.GetValue(file, nameof(TestInt), new CancellationToken()); } } }