public async Task GetNameTwiceWhenContactExistsShouldUseCachedValue() { // Arrange using (OwnerContext.Create(Application.Identity)) { Configuration.ContactCacheEnabled.Returns(true); Configuration.ContactCacheExpiration.Returns(TimeSpan.FromMinutes(5)); var target = GetTarget(); // Act var actualName = await target.GetVariableAsync("name", Context, CancellationToken); var actualAddress = await target.GetVariableAsync("address", Context, CancellationToken); // Asset actualName.ShouldBe(Contact.Name); actualAddress.ShouldBe(Contact.Address); ContactExtension.Received(1).GetAsync(Arg.Any <Identity>(), Arg.Any <CancellationToken>()); var cachedContact = await OwnerCallerContactMap.GetValueOrDefaultAsync(OwnerCaller.Create(Application.Identity, Contact.Identity)); cachedContact.ShouldNotBeNull(); } }
public ContextBaseTests() { var documentTypeResolver = new DocumentTypeResolver().WithMessagingDocuments(); ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>(); ContactExtension = Substitute.For <IContactExtension>(); TunnelExtension = Substitute.For <ITunnelExtension>(); Logger = Substitute.For <ILogger>(); Configuration = Substitute.For <IConfiguration>(); OwnerCallerContactMap = new OwnerCallerContactMap(); Sender = Substitute.For <ISender>(); Flow = new Flow() { Id = "0", Configuration = new Dictionary <string, string>() }; User = "******"; Application = "*****@*****.**"; Input = new LazyInput( new Message() { From = User.ToNode(), To = Application.ToNode(), Content = new PlainText() { Text = "Hello world!" } }, Flow.BuilderConfiguration, new DocumentSerializer(documentTypeResolver), new EnvelopeSerializer(documentTypeResolver), ArtificialIntelligenceExtension, CancellationToken); Configuration.ContactCacheExpiration.Returns(TimeSpan.FromMinutes(5)); }
public FlowManagerTestsBase() { BucketExtension = Substitute.For <IBucketExtension>(); ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>(); EventTrackExtension = Substitute.For <IEventTrackExtension>(); BroadcastExtension = Substitute.For <IBroadcastExtension>(); ContactExtension = Substitute.For <IContactExtension>(); HelpDeskExtension = Substitute.For <IHelpDeskExtension>(); TunnelExtension = Substitute.For <ITunnelExtension>(); Sender = Substitute.For <ISender>(); StateManager = Substitute.For <IStateManager>(); ContextProvider = Substitute.For <IContextProvider>(); Context = Substitute.For <IContext>(); Logger = new LoggerConfiguration().CreateLogger(); ContextProvider .CreateContext(Arg.Any <Identity>(), Arg.Any <Identity>(), Arg.Any <LazyInput>(), Arg.Any <Flow>()) .Returns(Context); UserIdentity = new Identity("user", "domain"); ApplicationIdentity = new Identity("application", "domain"); Application = new Application() { Identifier = ApplicationIdentity.Name, Domain = ApplicationIdentity.Domain }; Message = new Message() { From = UserIdentity.ToNode(), To = ApplicationIdentity.ToNode() }; Context.UserIdentity.Returns(UserIdentity); Input = new LazyInput( Message, UserIdentity, new BuilderConfiguration(), Substitute.For <IDocumentSerializer>(), Substitute.For <IEnvelopeSerializer>(), ArtificialIntelligenceExtension, CancellationToken); Context.Input.Returns(Input); TraceProcessor = Substitute.For <ITraceProcessor>(); OwnerCallerContactMap = new OwnerCallerContactMap(); UserOwnerResolver = Substitute.For <IUserOwnerResolver>(); UserOwnerResolver .GetUserOwnerIdentitiesAsync(Arg.Any <Message>(), Arg.Any <BuilderConfiguration>(), Arg.Any <CancellationToken>()) .Returns(new UserOwner(UserIdentity, ApplicationIdentity)); }
public ContactVariableProviderTests() { ContactExtension = Substitute.For <IContactExtension>(); Logger = Substitute.For <ILogger>(); Configuration = Substitute.For <IConfiguration>(); Application = Substitute.For <Application>(); OwnerCallerContactMap = new OwnerCallerContactMap(); CacheContactExtensionDecorator = new CacheContactExtensionDecorator(ContactExtension, OwnerCallerContactMap, Logger, Configuration); InputContext = new Dictionary <string, object>(); Context.InputContext.Returns(InputContext); Contact = new Contact() { Identity = "*****@*****.**", Name = "John Doe", Address = "184 Alpha Avenue" }; ContactExtension.GetAsync(Contact.Identity, CancellationToken).Returns(Contact); Context.UserIdentity.Returns(Contact.Identity); Context.OwnerIdentity.Returns(new Identity("application", "domain.com")); Application.Identifier = "application"; Application.Domain = "domain.com"; }