public void ReturnCreatedAtRouteWhenCreateMessageCalled()
        {
            var messageToCreate = new MessageDto
            {
                Title = "createMessageTitle",
                Body  = "createMessageBody"
            };

            IActionResult result = _controller.CreateMessage(messageToCreate);

            Assert.IsType <CreatedAtRouteResult>(result);
        }
        public bool Add()
        {
            bool added = false;

            try
            {
                MessageCrudView form = new MessageCrudView(_controls);
                form.CreateView(CrudPurposes.Create);

                form.ShowDialog();
                AppMessage   result       = form.Data.Results;
                DialogResult dialogResult = form.Data.DialogResult;

                if (dialogResult != DialogResult.Cancel && result != null)
                {
                    added = _messageController.CreateMessage(result);
                }

                form.Dispose();
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to add item.", "Please try again.", MessageBoxButtons.OK);
                added = false;
            }

            return(added);
        }
Esempio n. 3
0
        public async Task CreateMessage_ServiceInvoke()
        {
            //Act
            await _messageController.CreateMessage(It.IsAny <MessageDto>());

            //Assert
            _messageServiceMock.Verify(s => s.CreateMessage(It.IsAny <MessageDto>()));
        }
Esempio n. 4
0
        public void CreateMessageWorking()
        {
            List <Chat> chats = chatController.GetChatsByName("", profileId);
            Chat        chat  = chats[chats.Count - 1];

            Assert.AreNotEqual(null, controller.CreateMessage(profileId, "test", chat.ActivityId));
        }
        public async void CreateMessageBadRequestMessageIsNull()
        {
            // Arrange
            var mock = new Mock <IMessageRepository>();
            MessageController controller = new MessageController(mock.Object);

            // Act
            BadRequestObjectResult model = await controller.CreateMessage(null) as BadRequestObjectResult;

            // Assert
            mock.Verify(rep => rep.AddMessageAsync(It.IsAny <Message>()), Times.Never);
            Assert.Equal((int?)HttpStatusCode.BadRequest, model.StatusCode);
        }
Esempio n. 6
0
        public async Task TestCreateMessage_Failed_BadRequest()
        {
            //Arrange
            var id           = 1;
            var hotelMessage = new HotelMessageViewModel()
            {
                MessageId     = 0,
                HotelId       = id,
                MessageTitle  = "Title1",
                MessageTypeId = id,
                StartDate     = DateTime.Now,
                EndDate       = DateTime.Now.AddDays(-2),
                IsActive      = true,
                ObjectState   = ObjectState.Added
            };
            //Act
            var result = await mockMessageController.CreateMessage(hotelMessage);

            //Assert
            mockMessagesRepository.Verify();
            Assert.IsTrue(result is BadRequestObjectResult);
            Assert.AreEqual(((BadRequestObjectResult)result).StatusCode, 400);
        }
        public async void CreateMessageBadRequestMessageAlreadyExists(Message[] messages)
        {
            // Arrange
            var mock = new Mock <IMessageRepository>();
            MessageController controller = new MessageController(mock.Object);

            mock.SetupSequence(rep => rep.GetMessageByIdAsync(It.IsAny <int>())).Returns(Task <Message> .Run(() => messages[0]));

            // Act
            BadRequestObjectResult model = await controller.CreateMessage(messages[0]) as BadRequestObjectResult;

            // Assert
            mock.Verify(m => m.AddMessage(It.IsAny <Message>()), Times.Never);
            Assert.Equal((int?)HttpStatusCode.BadRequest, model.StatusCode);
        }
Esempio n. 8
0
        private void BtnEnviar_Click(object sender, EventArgs e)
        {
            //Valida se o usuário realmente deseja enviar o email
            if (MessageBox.Show("Enviando email para " + Receiver + " a partir do usuário " + Sender + ".\nDeseja continuar?", "Enviando mensagem", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.Cancel)
            {
                try
                {
                    //Cria um client SMTP para enviar o email. (host, porta)
                    SmtpClient client = new SmtpClient("smtp-mail.outlook.com", 587);

                    //Aqui informa ao programa qual email (junto com a senha) que irá enviar.
                    NetworkCredential cred = new NetworkCredential("*****@*****.**", "m1nh4s3nh4");

                    //Código para criar o email (sem as informações) que iremos mandar.
                    MailMessage msg = new MailMessage();

                    //Enviando informações do email
                    //Email remetente
                    msg.From = new MailAddress("*****@*****.**");

                    //Email destinatário
                    msg.To.Add(PessoaReceiver.email);

                    //Assunto do email
                    msg.Subject = "SACOI " + PessoaSender.p_nome + " " + TxtSubject.Text;

                    //Corpo de texto do email
                    msg.Body = TxtBody.Text;

                    //Envia para o SACOI as credenciais do email
                    client.Credentials = cred;

                    //Habilita o SSL (Secure Sockets Layer) que os servidores de email pedem.
                    client.EnableSsl = true;

                    //Envia o email
                    client.Send(msg);

                    Message.CreateMessage(Sender, Receiver, msg.Subject.ToString(), msg.Body.ToString());
                }
                catch
                {
                    MessageBox.Show("Não foi possível enviar o email", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void CreateMessageThrowsException()
        {
            // Arrange
            var mock = new Mock <IMessageRepository>();

            mock.SetupSequence(rep => rep.GetMessageByIdAsync(It.IsAny <int>())).Throws <MessagesDomainException>();
            MessageController controller = new MessageController(mock.Object);

            // Act & Assert
            Exception ex = Assert.ThrowsAsync <MessagesDomainException>(
                async() => await controller.CreateMessage(new Message()
            {
                Id = int.MaxValue
            })
                )?.Result;

            Assert.Equal(expected: typeof(MessagesDomainException), actual: ex.GetType());
        }
Esempio n. 10
0
        public async void CreateMessageBadRequestMessageIdIsLessThanOne()
        {
            // Arrange
            var mock = new Mock <IMessageRepository>();
            MessageController controller = new MessageController(mock.Object);
            Message           message    = new Message()
            {
                Id   = int.MinValue,
                Name = $"Name {int.MinValue}",
                Body = $"Body {int.MinValue}"
            };

            // Act
            BadRequestObjectResult model = await controller.CreateMessage(message) as BadRequestObjectResult;

            // Assert
            mock.Verify(rep => rep.AddMessageAsync(It.IsAny <Message>()), Times.Never);
            Assert.Equal((int?)HttpStatusCode.BadRequest, model.StatusCode);
        }
Esempio n. 11
0
        public async static void CreateMessageDialog(Chat chat, string messageText)
        {
            switch (chat.Step)
            {
            case 1:
                await MessageController.CreateMessage(messageText, string.Empty, chat.Id);

                await ChatController.SetStep(1, 2, chat);

                await botClient.SendTextMessageAsync(chat.ChatId, "Send output message");

                break;

            case 2:
                await MessageController.UpdateMessage(messageText, chat.Id);

                await ChatController.SetStep(0, 0, chat);

                await botClient.SendTextMessageAsync(chat.ChatId, "Done! Message saved!");

                break;
            }
        }
Esempio n. 12
0
        public async Task SeenMessageShouldGenerateHashButNotSaveToDatabase()
        {
            var message      = "foo";
            var expectedHash = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae";
            var saved        = false;

            var repo = new Mock <IServiceRepository>();

            repo.Setup(r => r.HashExistsAsync(It.IsAny <string>())).ReturnsAsync(true);
            repo.Setup(r => r.SaveChangesAsync()).Callback(() => saved = true).ReturnsAsync(true);
            var mapper = this.GetConfiguredMapper();
            var logger = Mock.Of <ILogger <MessageController> >();

            var request = new MessageRequestModel(message);

            var controller = new MessageController(repo.Object, mapper, logger);
            var response   = await controller.CreateMessage(request);

            var objectResult = Assert.IsType <OkObjectResult>(response.Result);
            var result       = Assert.IsType <MessageRequestModel>(objectResult.Value);

            Assert.Equal(expectedHash, result.Digest);
            Assert.False(saved);
        }
Esempio n. 13
0
        public async void CreateMessageCreated()
        {
            // Arrange
            Message messageCreated =
                new Message
            {
                Id   = int.MaxValue,
                Name = $"Name {int.MaxValue}",
                Body = $"Body {int.MaxValue}"
            };

            var mock = new Mock <IMessageRepository>();

            MessageController controller = new MessageController(mock.Object);

            mock.SetupSequence(rep => rep.GetMessageByIdAsync(It.IsAny <int>())).Returns(Task <Message> .Run(() => default(Message)));

            // Act
            CreatedAtRouteResult model = await controller.CreateMessage(messageCreated) as CreatedAtRouteResult;

            // Assert
            mock.Verify(rep => rep.AddMessageAsync(It.IsAny <Message>()), Times.Once);
            Assert.Equal((int?)HttpStatusCode.Created, model.StatusCode);
        }
Esempio n. 14
0
        public void CreateMessage(User user)
        {
            Console.Clear();
            UserController userController  = new UserController();
            List <User>    listOfReceivers = userController.RetrieveUsers().Where(x => x.Id != user.Id).ToList();

            foreach (var item in listOfReceivers)
            {
                Console.WriteLine($"Receiver: {item.UserName}, ReceiverId: {item.Id}");
            }

            bool value = true;
            int  checkId;
            var  listOfIds = listOfReceivers.Select(x => x.Id).ToList();

            do
            {
                Console.WriteLine("Give the Id of the receiver or press  0 to return back");
                bool success = int.TryParse(Console.ReadLine(), out checkId);
                if (success)
                {
                    if (checkId == 0)
                    {
                        return;
                    }
                    if (listOfIds.Contains(checkId))
                    {
                        value = false;
                    }
                }
            } while (value);

            string messageData;

            do
            {
                Console.WriteLine("Give the messageData");
                messageData = Console.ReadLine();
            } while (string.IsNullOrWhiteSpace(messageData));

            Message           message           = new Message();
            MessageController messageController = new MessageController();

            message.MessageData = messageData;
            message.ReceiverId  = checkId;
            message.SenderId    = user.Id;

            try
            {
                messageController.CreateMessage(message);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Console.Clear();
                Console.WriteLine(ex.EntityValidationErrors.FirstOrDefault().ValidationErrors.FirstOrDefault().ErrorMessage);
                Console.WriteLine("Press Something to continue");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.WriteLine(ex.Message);
                Console.WriteLine("Press Something to continue");
                Console.ReadKey();
            }
        }