Esempio n. 1
0
        public ActionResult NewMessage(Message p, string btn)
        {
            ValidationResult results = messageValidator.Validate(p);

            if (results.IsValid)
            {
                p.SenderMail = (string)Session["WriterMail"];
                var writeridinfo = vm.GetByWriterId(p.SenderMail);
                p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                if (btn == "Send")
                {
                    p.MessageDraftsStatus = false;
                    mm.MessageAdd(p);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    p.MessageDraftsStatus = true;
                    mm.MessageAdd(p);
                    return(RedirectToAction("Draftbox"));
                }
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
Esempio n. 2
0
            public void ValidSignatureReturnsSucceeds()
            {
                _mockHandler.Setup(
                    m => m.AuthenticateSession(SampleData.PublicKey, It.IsAny <string>(), It.IsAny <string>()));

                _validator.Validate(_message);

                _mockHandler.VerifyAll();
            }
        public void DuplicitMessageReceived()
        {
            // arrange
            var validator = new MessageValidator();
            var message1  = new Message(1, "test-message");

            // act & assert
            Assert.IsType <SuccessValidationResult>(validator.Validate(message1));
            Assert.IsType <AlreadyProcessedValidationResult>(validator.Validate(message1));
        }
Esempio n. 4
0
        public void FailsIfContentIsNull()
        {
            var message = new Message {
            };

            var result = validator.Validate(message);

            Assert.Multiple(() =>
            {
                Assert.That(result.IsValid, Is.False);
                Assert.That(result.Errors.Count, Is.EqualTo(2));
            });
        }
        public void ConsecutiveMessagesShouldPassValidation()
        {
            // arrange
            var validator = new MessageValidator();

            // act & assert
            var message1 = new Message(2, "test-message");

            Assert.IsType <SuccessValidationResult>(validator.Validate(message1));
            var message2 = new Message(3, "test-message");

            Assert.IsType <SuccessValidationResult>(validator.Validate(message2));
        }
Esempio n. 6
0
        public static Task Validate <TMessage>(this TestableMessageHandlerContext context, TMessage message)
            where TMessage : class
        {
            var         builder = context.Builder;
            List <Task> tasks   = new()
            {
                validator.Validate(message.GetType(), builder, message, context.Headers, context.Extensions)
            };

            tasks.AddRange(context.PublishedMessages.Select(publishedMessage => Validate(publishedMessage, builder)));
            tasks.AddRange(context.SentMessages.Select(sentMessage => Validate(sentMessage, builder)));
            tasks.AddRange(context.RepliedMessages.Select(repliedMessage => Validate(repliedMessage, builder)));
            tasks.AddRange(context.TimeoutMessages.Select(timeoutMessage => Validate(timeoutMessage, builder)));

            return(Task.WhenAll(tasks));
        }
        public ValidationResult ValidateMessageModel(MessageDto messageModel)
        {
            var validator       = new MessageValidator();
            var validatorResult = validator.Validate(messageModel);

            return(validatorResult);
        }
Esempio n. 8
0
    public override async Task Invoke(IOutgoingLogicalMessageContext context, Func <Task> next)
    {
        var message = context.Message;
        await validator.Validate(message.MessageType, context.Builder, message.Instance, context.Headers, context.Extensions);

        await next();
    }
Esempio n. 9
0
        public ActionResult NewMessage(Message message, string parameter)
        {
            ValidationResult results = messageValidator.Validate(message);

            if (results.IsValid)
            {
                message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                messageManager.MessageAddBL(message);
                return(RedirectToAction("SendBox"));
            }
            else if (parameter == "draft")
            {
                message.SenderMail  = "*****@*****.**";
                message.IsDraft     = true;
                message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                messageManager.MessageAddBL(message);
                return(RedirectToAction("Draft"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }

            return(View());
        }
Esempio n. 10
0
        /// <inheritdoc />
        public async Task <DispatchResponse> Dispatch(Message message, CancellationToken cancellationToken = default)
        {
            MessageValidator.Validate(message);
            message.Id = message.Id == Guid.Empty ? Guid.NewGuid() : message.Id;

            return(await GetProvider(message.Queue).Dispatch(message, cancellationToken).ConfigureAwait(false));
        }
Esempio n. 11
0
        public IActionResult SendMessage([Bind("Body,SenderName,SenderEmail,Subject")] Message message)
        {
            //Message message2 = this.contactService.GetById(Guid.Parse("7f0a9a23-e4ab-45c5-a647-d6e1c19c0f6a"));
            //message2.Subject = "Change tracker tests";
            //message.Id = Guid.Parse("7f0a9a23-e4ab-45c5-a647-d6e1c19c0f6a");
            //message.Subject = "Attach test";
            //this.contactService.UpdateMessage(message);

            string errorMessage     = "";
            var    messageValidator = new MessageValidator();
            var    validationResult = messageValidator.Validate(message);

            if (validationResult.IsValid)
            {
                this.contactService.SendMessage(message);
            }
            else
            {
                foreach (var validationFailure in validationResult.Errors)
                {
                    errorMessage += validationFailure.ErrorMessage + "\n";
                }
                ViewBag.ErrorMessage = errorMessage;
            }

            return(View("Index"));
        }
Esempio n. 12
0
        private IMessage ParseFromParameters(string[] parameters)
        {
            var abstractMessage = AbstractMessageValidator.Validate(this, parameters).Message as BaseMessage;

            if (abstractMessage == null)
            {
                throw new MessageProcessorException("Could not validate AbstractMessage");
            }

            if (!Enum.IsDefined(typeof(MessageId), abstractMessage.Id))
            {
                throw new MessageProcessorException(
                          string.Format("MessageId not defined (messageId = {0})", abstractMessage.Id));
            }

            if (!_messages.ContainsKey(abstractMessage.Id))
            {
                throw new MessageProcessorException(
                          string.Format("Message not registered (messageId = {0})", abstractMessage.Id));
            }

            if (!_validators.ContainsKey(_messages[abstractMessage.Id]))
            {
                throw new MessageProcessorException(
                          string.Format("Validator not found (messageId = {0})", abstractMessage.Id));
            }

            return(Match(abstractMessage, abstractMessage.Id, parameters.Skip(2).ToArray()).Message as IMessage);
        }
Esempio n. 13
0
        public OperationStatusInfo <string> SendMessage(MessageDTO messageDto)
        {
            this.loggingService.Info($"Попытка валидации сообщения {messageDto}.");

            // валидация
            var validator        = new MessageValidator();
            var validationResult = validator.Validate(messageDto);

            // проверка валидации
            if (!validationResult.IsValid)
            {
                return(this.operationStatusService.HandleValidationError(
                           $"Ошибка при валидации сообщения: {messageDto}. Текст ошибки: {validationResult}",
                           validationResult.ToString()));
            }

            try
            {
                var message = DTOService.ToEntity <MessageDTO, Message>(messageDto);
                message.UserFrom = null;
                message.UserTo   = null;
                this.currentRepository.Insert(message);
                return(this.operationStatusService.HandleSuccessOperation(
                           $"Сообщение {messageDto} успешно отправлено.", string.Empty));
            }
            catch (Exception exception)
            {
                return(this.operationStatusService.HandleException(exception, string.Empty));
            }
        }
Esempio n. 14
0
        public ActionResult NewMessage(Message model, string button)
        {
            ValidationResult results = new ValidationResult();

            if (button == "draft")
            {
                results = messageValidator.Validate(model);
                if (results.IsValid)
                {
                    model.SenderMail  = "*****@*****.**";
                    model.MessageDate = DateTime.Now;
                    model.SenderMail  = "*****@*****.**";
                    model.isDraft     = true;
                    mm.MessageAdd(model);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "save")
            {
                results = messageValidator.Validate(model);
                if (results.IsValid)
                {
                    model.SenderMail  = "*****@*****.**";
                    model.MessageDate = DateTime.Now;
                    model.SenderMail  = "*****@*****.**";
                    model.isDraft     = false;
                    mm.MessageAdd(model);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View());
        }
        public ActionResult AddNewMessage(Message message, string button)
        {
            string           sender     = (string)Session["WriterMail"];
            ValidationResult validation = messageValidator.Validate(message);

            if (button == "draft")
            {
                validation = messageValidator.Validate(message);
                if (validation.IsValid)
                {
                    message.SenderMail  = sender;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.IsDraft     = true;
                    messageManager.Add(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in validation.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (button == "send")
            {
                validation = messageValidator.Validate(message);
                if (validation.IsValid)
                {
                    message.SenderMail  = sender;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.IsDraft     = false;
                    messageManager.Add(message);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    foreach (var item in validation.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View(message));
        }
Esempio n. 16
0
        public ActionResult NewMessage(Message p, string button)
        {
            ValidationResult results = messageValidator.Validate(p);

            if (button == "draft")
            {
                results = messageValidator.Validate(p);
                if (results.IsValid)
                {
                    Draft draft = new Draft();
                    draft.ReceiverMail = p.ReceiverMail;
                    draft.Subject      = p.Subject;
                    draft.DraftContent = p.MessageContent;
                    draft.DraftDate    = DateTime.Parse(DateTime.Now.ToShortDateString());
                    draftController.AddDraft(draft);
                    return(RedirectToAction("Draft", "Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (button == "save")
            {
                results = messageValidator.Validate(p);
                if (results.IsValid)
                {
                    p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    p.SenderMail  = "*****@*****.**";
                    messageManager.MessageAdd(p);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View());
        }
        public ActionResult NewMessage(Message p, string button)
        {
            ValidationResult results = new ValidationResult();
            string           sender  = (string)Session["WriterMail"];

            if (button == "draft")
            {
                results = messagevalidator.Validate(p);
                if (results.IsValid)
                {
                    p.MessageDate = DateTime.Now;
                    p.SenderMail  = sender;
                    p.isDraft     = true;
                    mm.MessageAdd(p);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "save")
            {
                results = messagevalidator.Validate(p);
                if (results.IsValid)
                {
                    p.MessageDate = DateTime.Now;
                    p.SenderMail  = sender;
                    p.isDraft     = false;
                    mm.MessageAdd(p);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View());
        }
        public ActionResult NewMessage(Message p, string button)
        {
            ValidationResult results = messagevalidator.Validate(p);

            if (button == "draft")
            {
                results = messagevalidator.Validate(p);
                if (results.IsValid)
                {
                    p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    p.SenderMail  = "*****@*****.**";
                    p.isDraft     = true;
                    mm.MessageAdd(p);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "save")
            {
                results = messagevalidator.Validate(p);
                if (results.IsValid)
                {
                    p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    p.SenderMail  = "*****@*****.**";
                    p.isDraft     = false;
                    mm.MessageAdd(p);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            return(View());
        }
Esempio n. 19
0
        public ActionResult NewMessage(Message message, string button)
        {
            string           userEmail = (string)Session["WriterMail"];
            ValidationResult results   = messageValidator.Validate(message);

            if (button == "draft")
            {
                results = messageValidator.Validate(message);
                if (results.IsValid)
                {
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.SenderMail  = userEmail;
                    message.isDraft     = true;
                    _messageManager.Add(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "save")
            {
                results = messageValidator.Validate(message);
                if (results.IsValid)
                {
                    message.MessageDate = DateTime.Now;
                    message.SenderMail  = userEmail;
                    message.isDraft     = false;
                    _messageManager.Add(message);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View());
        }
        public void WhenMessageMissingIsDetectedThenValidationShouldFail()
        {
            // arrange
            var validator = new MessageValidator();

            // act & assert
            var message1 = new Message(1, "test-message");

            Assert.IsType <SuccessValidationResult>(validator.Validate(message1));

            var message2      = new Message(3, "test-message");
            var failureResult = validator.Validate(message2);

            Assert.Equal(3, validator.LastMessageId);
            var resultForMissingMessages = Assert.IsAssignableFrom <ValidationResultForMissedMessages>(failureResult);

            Assert.Equal(1, resultForMissingMessages.LastProcessedMessageId); // message with ID=2 is missing
        }
Esempio n. 21
0
        public void Part1(string filename, int rule, int end, long expected)
        {
            var parser = new Parser(filename);
            var lines  = parser.Parse(new MessageFactory())
                         .Where(c => c != null);
            var sut    = new MessageValidator(lines.FirstOrDefault());
            var actual = sut.Validate(rule, end);

            Assert.Equal(expected, actual);
        }
        public void SkipValidationWhenMessagesNotReceivedYet()
        {
            // arrange
            var validator = new MessageValidator();

            // act & assert
            var message = new Message(2000, "test-message"); // some large message ID

            Assert.IsType <SuccessValidationResult>(validator.Validate(message));
        }
Esempio n. 23
0
        public void Part2(string filename, int rule, int end, int expected)
        {
            var parser = new Parser(filename);
            var lines  = parser.Parse(new MessageFactory())
                         .Where(c => c != null);
            //var sut = new MessageValidator(new Envelope(lines.FirstOrDefault().Rules, new string[] { "aaaabbaaaabbaaa" })); // lines.FirstOrDefault());
            var sut    = new MessageValidator(lines.FirstOrDefault());
            var actual = sut.Validate(rule, end);

            Assert.Equal(expected, actual);
        }
Esempio n. 24
0
        public ActionResult AddDraftMessageOrSendMessage(Message message)
        {
            if (Request["Send"] != null)
            {
                Message sentMessage = new Message
                {
                    Content = message.Content,
                    Date    = message.Date,
                    isDraft = message.isDraft,
                    From    = "*****@*****.**",
                    Subject = message.Subject,
                    To      = message.To
                };

                ValidationResult results = validationRules.Validate(sentMessage);

                if (results.IsValid)
                {
                    _messageService.Add(sentMessage);

                    return(RedirectToAction("SentMessages"));
                }

                else
                {
                    foreach (var error in results.Errors)
                    {
                        ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                    }

                    return(View("NewMessage"));
                }
            }

            else if (Request["Draft"] != null)
            {
                Message draftMessage = new Message
                {
                    Date    = message.Date,
                    Content = message.Content,
                    From    = "*****@*****.**",
                    Subject = message.Subject,
                    To      = message.To,
                    isDraft = true
                };
                _messageService.Add(draftMessage);

                return(RedirectToAction("GetDraftMessages"));
            }

            return(View());
        }
Esempio n. 25
0
        public ActionResult AddMessage(Message message, string button)
        {
            string           sender           = (string)Session["WriterMail"];
            ValidationResult validationResult = messageValidator.Validate(message);

            if (button == "add")
            {
                if (validationResult.IsValid)
                {
                    message.SenderMail  = sender;
                    message.IsDraft     = false;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.MessageAddBL(message);
                    return(RedirectToAction("WriterSendbox"));
                }
                else
                {
                    foreach (var item in validationResult.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (button == "draft")
            {
                if (validationResult.IsValid)
                {
                    message.SenderMail  = "gizemyıldı[email protected]";
                    message.IsDraft     = true;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.MessageAddBL(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in validationResult.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "cancel")
            {
                return(RedirectToAction("AddMessage"));
            }

            return(View());
        }
Esempio n. 26
0
        public static void AddMessages(string solutionDirectory, IFileSystem fileSystem, List <Message> messages)
        {
            var validator = new MessageValidator();

            foreach (var message in messages)
            {
                var results = validator.Validate(message);
                if (!results.IsValid)
                {
                    throw new DataValidationErrorException(results.Errors);
                }
            }

            messages.ForEach(message => MessageBuilder.CreateMessage(solutionDirectory, message, fileSystem));
        }
Esempio n. 27
0
        public ActionResult NewMessage(Message message, string button)
        {
            ValidationResult validationResult = messageValidator.Validate(message);

            if (button == "add")
            {
                if (validationResult.IsValid)
                {
                    message.SenderMail  = "*****@*****.**";
                    message.IsDraft     = false;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.Insert(message);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    foreach (var item in validationResult.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (button == "draft")
            {
                if (validationResult.IsValid)
                {
                    message.SenderMail  = "*****@*****.**";
                    message.IsDraft     = true;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.Insert(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in validationResult.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "cancel")
            {
                return(RedirectToAction("NewMessage"));
            }

            return(View());
        }
Esempio n. 28
0
        public ActionResult NewMessage(Message message, string buttons)
        {
            MessageValidator messageValidator = new MessageValidator();
            ValidationResult results          = messageValidator.Validate(message);
            HttpUtility      utility          = new HttpUtility();

            string sender = (string)Session["WriterMail"];


            if (results.IsValid)
            {
                if (buttons == "send")
                {
                    message.SenderMail  = sender;
                    message.isDraft     = false;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    mm.MessageAddBl(message);
                    return(RedirectToAction("Sendbox"));
                }
                else if (buttons == "draft")
                {
                    message.SenderMail  = sender;
                    message.isDraft     = true;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());

                    //MvcHtmlString data = MvcHtmlString.Create( message.MessageContent);

                    //message.MessageContent = data.ToString();


                    string data = Server.HtmlEncode(message.MessageContent);
                    message.MessageContent = data;


                    mm.MessageAddBl(message);
                    return(RedirectToAction("DraftList"));
                }
            }

            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
Esempio n. 29
0
        public ActionResult NewMessage(Message p, string menuName)
        {
            string           session = (string)Session["AdminUserName"];
            ValidationResult results = messageValidator.Validate(p);

            if (menuName == "send")
            {
                if (results.IsValid)
                {
                    p.SenderMail  = session;
                    p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.MessageAddBL(p);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (menuName == "draft")
            {
                if (results.IsValid)
                {
                    p.SenderMail  = session;
                    p.IsDraft     = true;
                    p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.MessageAddBL(p);
                    return(RedirectToAction("DraftMessages"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (menuName == "cancel")
            {
                return(RedirectToAction("NewMessage"));
            }
            return(View());
        }
Esempio n. 30
0
        public ActionResult NewMessage(Message message)
        {
            ValidationResult results = messageValidator.Validate(message);

            if (results.IsValid)
            {
                message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                messageManager.MessageAdd(message);
                return(RedirectToAction("Sendbox"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }