1616
1717namespace Microsoft . Extensions . Diagnostics . ResourceMonitoring . Test ;
1818
19- [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
2019public sealed class ResourceMonitoringExtensionsTests
2120{
21+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
2222 [ ConditionalFact ]
2323 public void Throw_Null_When_Registration_Ingredients_Null ( )
2424 {
@@ -30,6 +30,7 @@ public void Throw_Null_When_Registration_Ingredients_Null()
3030 Assert . Throws < ArgumentNullException > ( ( ) => services . AddResourceMonitoring ( ( b ) => b . ConfigureMonitor ( ( Action < ResourceMonitoringOptions > ) null ! ) ) ) ;
3131 }
3232
33+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
3334 [ ConditionalFact ]
3435 public void AddsResourceMonitoringService_ToServicesCollection ( )
3536 {
@@ -50,6 +51,7 @@ public void AddsResourceMonitoringService_ToServicesCollection()
5051 Assert . IsAssignableFrom < IResourceMonitor > ( trackerService ) ;
5152 }
5253
54+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
5355 [ ConditionalFact ]
5456 public void AddsResourceMonitoringService_ToServicesCollection_NoArgs ( )
5557 {
@@ -66,6 +68,7 @@ public void AddsResourceMonitoringService_ToServicesCollection_NoArgs()
6668 Assert . IsAssignableFrom < IResourceMonitor > ( trackerService ) ;
6769 }
6870
71+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
6972 [ ConditionalFact ]
7073 public void AddsResourceMonitoringService_AsHostedService ( )
7174 {
@@ -87,6 +90,7 @@ public void AddsResourceMonitoringService_AsHostedService()
8790 Assert . IsAssignableFrom < IResourceMonitor > ( trackerService ) ;
8891 }
8992
93+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
9094 [ ConditionalFact ]
9195 public void ConfigureResourceUtilization_InitializeTrackerProperly ( )
9296 {
@@ -113,6 +117,7 @@ public void ConfigureResourceUtilization_InitializeTrackerProperly()
113117 Assert . NotNull ( publisher ) ;
114118 }
115119
120+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
116121 [ ConditionalFact ]
117122 public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsProperly ( )
118123 {
@@ -141,6 +146,7 @@ public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsPr
141146 Assert . Equal ( TimeSpan . FromSeconds ( CalculationPeriodValue ) , options ! . Value . PublishingWindow ) ;
142147 }
143148
149+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
144150 [ ConditionalFact ]
145151 public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOptionsProperly ( )
146152 {
@@ -182,6 +188,7 @@ public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOpt
182188 Assert . Equal ( TimeSpan . FromSeconds ( CalculationPeriod ) , options ! . Value . PublishingWindow ) ;
183189 }
184190
191+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
185192 [ ConditionalFact ]
186193 public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_ResourceUtilizationService_To_DI_Container ( )
187194 {
@@ -204,4 +211,46 @@ public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_Resour
204211 Assert . IsAssignableFrom < ResourceMonitorService > ( background ) ;
205212 Assert . Same ( tracker as ResourceMonitorService , background as ResourceMonitorService ) ;
206213 }
214+
215+ [ OSSkipCondition ( OperatingSystems . Linux | OperatingSystems . Windows , SkipReason = "For MacOs only." ) ]
216+ [ ConditionalFact ]
217+ public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection ( )
218+ {
219+ var services = new ServiceCollection ( ) ;
220+
221+ // Act
222+ IServiceCollection result = services . AddResourceMonitoring ( ) ;
223+
224+ // Assert
225+ Assert . Same ( services , result ) ;
226+ Assert . DoesNotContain ( services , s => s . ServiceType == typeof ( ISnapshotProvider ) ) ;
227+ }
228+
229+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
230+ [ ConditionalFact ]
231+ public void AddResourceMonitoring_AddsISnapshotProvider ( )
232+ {
233+ var services = new ServiceCollection ( ) ;
234+
235+ // Act
236+ IServiceCollection result = services . AddResourceMonitoring ( ) ;
237+
238+ // Assert
239+ Assert . Same ( services , result ) ;
240+ Assert . Contains ( services , s => s . ServiceType == typeof ( ISnapshotProvider ) ) ;
241+ }
242+
243+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "Not supported on MacOs." ) ]
244+ [ ConditionalFact ]
245+ public void AddResourceMonitoringInternal_CallsConfigureDelegate ( )
246+ {
247+ var services = new ServiceCollection ( ) ;
248+ bool delegateCalled = false ;
249+
250+ // Act
251+ services . AddResourceMonitoring ( _ => delegateCalled = true ) ;
252+
253+ // Assert
254+ Assert . True ( delegateCalled ) ;
255+ }
207256}
0 commit comments