private ITenantsOperations GetTenantMock(List <TenantIdDescription> tenants) { var tenantMock = new Mock <ITenantsOperations>(); tenantMock.Setup(t => t.ListWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns( (Dictionary <string, List <string> > ch, CancellationToken token) => { if (TenantListQueueVerLatest != null && TenantListQueueVerLatest.Any()) { return(ListTenantQueueDequeueVerLatest()); } var mockPage = new MockPage <TenantIdDescription>(tenants); AzureOperationResponse <IPage <TenantIdDescription> > r = new AzureOperationResponse <IPage <TenantIdDescription> > { Body = mockPage }; return(Task.FromResult(r)); } ); return(tenantMock.Object); }
public SubscriptionClient GetSubscriptionClientVerLatest() { var tenantMock = new Mock <ITenantsOperations>(); tenantMock.Setup(t => t.ListWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns( (Dictionary <string, List <string> > ch, CancellationToken token) => { if (TenantListQueueVerLatest != null && TenantListQueueVerLatest.Any()) { return(ListTenantQueueDequeueVerLatest()); } var tenants = _tenants.Select((k) => new TenantIdDescription(id: k, tenantId: k)); var mockPage = new MockPage <TenantIdDescription>(tenants.ToList()); AzureOperationResponse <IPage <TenantIdDescription> > r = new AzureOperationResponse <IPage <TenantIdDescription> > { Body = mockPage }; return(Task.FromResult(r)); } ); var subscriptionMock = new Mock <ISubscriptionsOperations>(); subscriptionMock.Setup( s => s.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())).Returns( (string subId, Dictionary <string, List <string> > ch, CancellationToken token) => { if (SubGetQueueVerLatest != null && SubGetQueueVerLatest.Any()) { return(GetSubQueueDequeueVerLatest()); } AzureOperationResponse <Subscription> result = new AzureOperationResponse <Subscription> { RequestId = Guid.NewGuid().ToString() }; if (_subscriptionSet.Contains(subId)) { result.Body = new Subscription( id: subId, subscriptionId: subId, tenantId: null, displayName: GetSubscriptionNameFromId(subId), state: SubscriptionState.Enabled, subscriptionPolicies: null, authorizationSource: null); } return(Task.FromResult(result)); }); subscriptionMock.Setup( (s) => s.ListWithHttpMessagesAsync(null, It.IsAny <CancellationToken>())).Returns( (Dictionary <string, List <string> > ch, CancellationToken token) => { if (SubListQueueVerLatest != null && SubListQueueVerLatest.Any()) { return(ListSubQueueDequeueVerLatest()); } AzureOperationResponse <IPage <Subscription> > result = null; if (_subscriptions.Count > 0) { var subscriptionList = _subscriptions.Dequeue(); result = new AzureOperationResponse <IPage <Subscription> > { RequestId = Guid.NewGuid().ToString(), Body = new MockPage <Subscription>( new List <Subscription>( subscriptionList.Select( sub => new Subscription( id: sub, subscriptionId: sub, tenantId: null, displayName: GetSubscriptionNameFromId(sub), state: SubscriptionState.Enabled, subscriptionPolicies: null, authorizationSource: null))), "LinkToNextPage") }; } return(Task.FromResult(result)); }); subscriptionMock.Setup( (s) => s.ListNextWithHttpMessagesAsync("LinkToNextPage", null, It.IsAny <CancellationToken>())).Returns( (string nextLink, Dictionary <string, List <string> > ch, CancellationToken token) => { AzureOperationResponse <IPage <Subscription> > result = null; if (_subscriptions.Count > 0) { var subscriptionList = _subscriptions.Dequeue(); result = new AzureOperationResponse <IPage <Subscription> > { RequestId = Guid.NewGuid().ToString(), Body = new MockPage <Subscription>( new List <Subscription>( subscriptionList.Select( sub => new Subscription( id: sub, subscriptionId: sub, tenantId: null, displayName: GetSubscriptionNameFromId(sub), state: SubscriptionState.Disabled, subscriptionPolicies: null, authorizationSource: null)))) }; } return(Task.FromResult(result)); }); var client = new Mock <SubscriptionClient>() { CallBase = true }; client.SetupGet(c => c.Subscriptions).Returns(subscriptionMock.Object); client.SetupGet(c => c.Tenants).Returns(tenantMock.Object); return(client.Object); }