A database based on .net
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.

68 lines
3.8 KiB

// 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<IXmlDataWriterFactory> dataWriterFactoryMock = new Mock<IXmlDataWriterFactory>();
dataWriterFactoryMock.Setup(w => w.Create())
.Returns(new XmlDataWriter());
Mock<IXmlDataReaderFactory> dataReaderFactoryMock = new Mock<IXmlDataReaderFactory>();
dataReaderFactoryMock.Setup(r => r.Create(It.IsAny<string>()))
.Returns((string path) => new XmlDataReader(path));
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("TestXml.xml", dataReaderFactoryMock.Object, dataWriterFactoryMock.Object,
dataHandlerCacheFactoryMock.Object);
await xmlDataHandler.Init(false, new CancellationToken());
//
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), TestProperty);
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), "empty");
await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), "test");
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty), "OverwrittenString");
//
await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt), 1);
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt), 2);
//await xmlDataHandler.SetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt), 3);
TestProperty = await xmlDataHandler.GetValue<XmlDataHandlerLocalIntegrationTest, string>(nameof(TestProperty));
TestInt = await xmlDataHandler.GetValue<XmlDataHandlerLocalIntegrationTest, int>(nameof(TestInt));
}
}
}