Esempio n. 1
0
 public void Handle(ICommandContext context, RegisterNewAccountCommand command)
 {
     _lockService.ExecuteInLock(typeof(Account).Name, () =>
     {
         _registerAccountService.RegisterAccount(command.AggregateRootId, command.Name);
         context.Add(new Account(command.AggregateRootId, command.Name, command.Password));
     });
 }
Esempio n. 2
0
 public Task HandleAsync(ICommandContext context, RegisterNewAccountCommand command)
 {
     return(Task.Factory.StartNew(() => _lockService.ExecuteInLock(typeof(Account).Name, () =>
     {
         var account = new Account(command.AggregateRootId, command.Name, command.Password);
         _registerAccountService.RegisterAccount(account);
         context.Add(account);
     })));
 }
Esempio n. 3
0
        public async Task HandleAsync(ICommandContext context, RegisterNewAccountCommand command)
        {
            var account = new Account(command.AggregateRootId, command.Name, command.Password);
            await _lockService.ExecuteInLock(typeof(Account).Name, () =>
            {
                return(_registerAccountService.RegisterAccount(account));
            });

            context.Add(account);
        }
        public async Task Should_UseSendEmailService_ToSend_AccountConfimationEmail()
        {
            var options = SqliteInMemory.CreateOptions <ApplicationDbContext>();

            using (var context = new ApplicationDbContext(options))
            {
                // Arrange
                context.Database.EnsureCreated();

                var accountToCreate = new RegisterDto
                {
                    FirstName = "Test",
                    LastName  = "User",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var confirmationEmail     = "Test Confirmation Email";
                var userId                = "0001";
                var emailConfirmationCode = "1234";


                var user = _fixture.UserMock;
                user.Setup(m => m.Id).Returns(userId);
                user.Setup(m => m.Email).Returns(accountToCreate.Email);

                var store           = new Mock <IUserStore <ApplicationUser> >();
                var userManagerMock = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);
                userManagerMock.Setup(m => m.CreateAsync(user.Object, "Password123!")).Returns(Task.FromResult(IdentityResult.Success));
                userManagerMock.Setup(m => m.GenerateEmailConfirmationTokenAsync(user.Object))
                .Returns(Task.FromResult(emailConfirmationCode));

                var errorFactoryMock = _fixture.ErrorFactoryMock;

                var mapperMock = _fixture.MapperMock;
                mapperMock.Setup(m => m.Map <RegisterDto, ApplicationUser>(accountToCreate)).Returns(user.Object);

                var sendEmailServiceMock = new Mock <ISendEmailService>();
                sendEmailServiceMock.Setup(m => m.SendAsync(accountToCreate.Email, "Confirm your account", confirmationEmail, accountToCreate.FirstName));
                sendEmailServiceMock.Setup(m => m.Status).Returns(new StatusGenericHandler());

                var confirmationEmailServiceMock = _fixture.ConfirmationEmailServiceMock;
                confirmationEmailServiceMock.Setup(m => m.ConfirmationEmail(accountToCreate.FirstName, userId, emailConfirmationCode)).Returns(confirmationEmail);

                var sut = new RegisterAccountService(userManagerMock.Object, context,
                                                     errorFactoryMock.Object, mapperMock.Object, sendEmailServiceMock.Object,
                                                     confirmationEmailServiceMock.Object);

                // Act
                await sut.RegisterAccount(accountToCreate);

                //Assert
                sendEmailServiceMock.Verify(m => m.SendAsync(accountToCreate.Email, "Confirm your account", confirmationEmail, accountToCreate.FirstName), Times.Once);
            }
        }
        public async Task Should_HaveErrors_When_PasswordNotProvided()
        {
            var options = SqliteInMemory.CreateOptions <ApplicationDbContext>();

            using (var context = new ApplicationDbContext(options))
            {
                // Arrange
                context.Database.EnsureCreated();

                var accountToCreate = new RegisterDto
                {
                    FirstName = "Test",
                    LastName  = "User",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var user            = _fixture.UserMock;
                var store           = new Mock <IUserStore <ApplicationUser> >();
                var userManagerMock = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);
                userManagerMock.Setup(m => m.CreateAsync(user.Object, null)).Returns(Task.FromResult(IdentityResult.Success));

                var errorFactoryMock = _fixture.ErrorFactoryMock;

                var mapperMock = _fixture.MapperMock;
                mapperMock.Setup(m => m.Map <RegisterDto, ApplicationUser>(accountToCreate)).Returns(user.Object);

                var sendEmailServiceMock         = new Mock <ISendEmailService>();
                var confirmationEmailServiceMock = _fixture.ConfirmationEmailServiceMock;

                var sut = new RegisterAccountService(userManagerMock.Object, context,
                                                     errorFactoryMock.Object, mapperMock.Object, sendEmailServiceMock.Object,
                                                     confirmationEmailServiceMock.Object);

                // Act
                await sut.RegisterAccount(accountToCreate);

                //Assert
                sut.Status.HasErrors.ShouldBeTrue();
            }
        }