You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GrpcAgentRuntimeTests.cs 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // GrpcAgentRuntimeTests.cs
  3. using FluentAssertions;
  4. using Microsoft.AutoGen.Contracts;
  5. using Microsoft.Extensions.Logging;
  6. using Xunit;
  7. namespace Microsoft.AutoGen.Core.Grpc.Tests;
  8. [Trait("Category", "GRPC")]
  9. public class GrpcAgentRuntimeTests : TestBase
  10. {
  11. [Fact]
  12. public async Task GatewayShouldNotReceiveRegistrationsUntilRuntimeStart()
  13. {
  14. var fixture = new GrpcAgentRuntimeFixture();
  15. var runtime = (GrpcAgentRuntime)await fixture.StartAsync(startRuntime: false, registerDefaultAgent: false);
  16. Logger<BaseAgent> logger = new(new LoggerFactory());
  17. await runtime.RegisterAgentFactoryAsync("MyAgent", async (id, runtime) =>
  18. {
  19. return await ValueTask.FromResult(new SubscribedProtobufAgent(id, runtime, logger));
  20. });
  21. await runtime.RegisterImplicitAgentSubscriptionsAsync<SubscribedProtobufAgent>("MyAgent");
  22. fixture.GrpcRequestCollector.RegisterAgentTypeRequests.Should().BeEmpty();
  23. fixture.GrpcRequestCollector.AddSubscriptionRequests.Should().BeEmpty();
  24. await fixture.AgentsApp!.StartAsync().ConfigureAwait(true);
  25. fixture.GrpcRequestCollector.RegisterAgentTypeRequests.Should().NotBeEmpty();
  26. fixture.GrpcRequestCollector.RegisterAgentTypeRequests.Single().Type.Should().Be("MyAgent");
  27. fixture.GrpcRequestCollector.AddSubscriptionRequests.Should().NotBeEmpty();
  28. fixture.GrpcRequestCollector.Clear();
  29. await runtime.RegisterAgentFactoryAsync("MyAgent2", async (id, runtime) =>
  30. {
  31. return await ValueTask.FromResult(new TestProtobufAgent(id, runtime, logger));
  32. });
  33. fixture.GrpcRequestCollector.RegisterAgentTypeRequests.Should().NotBeEmpty();
  34. fixture.GrpcRequestCollector.RegisterAgentTypeRequests.Single().Type.Should().Be("MyAgent2");
  35. fixture.GrpcRequestCollector.AddSubscriptionRequests.Should().BeEmpty();
  36. fixture.Dispose();
  37. }
  38. }