1+ using System ;
12using System . Linq ;
23using System . Xml . Linq ;
34
@@ -49,9 +50,9 @@ public void ParseTreatsPlateauMissingSentinelsAsMissingMetrics()
4950
5051 BuildingAttributeContext attributes = BuildingAttributeParser . Parse ( element ) ;
5152
52- Assert . Equal ( BuildingMetricValueKind . Missing , attributes . MeasuredHeightMeters . Kind ) ;
53- Assert . Equal ( BuildingMetricValueKind . Missing , attributes . StoreysAboveGround . Kind ) ;
54- Assert . Equal ( BuildingMetricValueKind . Missing , attributes . StoreysBelowGround . Kind ) ;
53+ Assert . IsType < BuildingMetricValue . MissingMetricValue > ( attributes . MeasuredHeightMeters ) ;
54+ Assert . IsType < BuildingMetricValue . MissingMetricValue > ( attributes . StoreysAboveGround ) ;
55+ Assert . IsType < BuildingMetricValue . MissingMetricValue > ( attributes . StoreysBelowGround ) ;
5556 }
5657
5758 [ Fact ]
@@ -70,12 +71,55 @@ public void ParseRejectsNonMeterHeightButKeepsAreaWithoutMeterRequirement()
7071
7172 BuildingAttributeContext attributes = BuildingAttributeParser . Parse ( element ) ;
7273
73- Assert . Equal ( BuildingMetricValueKind . Invalid , attributes . MeasuredHeightMeters . Kind ) ;
74- Assert . Equal ( "12" , attributes . MeasuredHeightMeters . Raw ) ;
75- Assert . Equal ( BuildingMetricValueKind . Known , attributes . BuildingFootprintArea . Kind ) ;
76- Assert . Equal ( 160.5 , attributes . BuildingFootprintArea . Value ) ;
77- Assert . Equal ( BuildingMetricValueKind . Known , attributes . BuildingHeight . Kind ) ;
78- Assert . Equal ( 9.25 , attributes . BuildingHeight . Value ) ;
74+ BuildingMetricValue . InvalidMetricValue invalidMeasuredHeight =
75+ Assert . IsType < BuildingMetricValue . InvalidMetricValue > ( attributes . MeasuredHeightMeters ) ;
76+ BuildingMetricValue . KnownMetricValue footprintArea =
77+ Assert . IsType < BuildingMetricValue . KnownMetricValue > ( attributes . BuildingFootprintArea ) ;
78+ BuildingMetricValue . KnownMetricValue buildingHeight =
79+ Assert . IsType < BuildingMetricValue . KnownMetricValue > ( attributes . BuildingHeight ) ;
80+ Assert . Equal ( "12" , invalidMeasuredHeight . Raw ) ;
81+ Assert . Equal ( 160.5 , footprintArea . Value ) ;
82+ Assert . Equal ( 9.25 , buildingHeight . Value ) ;
83+ }
84+
85+ [ Fact ]
86+ public void ParsePreservesBlankMetricElementsAsInvalidMetrics ( )
87+ {
88+ XElement element = XElement . Parse (
89+ """
90+ <bldg:Building xmlns:bldg="urn:bldg">
91+ <bldg:measuredHeight uom="m"> </bldg:measuredHeight>
92+ </bldg:Building>
93+ """ ) ;
94+
95+ BuildingAttributeContext attributes = BuildingAttributeParser . Parse ( element ) ;
96+
97+ BuildingMetricValue . InvalidMetricValue invalidMeasuredHeight =
98+ Assert . IsType < BuildingMetricValue . InvalidMetricValue > ( attributes . MeasuredHeightMeters ) ;
99+ Assert . Equal ( string . Empty , invalidMeasuredHeight . Raw ) ;
100+ }
101+
102+ [ Fact ]
103+ public void ParsePreservesNonFiniteMetricTextAsInvalidMetrics ( )
104+ {
105+ XElement element = XElement . Parse (
106+ """
107+ <bldg:Building xmlns:bldg="urn:bldg">
108+ <bldg:measuredHeight uom="m">Infinity</bldg:measuredHeight>
109+ <bldg:BuildingDetailAttribute>
110+ <bldg:buildingHeight uom="m">1e309</bldg:buildingHeight>
111+ </bldg:BuildingDetailAttribute>
112+ </bldg:Building>
113+ """ ) ;
114+
115+ BuildingAttributeContext attributes = BuildingAttributeParser . Parse ( element ) ;
116+
117+ BuildingMetricValue . InvalidMetricValue invalidMeasuredHeight =
118+ Assert . IsType < BuildingMetricValue . InvalidMetricValue > ( attributes . MeasuredHeightMeters ) ;
119+ BuildingMetricValue . InvalidMetricValue invalidBuildingHeight =
120+ Assert . IsType < BuildingMetricValue . InvalidMetricValue > ( attributes . BuildingHeight ) ;
121+ Assert . Equal ( "Infinity" , invalidMeasuredHeight . Raw ) ;
122+ Assert . Equal ( "1e309" , invalidBuildingHeight . Raw ) ;
79123 }
80124
81125 [ Fact ]
@@ -93,4 +137,13 @@ public void ParseDropsBlankDirectCodeValues()
93137
94138 Assert . Equal ( [ "402101" ] , attributes . CityGmlFunctionCodes . ToArray ( ) ) ;
95139 }
140+
141+ [ Fact ]
142+ public void MetricValueFactoriesRejectInvalidPayloadShapes ( )
143+ {
144+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => BuildingMetricValue . Known ( double . NaN ) ) ;
145+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => BuildingMetricValue . Known ( double . PositiveInfinity ) ) ;
146+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => BuildingMetricValue . Known ( - 1.0 ) ) ;
147+ Assert . Throws < ArgumentNullException > ( ( ) => BuildingMetricValue . Invalid ( null ! ) ) ;
148+ }
96149}
0 commit comments