From baad53d25f311af5dbad46941e553b7ec841d2fa Mon Sep 17 00:00:00 2001 From: likp Date: Tue, 14 Jan 2025 11:14:21 +0100 Subject: [PATCH 1/2] Initializes Contact info array and set the languag dependent attribute --- PCAxis.Core/PaxiOM/ContInfo.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PCAxis.Core/PaxiOM/ContInfo.vb b/PCAxis.Core/PaxiOM/ContInfo.vb index d18bb11..95c8dba 100644 --- a/PCAxis.Core/PaxiOM/ContInfo.vb +++ b/PCAxis.Core/PaxiOM/ContInfo.vb @@ -18,7 +18,7 @@ Namespace PCAxis.Paxiom mContact = New String(0) {} mUnits = New String(0) {} mContact(0) = "" - mContactInfo = New List(Of Contact)() {} + mContactInfo = New List(Of Contact)(0) {} End Sub ''' @@ -81,6 +81,7 @@ Namespace PCAxis.Paxiom Private mCFPrices As String Private mContact() As String + Private mContactInfo() As List(Of Contact) Private mLastUpdated As String Private mRefPeriod As String From 304c42a0c696871f59f5c14ac7f7e99c4dbcd599 Mon Sep 17 00:00:00 2001 From: likp Date: Tue, 14 Jan 2025 11:22:20 +0100 Subject: [PATCH 2/2] Added unit test --- PCAxis.Core.UnitTest/PxFileSerializerTest.vb | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 PCAxis.Core.UnitTest/PxFileSerializerTest.vb diff --git a/PCAxis.Core.UnitTest/PxFileSerializerTest.vb b/PCAxis.Core.UnitTest/PxFileSerializerTest.vb new file mode 100644 index 0000000..34ef6b7 --- /dev/null +++ b/PCAxis.Core.UnitTest/PxFileSerializerTest.vb @@ -0,0 +1,67 @@ +Imports System.IO +Imports System.Text +Imports Microsoft.VisualStudio.TestTools.UnitTesting +Imports PCAxis.Paxiom + + + +Public Class PxFileSerializerTest + + Sub ShouldBeAbleToSerialize() + + 'Arrange + Dim pxModel As New PXModel() + + Dim timeVar As New Variable("Period", PlacementType.Heading) + timeVar.IsTime = True + timeVar.Values.Add(New Value("2018M01")) + + pxModel.Meta.AddVariable(timeVar) + + Dim regionVar As New Variable("Region", PlacementType.Stub) + regionVar.IsTime = False + regionVar.Values.Add(New Value("A")) + regionVar.Values.Add(New Value("B")) + + pxModel.Meta.AddVariable(regionVar) + + pxModel.Meta.AxisVersion = "2018" + pxModel.Meta.Language = "en" + pxModel.Meta.SubjectArea = "TST" + pxModel.Meta.SubjectCode = "TST" + pxModel.Meta.Matrix = "TST01" + pxModel.Meta.Title = "Test data" + pxModel.Meta.Source = "PxTools" + pxModel.Meta.Contents = "Test data" + pxModel.Meta.Decimals = 0 + pxModel.Meta.Description = "Test file" + pxModel.Meta.DescriptionDefault = False + + Dim contentInfo As New ContInfo() + contentInfo.Units = "Amount" + pxModel.Meta.ContentInfo = contentInfo + pxModel.IsComplete = True + + pxModel.Data.SetMatrixSize(1, 1) + + pxModel.Data.WriteElement(0, 100) + + 'Act + 'Get a UTF-32 encoding by name. + Dim serializer As PXFileSerializer = New PXFileSerializer() + + serializer.Serialize(pxModel, Stream.Null) + + 'Assert + Try + serializer.Serialize(pxModel, Stream.Null) + 'Assert + 'If no exception is thrown, the test passes. + Assert.IsTrue(True) + Catch ex As Exception + 'If an exception is thrown, the test fails. + Assert.Fail("Serialization threw an exception: " & ex.Message) + End Try + + End Sub +End Class