public void ExecuteReturnsDuplicateWhenDuplicateName(string tName, string tPassword, string tEmail)
        {
            var vHashProvider = new Mock<IHashProvider>();
            var vDocumentStore = GetEmbeddedDatabase;
            var vAccountCommandFactory = new Mock<IAccountCommandFactory>();
            var vSendConfirmationCommand = new Mock<ISendConfirmationCommand>();
            vAccountCommandFactory
                .Setup(t => t.CreateSendConfirmationCommand(It.IsAny<Account>()))
                .Returns(vSendConfirmationCommand.Object);

            var vCreateAccount = new CreateAccount
                                     {
                                         Name = tName,
                                         Password = tPassword,
                                         Email = tEmail
                                     };
            var vRandomProvider = new Mock<IRandomProvider>();

            var vCreateAccountCommand = new CreateAccountCommand(vDocumentStore, vHashProvider.Object,
                                                                 vAccountCommandFactory.Object, vRandomProvider.Object,
                                                                 vCreateAccount);

            vCreateAccountCommand.Execute();
            var vResult = vCreateAccountCommand.Execute();
            Assert.AreEqual(eAccountCreationStatus.DuplicateName, vResult);
        }
        public void Should_Not_GenerateToken_With_Bad_Request()
        {
            var request = new CreateAccountCommand.Request();

            CreateAccountCommand.Response response = null;
            Task.Run(async() =>
            {
                response = await _authenticateCommand.Execute(request);
            }).GetAwaiter().GetResult();

            Assert.IsFalse(_notifications.IsValid());
            Assert.AreEqual(5, _notifications.Notifications.Count);
            Assert.IsTrue(string.IsNullOrEmpty(response.Token));
        }
Ejemplo n.º 3
0
 public async Task ConsumeAsync(UserCreatedEventV1 message, CancellationToken cancellationToken = new CancellationToken())
 {
     await createAccountCommand.Execute(new CreateAccountDto
     {
         Id   = message.Id,
         Name = message.Name
     });
 }
        private TestObjects Setup()
        {
            var vObjects = new TestObjects();
            vObjects.HashProvider = new Mock<IHashProvider>();
            vObjects.HashProvider.Setup(t => t.Hash(cPassword)).Returns(cHash);
            vObjects.HashProvider.Setup(t => t.CheckHash(cPassword, cHash)).Returns(true);

            vObjects.DocumentStore = GetEmbeddedDatabase;

            var vNewAccount = new CreateAccount
                                  {
                                      Name = cName,
                                      Email = cEmail,
                                      Password = cPassword
                                  };
            var vAccountCommandFactory = new Mock<IAccountCommandFactory>();
            var vSendConfirmationCommand = new Mock<ISendConfirmationCommand>();
            vAccountCommandFactory
                .Setup(t => t.CreateSendConfirmationCommand(It.IsAny<Account>()))
                .Returns(vSendConfirmationCommand.Object);


            var vNewAccountCommand = new CreateAccountCommand(
                vObjects.DocumentStore,
                vObjects.HashProvider.Object, vAccountCommandFactory.Object, new CryptoRandomProvider(),
                vNewAccount);
            vNewAccountCommand.Execute();

            var vLogin = new LoginAccount
                             {
                                 Name = cName,
                                 Password = cPassword
                             };
            vObjects.GoodLoginAccountCommand = new LoginAccountCommand(
                vObjects.DocumentStore,
                vObjects.HashProvider.Object,
                vLogin);
            return vObjects;
        }
        public void ExecuteUsesHashProviderForHashWithSalt(string tName, string tPassword, string tEmail)
        {
            var vHashProvider = new Mock<IHashProvider>();
            var vDocumentStore = GetEmbeddedDatabase;
            var vAccountCommandFactory = new Mock<IAccountCommandFactory>();
            var vSendConfirmationCommand = new Mock<ISendConfirmationCommand>();
            vAccountCommandFactory
                .Setup(t => t.CreateSendConfirmationCommand(It.IsAny<Account>()))
                .Returns(vSendConfirmationCommand.Object);

            var vCreateAccount = new CreateAccount
                                     {
                                         Name = tName,
                                         Password = tPassword,
                                         Email = tEmail
                                     };
            var vRandomProvider = new Mock<IRandomProvider>();

            var vCreateAccountCommand = new CreateAccountCommand(vDocumentStore, vHashProvider.Object,
                                                                 vAccountCommandFactory.Object, vRandomProvider.Object,
                                                                 vCreateAccount);

            vCreateAccountCommand.Execute();
            vHashProvider.Verify(t => t.Hash(tPassword));
        }
        public void NewAccountIsAdminWhenMatchesConfigForAdmin(string tName, string tPassword, string tEmail)
        {
            var vHashProvider = new Mock<IHashProvider>();
            var vDocumentStore = GetEmbeddedDatabase;
            var vAccountCommandFactory = new Mock<IAccountCommandFactory>();
            var vSendConfirmationCommand = new Mock<ISendConfirmationCommand>();
            vAccountCommandFactory
                .Setup(t => t.CreateSendConfirmationCommand(It.IsAny<Account>()))
                .Returns(vSendConfirmationCommand.Object);

            var vCreateAccount = new CreateAccount
                                     {
                                         Name = tName,
                                         Password = tPassword,
                                         Email = tEmail
                                     };
            var vRandomProvider = new Mock<IRandomProvider>();

            var vCreateAccountCommand = new CreateAccountCommand(vDocumentStore, vHashProvider.Object,
                                                                 vAccountCommandFactory.Object, vRandomProvider.Object,
                                                                 vCreateAccount);
            vCreateAccountCommand.Execute();

            using (var vSession = vDocumentStore.OpenSession())
            {
                var vAccount = vSession.Load<Account>("Accounts/"+tName);

                Assert.IsTrue(vAccount.Roles.Any(t => t == eRoles.Admin));
            }
        }
        private TestObjects Setup()
        {
            var vReturn = new TestObjects
                              {
                                  SignInPersistance = new Mock<ISignInPersistance>(),
                                  DocumentStore = new EmbeddableDocumentStore {RunInMemory = true}
                              };

            vReturn.DocumentStore.Initialize();
            vReturn.DocumentStore.RegisterListener(new RavenDbNoStaleData());
            var vAccountCommandFactory = new Mock<IAccountCommandFactory>();
            var vSendConfirmationCommand = new Mock<ISendConfirmationCommand>();
            vAccountCommandFactory
                .Setup(t => t.CreateSendConfirmationCommand(It.IsAny<Account>()))
                .Returns(vSendConfirmationCommand.Object);

            //Make sure there is an account to get. Since this deals with getting an account.
            var vNewAccount = new CreateAccountCommand(vReturn.DocumentStore, new CustomHashProvider(), vAccountCommandFactory.Object, new CryptoRandomProvider(),
                                                    new CreateAccount
                                                        {
                                                            Email = "*****@*****.**",
                                                            Name = cTestName,
                                                            Password = "******"
                                                        });
            vNewAccount.Execute();

            vReturn.Query = new CheckLoginQuery(vReturn.SignInPersistance.Object, vReturn.DocumentStore);
            return vReturn;
        }