public void TurnContextStateCollection_AddNullKey() { var ts = new TurnContextStateCollection(); ts.Add(null, new object()); Assert.Fail("Should Fail due to null key"); }
/// <summary> /// Initializes a new instance of the <see cref="DialogContext"/> class from the turn context. /// </summary> /// <param name="dialogs">The dialog set to create the dialog context for.</param> /// <param name="turnContext">The current turn context.</param> /// <param name="state">The state property from which to retrieve the dialog context.</param> public DialogContext(DialogSet dialogs, ITurnContext turnContext, DialogState state) { Dialogs = dialogs ?? throw new ArgumentNullException(nameof(dialogs)); Context = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); Stack = state.DialogStack; State = new DialogStateManager(this); Services = new TurnContextStateCollection(); ObjectPath.SetPathValue(turnContext.TurnState, TurnPath.Activity, Context.Activity); }
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 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 TurnContextStateCollection_PopPushSetFirst() { var ts = new TurnContextStateCollection(); var test1 = new object(); var test2 = new object(); var test3 = new object(); Assert.IsNull(ts.Pop <object>(), "pop with no pushes is null"); ts.Set(test1); Assert.AreEqual(test1, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(), "test1 should be current"); ts.Push(test2); ts.Push(test3); // test3 should be current object Assert.AreNotEqual(test1, ts.Get <object>(), "test3 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(), "test3 should be current"); Assert.AreEqual(test3, ts.Get <object>(), "test3 should be current"); Assert.AreEqual(test2, ts.Pop <object>(), "pop should return test2"); Assert.AreNotEqual(test1, ts.Get <object>(), "test2 should be current"); Assert.AreEqual(test2, ts.Get <object>(), "test2 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(), "test2 should be current"); Assert.AreEqual(test1, ts.Pop <object>(), "pop should return test1"); Assert.AreEqual(test1, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(), "test1 should be current"); Assert.AreEqual(test1, ts.Pop <object>(), "pop should return test1"); Assert.AreEqual(test1, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(), "test1 should be current"); Assert.AreEqual(test1, ts.Pop <object>(), "pop should return test1"); Assert.AreEqual(test1, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(), "test1 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(), "test1 should be current"); }
public void TurnContextStateCollection_Set() { var ts = new TurnContextStateCollection(); var test = new object(); var test2 = new object(); ts.Set("test", test); ts.Set(test2); Assert.AreEqual(test, ts.Get <object>("test")); Assert.AreEqual(test2, ts.Get <object>()); Assert.AreNotEqual(test, ts.Get <object>()); ts.Set <object>("test", null); Assert.IsNull(ts.Get <object>("test")); Assert.AreEqual(test2, ts.Get <object>()); ts.Set <object>(null); Assert.IsNull(ts.Get <object>()); }
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_PopPushKey() { var ts = new TurnContextStateCollection(); var test1 = new object(); var test2 = new object(); var test3 = new object(); var key = "test"; Assert.IsNull(ts.Pop <object>(key), "pop with no pushes is null"); ts.Push(key, test1); ts.Push(key, test2); ts.Push(key, test3); // test3 should be current object Assert.AreNotEqual(test1, ts.Get <object>(key), "test3 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(key), "test3 should be current"); Assert.AreEqual(test3, ts.Get <object>(key), "test3 should be current"); Assert.AreEqual(test2, ts.Pop <object>(key), "pop should return test2"); Assert.AreNotEqual(test1, ts.Get <object>(key), "test2 should be current"); Assert.AreEqual(test2, ts.Get <object>(key), "test2 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(key), "test2 should be current"); Assert.AreEqual(test1, ts.Pop <object>(key), "pop should return test1"); Assert.AreEqual(test1, ts.Get <object>(key), "test1 should be current"); Assert.AreNotEqual(test2, ts.Get <object>(key), "test1 should be current"); Assert.AreNotEqual(test3, ts.Get <object>(key), "test1 should be current"); Assert.AreEqual(null, ts.Pop <object>(key), "pop should return null"); Assert.IsNull(ts.Get <object>(key), "null should be current"); Assert.AreEqual(null, ts.Pop <object>(key), "pop with nothing should be null"); Assert.IsNull(ts.Get <object>(key), "null should be current"); }
public void TurnContextStateCollection_SetNullKey() { var ts = new TurnContextStateCollection(); Assert.Throws <ArgumentNullException>(() => ts.Set(null, new object())); }