You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
3.9 KiB
70 lines
3.9 KiB
// 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<IXmlDataWriterFactory> dataWriterFactoryMock = new Mock<IXmlDataWriterFactory>();
|
|
dataWriterFactoryMock.Setup(w => w.Create())
|
|
.Returns(new XmlDataWriter());
|
|
|
|
Mock<IXmlDataReaderFactory> dataReaderFactoryMock = new Mock<IXmlDataReaderFactory>();
|
|
dataReaderFactoryMock.Setup(r => r.Create())
|
|
.Returns(new XmlDataReader());
|
|
|
|
Mock<IXmlDataHandlerCachePropertyEntryFactory> dataHandlerCachePropertyEntryFactoryMock = new Mock<IXmlDataHandlerCachePropertyEntryFactory>();
|
|
dataHandlerCachePropertyEntryFactoryMock.Setup(p => p.Create(It.IsAny<string>(), It.IsAny<object>()))
|
|
.Returns((string propertyName, object value) => new XmlDataHandlerCachePropertyEntry(propertyName, value));
|
|
|
|
Mock<IXmlDataHandlerCacheEntryFactory> dataHandlerCacheEntryFactoryMock = new Mock<IXmlDataHandlerCacheEntryFactory>();
|
|
dataHandlerCacheEntryFactoryMock.Setup(e => e.Create(It.IsAny<Type>(), It.IsAny<string>(), It.IsAny<object>()))
|
|
.Returns((Type type, string propertyName, object value) =>
|
|
new XmlDataHandlerCacheEntry(type, propertyName, value, dataHandlerCachePropertyEntryFactoryMock.Object));
|
|
|
|
Mock<IXmlDataHandlerCacheFactory> dataHandlerCacheFactoryMock = new Mock<IXmlDataHandlerCacheFactory>();
|
|
dataHandlerCacheFactoryMock.Setup(c => c.Create(It.IsAny<IXmlDataReader>()))
|
|
.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<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), TestProperty);
|
|
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), "empty");
|
|
await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(file, nameof(TestProperty), "test", new CancellationToken());
|
|
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), "OverwrittenString");
|
|
//
|
|
await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(file, nameof(TestInt), 1, new CancellationToken());
|
|
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt), 2);
|
|
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt), 3);
|
|
TestProperty = await xmlDataHandler.GetValue<XmlDataHandlerLocalIntegrationTest, string>(file, nameof(TestProperty), new CancellationToken());
|
|
TestInt = await xmlDataHandler.GetValue<XmlDataHandlerLocalIntegrationTest, int>(file, nameof(TestInt), new CancellationToken());
|
|
}
|
|
}
|
|
} |