public void AddUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //create new user messsage
                var newUserMessage = new UserMessage()
                {
                    User = existingUser,
                    Message = existingMessage
                };

                //add the new user message to the repository
                var userMessageRepository = new UserMessageRepository(uow);
                userMessageRepository.Add(newUserMessage);

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                                (
                                    e =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                    }
                                );
                        }
                    );

                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1 = new CapriconContext();
                var repository = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName = "james");
                Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
            };
        }
Beispiel #2
0
        public void AddUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser   = userRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage   = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //create new user messsage
                var newUserMessage = new UserMessage()
                {
                    User    = existingUser,
                    Message = existingMessage
                };

                //add the new user message to the repository
                var userMessageRepository = new UserMessageRepository(uow);
                userMessageRepository.Add(newUserMessage);

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                    {
                        v.ValidationErrors.ToList().ForEach
                        (
                            e =>
                        {
                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                        }
                        );
                    }
                    );

                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1              = new CapriconContext();
                var repository        = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName       = "james");
                Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
            };
        }
Beispiel #3
0
        public void CanSetStatusToHasBeenReceived()
        {
            var sendTime    = DateTime.Now;
            var userMessage = new UserMessage(_toaccount, _fromaccount, sendTime, "message" + _uniqueTestString);

            UserMessageRepository userMessageRepository = new UserMessageRepository();

            userMessageRepository.Add(userMessage);
            Assert.That(userMessage.Id > 0);

            userMessage.HasBeenReceived = true;

            userMessageRepository.Add(userMessage);

            Assert.AreEqual(true, userMessage.HasBeenReceived);
        }
Beispiel #4
0
        public void CanGetTheLastUserMessage()
        {
            var randomRccount = new Account(0, "RandomAccount" + _uniqueTestString, "ToEmail" + _uniqueTestString,
                                            AccountType.Full);


            var accountRepository = new AccountRepository();

            accountRepository.Add(_fromaccount);
            accountRepository.Add(_toaccount);
            accountRepository.Add(randomRccount);

            var sendTime     = DateTime.Now;
            var userMessage1 = new UserMessage(_toaccount, _fromaccount, sendTime, "message" + _uniqueTestString + 1)
            {
                HasBeenReceived = true
            };
            var userMessage2 = new UserMessage(_toaccount, _fromaccount, sendTime, "message" + _uniqueTestString + 2)
            {
                HasBeenReceived = true
            };
            var userMessage3 = new UserMessage(randomRccount, _fromaccount, sendTime, "message" + _uniqueTestString + 3);
            var userMessage4 = new UserMessage(_toaccount, _fromaccount, sendTime, "message" + _uniqueTestString + 3);



            UserMessageRepository userMessageRepository = new UserMessageRepository();

            userMessageRepository.Add(userMessage1);
            userMessageRepository.Add(userMessage2);
            userMessageRepository.Add(userMessage3);
            userMessageRepository.Add(userMessage4);

            var result = userMessageRepository.GetAllPendingMessagesForAccount(_toaccount.Id);

            var singleMessage = result.Single();

            Assert.AreEqual(userMessage4.Id, singleMessage.Id);
            Assert.AreEqual(userMessage4.TextMessage, singleMessage.TextMessage);
            Assert.AreEqual(userMessage4.FromAccount.Id, singleMessage.FromAccount.Id);
            Assert.AreEqual(userMessage4.FromAccount.Name, singleMessage.FromAccount.Name);
            Assert.AreEqual(userMessage4.ToAccount.Id, singleMessage.ToAccount.Id);
        }