public void SendEmail_DeserializeObject()
        {
            var base64 =
                Convert.ToBase64String(
                    Encoding.UTF8.GetBytes("<h1>Title</h1><p>This is the mail body.</p>")
                    );

            var command = new SendMailCommand(
                "*****@*****.**",
                subject: "subject",
                message: base64
                );

            var text = MaskedEmailCommandJsonConvert.SerializeObject(command);

            var o = MaskedEmailCommandJsonConvert.DeserializeObject(text);

            Assert.AreEqual(command.Action, o.Action);
            Assert.AreEqual(command.Address, o.Address);

            var c = o as SendMailCommand;

            Assert.AreEqual(command.Subject, c.Subject);
            Assert.AreEqual(command.Message, c.Message);
        }
        public void DisableMaskedEmail_DeserializeObject()
        {
            var command = new DisableMaskedEmailCommand("*****@*****.**");

            var text = MaskedEmailCommandJsonConvert.SerializeObject(command);

            var o = MaskedEmailCommandJsonConvert.DeserializeObject(text);

            Assert.AreEqual(command.Action, o.Action);
            Assert.AreEqual(command.Address, o.Address);

            var c = o as DisableMaskedEmailCommand;

            Assert.NotNull(c);
        }
        public void AddMaskedEmailCommand_DeserializeObject()
        {
            var command = new AddMaskedEmailCommand("*****@*****.**", "hash", "*****@*****.**");

            var text = MaskedEmailCommandJsonConvert.SerializeObject(command);

            var o = MaskedEmailCommandJsonConvert.DeserializeObject(text);

            Assert.AreEqual(command.Action, o.Action);
            Assert.AreEqual(command.Address, o.Address);

            var c = o as AddMaskedEmailCommand;

            Assert.AreEqual(command.PasswordHash, c.PasswordHash);
            Assert.AreEqual(command.AlternateAddress, c.AlternateAddress);
        }
        public void ChangeMaskedEmailPassword_DeserializeObject()
        {
            var command = new ChangeMaskedEmailPasswordCommand("*****@*****.**")
            {
                PasswordHash = "password-hash",
            };

            var text = MaskedEmailCommandJsonConvert.SerializeObject(command);

            var o = MaskedEmailCommandJsonConvert.DeserializeObject(text);

            Assert.AreEqual(o.Action, command.Action);

            var c = o as ChangeMaskedEmailPasswordCommand;

            Assert.AreEqual(command.Address, c.Address);
            Assert.AreEqual(command.PasswordHash, c.PasswordHash);
        }
        public void ProcessMaskedEmailCommandAsync(
            [QueueTrigger("commands")] string text,
            ILogger logger)
        {
            var request = MaskedEmailCommandJsonConvert.DeserializeObject(text);

            if (request == null)
            {
                logger.LogError("Invalid or malformed request. Ignoring (Enable Trace to include more details).");
                logger.LogTrace(text);
                return;
            }

            logger.LogInformation($"Handling {request.Action} request...");

            var commands = MaskedEmailCommandLineFormatter.Format(request);

            foreach (var command in commands)
            {
                Exec(command, logger);
            }
        }