public TenantCmdletMockTests(ITestOutputHelper output) { TestExecutionHelpers.SetUpSessionAndProfile(); XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(); ((MockTokenAuthenticationFactory)AzureSession.Instance.AuthenticationFactory).TokenProvider = (account, environment, tenant) => new MockAccessToken { UserId = "*****@*****.**", LoginType = LoginType.OrgId, AccessToken = "bbb", TenantId = tenant }; commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny <object>(), It.IsAny <bool>())).Callback( (Object o, bool enumerateCollection) => { if (enumerateCollection) { IEnumerable <object> objects = o as IEnumerable <object>; objects?.ForEach(e => OutputPipeline.Add(e)); } else { OutputPipeline.Add(o); } }); cmdlet = new GetAzureRMTenantCommandMock() { CommandRuntime = commandRuntimeMock.Object, }; var sub = new AzureSubscription() { Id = Guid.NewGuid().ToString(), Name = "Test subscription" }; defaultContext = new AzureContext(sub, new AzureAccount() { Id = "*****@*****.**", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], new AzureTenant() { Id = Guid.NewGuid().ToString() }); var profile = new AzureRmProfile(); profile.DefaultContext = defaultContext; cmdlet.profileClient = new RMProfileClient(profile); cmdlet.profileClient.SubscriptionAndTenantClient = mockSubscriptionClient.Object; }
public SilentReAuthByTenantCmdletTest(ITestOutputHelper output) { ResourceManagerProfileProvider.InitializeResourceManagerProfile(); xunitLogger = new XunitTracingInterceptor(output); XunitTracingInterceptor.AddToContext(xunitLogger); commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny <object>(), It.IsAny <bool>())).Callback( (Object o, bool enumerateCollection) => { if (enumerateCollection) { IEnumerable <object> objects = o as IEnumerable <object>; objects?.ForEach(e => OutputPipeline.Add(e)); } else { OutputPipeline.Add(o); } }); commandRuntimeMock.Setup(f => f.WriteDebug(It.IsAny <string>())).Callback((string message) => DebugPipeline.Add(message)); commandRuntimeMock.Setup(f => f.WriteWarning(It.IsAny <string>())).Callback((string message) => WarnPipeline.Add(message)); cmdlet = new GetAzureRMTenantCommandMock() { CommandRuntime = commandRuntimeMock.Object, }; var sub = new AzureSubscription() { Id = Guid.NewGuid().ToString(), Name = "Test subscription" }; defaultContext = new AzureContext(sub, new AzureAccount() { Id = "*****@*****.**", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], new AzureTenant() { Id = Guid.NewGuid().ToString() }); }