From 0f9531cfb5c4ea9c6cd2a0157ab1dfb343325e99 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Thu, 13 Feb 2020 15:37:17 +0100 Subject: [PATCH] #11: update setValue method to handle enumerables --- GBase/DataHandling/XmlDataHandler.cs | 10 +++++++++- GBase/GBase.xml | 7 +++++++ Test.GBase/DataHandling/XmlDataHandlerTest.cs | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/GBase/DataHandling/XmlDataHandler.cs b/GBase/DataHandling/XmlDataHandler.cs index 7c620af..d8d76bc 100644 --- a/GBase/DataHandling/XmlDataHandler.cs +++ b/GBase/DataHandling/XmlDataHandler.cs @@ -3,12 +3,14 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using GBase.DataHandling.Cache.Factories; using GBase.DataHandling.Factories; +using GBase.Helpers; using GBase.Interfaces.DataHandling; using GBase.Interfaces.DataHandling.Xml; using GBase.Interfaces.DataHandling.Xml.Cache; @@ -97,8 +99,14 @@ namespace GBase.DataHandling if (value == null) return; + string valueString; + if (typeof(TProperty) != typeof(string) && value is IEnumerable enumerable) + valueString = enumerable.ToGBaseString(); + else + valueString = value.ToString(); + await _cache.SetValue(propertyName, value, _overwrite); - await _xmlDataWriter.Write(propertyName, value.ToString(), _overwrite); + await _xmlDataWriter.Write(propertyName, valueString, _overwrite); } /// diff --git a/GBase/GBase.xml b/GBase/GBase.xml index 4e6c105..2335a4e 100644 --- a/GBase/GBase.xml +++ b/GBase/GBase.xml @@ -532,6 +532,13 @@ A to await + + + Convert an to a GBase + + The + + for the data handling diff --git a/Test.GBase/DataHandling/XmlDataHandlerTest.cs b/Test.GBase/DataHandling/XmlDataHandlerTest.cs index 2b44a9a..89881e7 100644 --- a/Test.GBase/DataHandling/XmlDataHandlerTest.cs +++ b/Test.GBase/DataHandling/XmlDataHandlerTest.cs @@ -165,7 +165,7 @@ namespace Test.GBase.DataHandling await xmlDataHandler.SetValue>("property", stringList); xmlDataHandlerCacheMock.Verify(c => c.SetValue>("property", stringList, false), Times.Once); - xmlDataWriterMock.Verify(w => w.Write>("property", $"{stringList[0]}, {stringList[1]}, {stringList[2]}", false), Times.Once); + xmlDataWriterMock.Verify(w => w.Write>("property", $"{stringList[0]},{stringList[1]},{stringList[2]}", false), Times.Once); } [Test]