public async Task ReceiveMessageTwiceShouldGetContactFromContactsTwiceWhenCaseExpires()
        {
            // Arrange
            CacheLocally = true;
            var message  = Dummy.CreateMessage();
            var identity = message.From.ToIdentity();
            var contact  = Dummy.CreateContact();

            contact.Identity = identity;
            ContactExtension
            .GetAsync(identity, Arg.Any <CancellationToken>())
            .Returns(contact);

            var target = GetTarget();

            // Act
            await target.ReceiveAsync(message, CancellationToken);

            await Task.Delay(CacheExpiration + CacheExpiration);

            await target.ReceiveAsync(message, CancellationToken);

            // Assert

            ContactExtension.Received(2).GetAsync(identity, CancellationToken);
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public async Task GetNameTwiceWhenContactExistsShouldUseCachedValue()
        {
            // Arrange
            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>());
        }