@@ -730,25 +730,115 @@ public async Task TestListBillableLoadBalancers()
730730 [ TestMethod ]
731731 [ TestCategory ( TestCategories . User ) ]
732732 [ TestCategory ( TestCategories . LoadBalancers ) ]
733- public void TestListAccountLevelUsage ( )
733+ public async Task TestListAccountLevelUsage ( )
734734 {
735- Assert . Inconclusive ( "Not yet implemented." ) ;
735+ ILoadBalancerService provider = CreateProvider ( ) ;
736+ using ( CancellationTokenSource cancellationTokenSource = new CancellationTokenSource ( TestTimeout ( TimeSpan . FromSeconds ( 60 ) ) ) )
737+ {
738+ IEnumerable < LoadBalancingProtocol > protocols = await provider . ListProtocolsAsync ( cancellationTokenSource . Token ) ;
739+ LoadBalancingProtocol httpProtocol = protocols . First ( i => i . Name . Equals ( "HTTP" , StringComparison . OrdinalIgnoreCase ) ) ;
740+
741+ string loadBalancerName = CreateRandomLoadBalancerName ( ) ;
742+
743+ LoadBalancerConfiguration configuration = new LoadBalancerConfiguration (
744+ name : loadBalancerName ,
745+ nodes : null ,
746+ protocol : httpProtocol ,
747+ virtualAddresses : new [ ] { new LoadBalancerVirtualAddress ( LoadBalancerVirtualAddressType . Public ) } ,
748+ algorithm : LoadBalancingAlgorithm . RoundRobin ) ;
749+ LoadBalancer tempLoadBalancer = await provider . CreateLoadBalancerAsync ( configuration , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
750+
751+ IEnumerable < LoadBalancerUsage > usage = await provider . ListAccountLevelUsageAsync ( DateTimeOffset . Now . Date . AddDays ( - 60 ) , DateTimeOffset . Now . Date . AddDays ( 1 ) , cancellationTokenSource . Token ) ;
752+ Assert . IsNotNull ( usage ) ;
753+ LoadBalancerUsage [ ] usageRecords = usage . ToArray ( ) ;
754+ if ( usageRecords . Length == 0 )
755+ Assert . Inconclusive ( "No account level usage was reported." ) ;
756+
757+ Console . WriteLine ( "Account Level Usage ({0} records)" , usageRecords . Length ) ;
758+ foreach ( LoadBalancerUsage usageRecord in usageRecords )
759+ Console . WriteLine ( JsonConvert . SerializeObject ( usageRecord , Formatting . Indented ) ) ;
760+
761+ /* Cleanup
762+ */
763+
764+ await provider . RemoveLoadBalancerAsync ( tempLoadBalancer . Id , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
765+ }
736766 }
737767
738768 [ TestMethod ]
739769 [ TestCategory ( TestCategories . User ) ]
740770 [ TestCategory ( TestCategories . LoadBalancers ) ]
741- public void TestListHistoricalUsage ( )
771+ public async Task TestListHistoricalUsage ( )
742772 {
743- Assert . Inconclusive ( "Not yet implemented." ) ;
773+ ILoadBalancerService provider = CreateProvider ( ) ;
774+ using ( CancellationTokenSource cancellationTokenSource = new CancellationTokenSource ( TestTimeout ( TimeSpan . FromSeconds ( 60 ) ) ) )
775+ {
776+ IEnumerable < LoadBalancingProtocol > protocols = await provider . ListProtocolsAsync ( cancellationTokenSource . Token ) ;
777+ LoadBalancingProtocol httpProtocol = protocols . First ( i => i . Name . Equals ( "HTTP" , StringComparison . OrdinalIgnoreCase ) ) ;
778+
779+ string loadBalancerName = CreateRandomLoadBalancerName ( ) ;
780+
781+ LoadBalancerConfiguration configuration = new LoadBalancerConfiguration (
782+ name : loadBalancerName ,
783+ nodes : null ,
784+ protocol : httpProtocol ,
785+ virtualAddresses : new [ ] { new LoadBalancerVirtualAddress ( LoadBalancerVirtualAddressType . Public ) } ,
786+ algorithm : LoadBalancingAlgorithm . RoundRobin ) ;
787+ LoadBalancer tempLoadBalancer = await provider . CreateLoadBalancerAsync ( configuration , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
788+
789+ IEnumerable < LoadBalancerUsage > usage = await provider . ListHistoricalUsageAsync ( tempLoadBalancer . Id , DateTimeOffset . Now . Date . AddDays ( - 60 ) , DateTimeOffset . Now . Date . AddDays ( 1 ) , cancellationTokenSource . Token ) ;
790+ Assert . IsNotNull ( usage ) ;
791+ LoadBalancerUsage [ ] usageRecords = usage . ToArray ( ) ;
792+ if ( usageRecords . Length == 0 )
793+ Assert . Inconclusive ( "No historical usage was reported for load balancer: {0}" , tempLoadBalancer . Id ) ;
794+
795+ Console . WriteLine ( "Historical Load Balancer Usage ({0} records)" , usageRecords . Length ) ;
796+ foreach ( LoadBalancerUsage usageRecord in usageRecords )
797+ Console . WriteLine ( JsonConvert . SerializeObject ( usageRecord , Formatting . Indented ) ) ;
798+
799+ /* Cleanup
800+ */
801+
802+ await provider . RemoveLoadBalancerAsync ( tempLoadBalancer . Id , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
803+ }
744804 }
745805
746806 [ TestMethod ]
747807 [ TestCategory ( TestCategories . User ) ]
748808 [ TestCategory ( TestCategories . LoadBalancers ) ]
749- public void TestListCurrentUsage ( )
809+ public async Task TestListCurrentUsage ( )
750810 {
751- Assert . Inconclusive ( "Not yet implemented." ) ;
811+ ILoadBalancerService provider = CreateProvider ( ) ;
812+ using ( CancellationTokenSource cancellationTokenSource = new CancellationTokenSource ( TestTimeout ( TimeSpan . FromSeconds ( 60 ) ) ) )
813+ {
814+ IEnumerable < LoadBalancingProtocol > protocols = await provider . ListProtocolsAsync ( cancellationTokenSource . Token ) ;
815+ LoadBalancingProtocol httpProtocol = protocols . First ( i => i . Name . Equals ( "HTTP" , StringComparison . OrdinalIgnoreCase ) ) ;
816+
817+ string loadBalancerName = CreateRandomLoadBalancerName ( ) ;
818+
819+ LoadBalancerConfiguration configuration = new LoadBalancerConfiguration (
820+ name : loadBalancerName ,
821+ nodes : null ,
822+ protocol : httpProtocol ,
823+ virtualAddresses : new [ ] { new LoadBalancerVirtualAddress ( LoadBalancerVirtualAddressType . Public ) } ,
824+ algorithm : LoadBalancingAlgorithm . RoundRobin ) ;
825+ LoadBalancer tempLoadBalancer = await provider . CreateLoadBalancerAsync ( configuration , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
826+
827+ IEnumerable < LoadBalancerUsage > usage = await provider . ListCurrentUsageAsync ( tempLoadBalancer . Id , cancellationTokenSource . Token ) ;
828+ Assert . IsNotNull ( usage ) ;
829+ LoadBalancerUsage [ ] usageRecords = usage . ToArray ( ) ;
830+ if ( usageRecords . Length == 0 )
831+ Assert . Inconclusive ( "No current usage was reported for load balancer: {0}" , tempLoadBalancer . Id ) ;
832+
833+ Console . WriteLine ( "Current Load Balancer Usage ({0} records)" , usageRecords . Length ) ;
834+ foreach ( LoadBalancerUsage usageRecord in usageRecords )
835+ Console . WriteLine ( JsonConvert . SerializeObject ( usageRecord , Formatting . Indented ) ) ;
836+
837+ /* Cleanup
838+ */
839+
840+ await provider . RemoveLoadBalancerAsync ( tempLoadBalancer . Id , AsyncCompletionOption . RequestCompleted , cancellationTokenSource . Token , null ) ;
841+ }
752842 }
753843
754844 [ TestMethod ]
0 commit comments