public void TurnContextStateDisposeNonConnectorClient() { var disposableObject1 = new TrackDisposed(); var disposableObject2 = new TrackDisposed(); var disposableObject3 = new TrackDisposed(); Assert.IsFalse(disposableObject1.Disposed); Assert.IsTrue(disposableObject1 is IDisposable); var connector = new ConnectorClientThrowExceptionOnDispose(); Assert.IsTrue(connector is IDisposable); Assert.IsTrue(connector is IConnectorClient); var stateCollection = new TurnContextStateCollection(); stateCollection.Add("disposable1", disposableObject1); stateCollection.Add("disposable2", disposableObject2); stateCollection.Add("disposable3", disposableObject3); stateCollection.Add("connector", connector); stateCollection.Dispose(); Assert.IsTrue(disposableObject1.Disposed); Assert.IsTrue(disposableObject2.Disposed); Assert.IsTrue(disposableObject3.Disposed); }
public void TurnContextStateCollection_AddRemove() { var ts = new TurnContextStateCollection(); var test = new object(); var test2 = new object(); ts.Add("test", test); ts.Add(test2); Assert.AreEqual(test, ts.Get <object>("test")); Assert.AreEqual(test2, ts.Get <object>()); Assert.AreNotEqual(test, ts.Get <object>()); }
public void TurnContextStateCollection_AddNullKey() { var ts = new TurnContextStateCollection(); ts.Add(null, new object()); Assert.Fail("Should Fail due to null key"); }
public async Task CreateOAuthClientWithDifferentEndpoints() { var mockAppCredentials = new MockAppCredentials(); var mockCredentialProvider = new Mock <ICredentialProvider>(); var adapter = new MockAdapter(mockCredentialProvider.Object, () => new TokenResponse()); var claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AudienceClaim, "AppId")); var turnStateCollection = new TurnContextStateCollection(); turnStateCollection.Add(BotAdapter.BotIdentityKey, claimsIdentity); var turnContext = new Mock <ITurnContext>(); turnContext.SetupGet(x => x.Activity).Returns(new Activity()); turnContext.SetupGet(x => x.TurnState).Returns(turnStateCollection); var oauthEndpoint1 = "https://foo.com"; OAuthClientConfig.OAuthEndpoint = oauthEndpoint1; var client = await adapter.CallCreateOAuthApiClientAsync(turnContext.Object, mockAppCredentials); Assert.NotNull(client); Assert.Equal(new Uri(oauthEndpoint1), client.BaseUri); Assert.Same(mockAppCredentials, client.Credentials); // client2 should come from the cache so it should be the same object var client2 = await adapter.CallCreateOAuthApiClientAsync(turnContext.Object, mockAppCredentials); Assert.NotNull(client2); Assert.Same(client, client2); Assert.Equal(new Uri(oauthEndpoint1), client2.BaseUri); Assert.Same(mockAppCredentials, client2.Credentials); // Changing the OAuthEndpoint should result in a different OAuthClient var oauthEndpoint2 = "https://bar.com"; OAuthClientConfig.OAuthEndpoint = oauthEndpoint2; var client3 = await adapter.CallCreateOAuthApiClientAsync(turnContext.Object, mockAppCredentials); Assert.NotNull(client3); Assert.NotSame(client3, client); Assert.Equal(new Uri(oauthEndpoint2), client3.BaseUri); Assert.Same(mockAppCredentials, client3.Credentials); }
public void TurnContextStateNoDispose() { // Verify any ConnectorClient in TurnContextCollection doesn't get disposed. // - Adapter caches ConnectorClient. // - Adapter lifetime is singleton. // - ConnectorClient implements IDisposable. // - ConnectorClient added in turnContet.TurnCollection. // - TurnContextCollection disposes elements after each turn. var connector = new ConnectorClientThrowExceptionOnDispose(); Assert.IsTrue(connector is IDisposable); Assert.IsTrue(connector is IConnectorClient); var stateCollection = new TurnContextStateCollection(); stateCollection.Add("connector", connector); stateCollection.Dispose(); }
public void TurnContextStateCollection_AddNullKey() { var ts = new TurnContextStateCollection(); Assert.Throws <ArgumentNullException>(() => ts.Add(null, new object())); }