public void Should_Apply_Request_Treatment()
        {
            var request = new CreateAccountCommand.Request()
            {
                Cpf     = "1/11.111.111-11\\",
                Address = "x.y.z",
                Email   = "Email",
                Name    = "Name",
                Phone   = "Phone"
            };

            request.Treatment();
            Assert.AreEqual(request.Cpf, "11111111111");
            request = new CreateAccountCommand.Request()
            {
                Cpf     = "",
                Address = "x.y.z",
                Email   = "Email",
                Name    = "Name",
                Phone   = "Phone"
            };
            request.Treatment();

            Assert.AreEqual(request.Cpf, "");
        }
        public void Should_Return_Existent_Account()
        {
            var request = new CreateAccountCommand.Request()
            {
                Cpf     = "111.111.111-11",
                Address = "x.y.z",
                Email   = "Email",
                Name    = "Name",
                Phone   = "Phone"
            };

            CreateAccountCommand.Response response = null;

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

            Assert.IsFalse(string.IsNullOrEmpty(response.Token));

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

            var keys = _notifications.Notifications.Select(x => x.Key).ToArray();

            Assert.IsTrue(keys.Contains(nameof(request.Cpf)));
            Assert.IsTrue(string.IsNullOrEmpty(response.Token));
        }
        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));
        }
        public void Should_Request_Validating()
        {
            var request = new CreateAccountCommand.Request();

            _authenticateCommand.Validate(request);

            var keys = _notifications.Notifications.Select(x => x.Key).ToArray();

            Assert.AreEqual(5, _notifications.Notifications.Count);
            Assert.IsTrue(keys.Contains(nameof(request.Name)));
            Assert.IsTrue(keys.Contains(nameof(request.Cpf)));
            Assert.IsTrue(keys.Contains(nameof(request.Address)));
            Assert.IsTrue(keys.Contains(nameof(request.Email)));
            Assert.IsTrue(keys.Contains(nameof(request.Phone)));
        }
        public void Should_Create_And_Return_Token()
        {
            var request = new CreateAccountCommand.Request()
            {
                Cpf     = "11111111111",
                Address = "x.y.z",
                Email   = "Email",
                Name    = "Name",
                Phone   = "Phone"
            };

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

            Assert.IsFalse(string.IsNullOrEmpty(response.Token));
        }
        public void Should_Return_Not_Valid_Request()
        {
            var request = new CreateAccountCommand.Request()
            {
                Cpf     = "99999999999",
                Address = "",
                Email   = "Email",
                Name    = "",
                Phone   = "Phone"
            };

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

            Assert.AreEqual(2, _notifications.Notifications.Count);

            Assert.IsTrue(string.IsNullOrEmpty(response.Token));
        }
 public async Task <ActionResult <CreateAccountCommand.Response> > SignUp([FromBody] CreateAccountCommand.Request request)
 {
     return(await Execute(_command, request));
 }