Esempio n. 1
0
        async Task IEventSink.PersistAsync(Event evt)
        {
            await(_innerSink?.PersistAsync(evt) ?? Task.CompletedTask);

            var eventType           = evt.GetType();
            var eventTypeEvaluators = _evaluators.GetOrAdd(eventType, x => new ConcurrentDictionary <Guid, IEventOccurredConditionEvaluator>());

            foreach (var evaluator in eventTypeEvaluators.Values)
            {
                await evaluator.CheckEventAsync(evt);
            }
        }
        /// <summary>
        /// Raises the specified event.
        /// </summary>
        /// <param name="evt">The event.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">evt</exception>
        public async Task RaiseAsync(Event evt)
        {
            if (evt == null)
            {
                throw new ArgumentNullException(nameof(evt));
            }

            if (CanRaiseEvent(evt))
            {
                await PrepareEventAsync(evt);

                await Sink.PersistAsync(evt);
            }
        }
Esempio n. 3
0
        public async Task PersistAsync_Should_Update_Account_Login_On_TokenIssuedSuccessEvent()
        {
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail("*****@*****.**")
                          .SetConfirmed(true)
                          .SetPasswordHash(string.Empty)
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .Build();
            var getAccountResult = GetResult <Account> .Ok(account);

            var claims = new[] {
                new Claim(JwtClaimTypes.Subject, account.Id.ToString())
            };
            var claimsIdentity    = new ClaimsIdentity(claims);
            var authorizeResponse = new AuthorizeResponse
            {
                Request = new ValidatedAuthorizeRequest
                {
                    Subject  = new ClaimsPrincipal(claimsIdentity),
                    ClientId = "clientId",
                    Client   = new Client
                    {
                        ClientName = "ClientName"
                    },
                    RedirectUri = "RedirectUri",
                    GrantType   = "GrantType"
                }
            };
            var evt = new TokenIssuedSuccessEvent(authorizeResponse);

            _accountGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getAccountResult);
            _communicationBusMock
            .Setup(x => x.DispatchDomainEventsAsync(It.IsAny <Account>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            _accountRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <Account>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            Func <Task> result = async() => await _service.PersistAsync(evt);

            await result.Should().NotThrowAsync <Exception>();

            _communicationBusMock.Verify(
                x => x.DispatchDomainEventsAsync(It.IsAny <Account>(), It.IsAny <CancellationToken>()), Times.Exactly(1));
            _accountRepositoryMock.Verify(x => x.UpdateAsync(It.Is <Account>(a => a.LastLogin.HasValue)));
        }
Esempio n. 4
0
 public Task PersistAsync(Event evt)
 {
     _innerEventSink.PersistAsync(evt);
     _documentDbService.AddDocument(Guid.NewGuid().ToString(), evt);
     return(Task.CompletedTask);
 }