public void when_account_registered_then_account_settings_populated() { var accountId = Guid.NewGuid(); var accountRegistered = new AccountRegistered { SourceId = accountId, Name = "Bob", Email = "*****@*****.**", Country = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("CA")).CountryISOCode, Phone = "555.555.2525", Password = new byte[] { 1 } }; Sut.Handle(accountRegistered); using (var context = new BookingDbContext(DbName)) { var dto = context.Find <AccountDetail>(accountId); Assert.NotNull(dto); Assert.AreEqual(dto.Settings.Name, dto.Name); Assert.AreEqual(CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("CA")).CountryISOCode.Code, dto.Settings.Country.Code); Assert.AreEqual(accountRegistered.Phone, dto.Settings.Phone); var config = new TestServerSettings(); Assert.IsNull(dto.Settings.ChargeTypeId); Assert.AreEqual(dto.Settings.Passengers, config.ServerData.DefaultBookingSettings.NbPassenger); Assert.IsNull(dto.Settings.VehicleTypeId); Assert.IsNull(dto.Settings.ProviderId); } }
public Account(AccountId userId, string email) { var evnt = new AccountRegistered(userId, email); state = new AccountState(); Apply(evnt); }
public void Handle(AccountRegistered @event) { Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName); _eventBus.SendCommand(new Login { UserName = "******", Password = "******" }); }
public async Task <RegistrationResult> Register(string username, string password) { var result = await Post.To("/_matrix/client/r0/register") .Using(RestClient) .AddBody(new RegistrationRequest { Username = username, Password = password, AuthenticationData = new AuthenticationData { Type = "m.login.dummy" }, InhibitLogin = true, DeviceId = null, InitialDeviceDisplayName = null }) .On(400, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res))) .On(401, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res))) .On(403, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res))) .On(429, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res))) .WhenSucceeded(new Action <RegistrationResult>(r => { AccountRegistered?.Invoke(this, new RegistrationEventArgs(MxId.Parse(r.UserId))); })) .Execute <RegistrationResult>(); return(result); }
/// <summary> /// Execute a command asynchronously. /// </summary> /// <param name="command">Command to execute.</param> /// <returns> /// Task which will be completed once the command has been executed. /// </returns> public async Task HandleAsync(IMessageContext context, RegisterAccount command) { if (command == null) { throw new ArgumentNullException("command"); } if (!string.IsNullOrEmpty(command.UserName) && await _repository.IsUserNameTakenAsync(command.UserName)) { _logger.Warn("UserName is taken: " + command.UserName); await SendAccountInfo(context, command.UserName); return; } var account = command.AccountId > 0 ? new Account(command.AccountId, command.UserName, command.Password) : new Account(command.UserName, command.Password); account.SetVerifiedEmail(command.Email); if (command.ActivateDirectly) { _logger.Debug("Activating directly"); account.Activate(); } var accountCount = await _repository.CountAsync(); if (accountCount == 0) { account.IsSysAdmin = true; } await _repository.CreateAsync(account); // accounts can be activated directly. // should not send activation email then. if (account.AccountState == AccountState.VerificationRequired) { await SendVerificationEmail(context, account); } var evt = new AccountRegistered(account.Id, account.UserName) { IsSysAdmin = account.IsSysAdmin }; await context.SendAsync(evt); if (command.ActivateDirectly) { var evt1 = new AccountActivated(account.Id, account.UserName) { EmailAddress = account.Email }; await context.SendAsync(evt1); } }
private void Apply(AccountRegistered @event) { Id = @event.Id; Created = @event.OccurredAt; CreatedBy = @event.UserId; LastModified = @event.OccurredAt; LastModifiedBy = @event.UserId; LastModifiedVersion = CalculateLastModifiedVersion(); }
public Account(AccountId userId, string email) { if (string.IsNullOrEmpty(email)) { throw new ArgumentException(nameof(email)); } var evnt = new AccountRegistered(userId, email); state = new AccountState(); Apply(evnt); }
public void Handle(AccountRegistered @event) { // Check if exists promotion triggered on account creation var accountCreatedPromotion = _promotionDao.GetAllCurrentlyActive(PromotionTriggerTypes.AccountCreated).FirstOrDefault(); if (accountCreatedPromotion != null) { _commandBus.Send(new AddUserToPromotionWhiteList { AccountIds = new[] { @event.SourceId }, PromoId = accountCreatedPromotion.Id }); } }
public async Task HandleAsync(IMessageContext context, RegisterSimple command) { var pos = command.EmailAddress.IndexOf('@'); if (pos == -1) { _logger.Warn("Invalid email address: " + command.EmailAddress); throw new InvalidOperationException("Invalid email address"); } var user = _repository.FindByEmailAsync(command.EmailAddress); if (user != null) { _logger.Warn("Email already taken, sending reset password: "******"Failed to generate user name for " + command.EmailAddress); return; } //var id = _idGeneratorClient.GetNextId(Account.SEQUENCE); var password = Guid.NewGuid().ToString("N").Substring(0, 10); var account = new Account(userName, password); account.SetVerifiedEmail(command.EmailAddress); await _repository.CreateAsync(account); await SendAccountEmail(context, account, password); var evt = new AccountRegistered(account.Id, account.UserName); await context.SendAsync(evt); }
public void when_account_registered_with_null_country_code() { var accountId = Guid.NewGuid(); var accountRegistered = new AccountRegistered { SourceId = accountId, Name = "Bob", Email = "*****@*****.**", Country = null, Phone = "555.555.2525", Password = new byte[] { 1 } }; Sut.Handle(accountRegistered); using (var context = new BookingDbContext(DbName)) { var dto = context.Find <AccountDetail>(accountId); Assert.AreEqual(CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("US")).CountryISOCode.Code, dto.Settings.Country.Code); } }
/// <summary> /// Execute a command asynchronously. /// </summary> /// <param name="command">Command to execute.</param> /// <returns> /// Task which will be completed once the command has been executed. /// </returns> public async Task ExecuteAsync(RegisterAccount command) { if (command == null) { throw new ArgumentNullException("command"); } if (await _repository.IsUserNameTakenAsync(command.UserName)) { await SendAccountInfo(command.UserName); return; } var account = new Account(command.UserName, command.Password); account.SetVerifiedEmail(command.Email); await _repository.CreateAsync(account); await SendVerificationEmail(account); var evt = new AccountRegistered(account.Id, account.UserName); await _eventBus.PublishAsync(evt); }
#pragma warning disable IDE0051 private void On(AccountRegistered @event) { Dict.Add(@event.ID, new AccountEntry(@event.ID, @event.Username, @event.Password, @event.Timestamp)); }
public void Handle(AccountRegistered @event) { Console.Write("subscriber2: {0} has registered.", @event.UserName); throw new DomainException(ErrorCode.UnknownError, "test fail handled event!"); }
public void Handle(AccountRegistered @event) { Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName); // _eventBus.SendCommand(new Login {UserName = @event.UserName, Password = @event.Password}); }
private void Apply(AccountRegistered @event) { _accounts.Add(@event.AccountId); LastModified = @event.OccurredAt; LastModifiedBy = @event.UserId; }
private void Handle(AccountRegistered @event) { _name = @event.Name; }
private void OnAccountRegistered(AccountRegistered @event) { _confirmationToken = @event.ConfirmationToken; }
public void When(AccountRegistered e) { Id = e.Id; Email = e.Email; }
public void Handle(AccountRegistered @event) { Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName); }