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);
            };
        }
Esempio n. 2
0
        public void AddAgent()
        {
            using (CapriconContext context = new CapriconContext())
            {

                var newAgent = new Agent()
                {
                    FirstName = "Blaise",
                    LastName = "Nyamwamba",
                    OtherName = "",
                    Gender = Gender.Female,
                    MobilePhone = "0756 123 456",
                    Email = "*****@*****.**",
                    Town = "Nairobi",
                    District = "Nairobi",
                    DateOfBirth = DateTime.Now.AddYears(-40),
                };

                var agentRep = new AgentRepository(context);
                agentRep.Add(newAgent);

                try
                {
                    context.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 context1 = new CapriconContext();
                var repository = new AgentRepository(context1);
                var savedAgents = repository.GetAll().ToList();

                Assert.AreEqual(savedAgents.Count(), 1, "returns 20 records");
                var savedAgentsList = savedAgents;
                savedAgentsList.ForEach
                    (
                        s =>
                        {
                            Debug.WriteLine(s.AgentId + " - " + s.FirstName + " " + s.LastName);
                        }
                    );
            };
        }
        public void AddPayment()
        {
            using (CapriconContext context = new CapriconContext())
            {
                var messageRepository = new MessageRepository(context);
                var existingMessage = messageRepository.GetAll().LastOrDefault();

                Assert.IsNotNull(existingMessage);

                var newPayment = new Payment()
                {
                    PaymentDate = DateTime.Now,
                    Amount = 750,
                    Message = existingMessage
                };

                var paymentRep = new PaymentRepository(context);
                paymentRep.Add(newPayment);

                try
                {
                    context.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 context1 = new CapriconContext();
                var repository = new PaymentRepository(context1);
                var savedPayments = repository.GetAll().ToList();

                Assert.AreEqual(savedPayments.Count(), 3, "returns 20 records");
                var savedPaymentsList = savedPayments;
                savedPaymentsList.ForEach
                    (
                        p =>
                        {
                            Debug.WriteLine(p.PaymentId + " - " + p.Amount + " " + p.Message.MessageId);
                        }
                    );
            };
        }
        public void AddMessage()
        {
            using (CapriconContext context = new CapriconContext())
            {
                var newMessage = new Message()
                {
                    Body = "Testing...............",
                    Sent = DateTime.Now,
                    MessageStatus = MessageStatus.Sent
                };

                var messageRep = new MessageRepository(context);
                messageRep.Add(newMessage);

                try
                {
                    context.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 context1 = new CapriconContext();
                var repository = new MessageRepository(context1);
                var savedMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedMessages.Count(), 2, "returns 20 records");
                var savedMessagesList = savedMessages;
                savedMessagesList.ForEach
                    (
                        m =>
                        {
                            Debug.WriteLine(m.MessageId + " - " + m.Body);
                        }
                    );
            };
        }
        public void DeleteUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                var userMessageRepository = new UserMessageRepository(uow);
                var existingUserMessage = userMessageRepository.Find(um => um.Id == 2).FirstOrDefault();

                Assert.IsNotNull(existingUserMessage);

                int id;
                if (existingUserMessage != null)
                {
                    id = existingUserMessage.Id;

                    //Delete selected user message
                    userMessageRepository.Delete(existingUserMessage);

                    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");
                    }

                    Assert.IsNull(userMessageRepository.Find(um => um.Id == id).FirstOrDefault());
                }
                else //no user messages were selected
                    Assert.Fail("No user message was selected");
            }
        }
        public void UpdateUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                var userMessageRepository = new UserMessageRepository(uow);

                var existingUserMessage = userMessageRepository.Find(um => um.Id == 1).FirstOrDefault();

                Assert.IsNotNull(existingUserMessage);

                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.Find(u => u.UserId == 1).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.Find(m => m.MessageId == 1).FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //edit an existing user message
                existingUserMessage.User = existingUser;
                existingUserMessage.Message = existingMessage;

                userMessageRepository.Attach(existingUserMessage);
                uow.Entry(existingUserMessage).State = EntityState.Modified;

                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, existingUser);
                Assert.AreEqual(savedUserMessages[0].Message, existingMessage);
            };
        }
Esempio n. 7
0
        public void DeleteAgent()
        {
            using (var uow = new CapriconContext())
            {
                var agentRep = new AgentRepository(uow);
                var existingAgent = agentRep.Find(a => a.AgentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingAgent);

                int agentId;
                if (existingAgent != null)
                {
                    agentId = existingAgent.AgentId;

                    agentRep.Delete(existingAgent);

                    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");
                    }

                    Assert.IsNull(agentRep.Find(a => a.AgentId == agentId).FirstOrDefault());
                }
                else //no agents were selected
                    Assert.Fail("No agent was selected");
            }
        }
Esempio n. 8
0
        public void UpdateAgent()
        {
            using (var uow = new CapriconContext())
            {
                var agentRep = new AgentRepository(uow);

                var existingAgents = agentRep.GetAll().ToList();

                var existingAgent = existingAgents.LastOrDefault();

                Assert.IsNotNull(existingAgent);

                existingAgent.FirstName = "Hilda";
                existingAgent.LastName = "Kunda";
                existingAgent.OtherName = "";
                existingAgent.Gender = Gender.Male;
                existingAgent.DateOfBirth = DateTime.Now.AddYears(-60);
                existingAgent.MobilePhone = "0777 700 700";
                existingAgent.Email = "*****@*****.**";
                existingAgent.Town = "Bugembe";
                existingAgent.District = "Jinja";

                //check for validation rules
                //existingAgent.FirstName = "";
                //existingAgent.LastName = "";
                //existingAgent.Gender = Gender.Not_Specified;
                //existingAgent.Email = "";
                //existingAgent.Town = "";
                //existingAgent.District = "";

                agentRep.Attach(existingAgent);
                uow.Entry(existingAgent).State = EntityState.Modified;

                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 AgentRepository(uow1);
            var savedAgents = repository.GetAll().ToList();

            Assert.AreEqual(savedAgents[0].LastName, "Byanjeru");
        }
        public void UpdateMessage()
        {
            using (var uow = new CapriconContext())
            {
                var messageRep = new MessageRepository(uow);

                var existingMessages = messageRep.GetAll().ToList();

                var existingMessage = existingMessages.Find(m => m.MessageId == 3);

                Assert.IsNotNull(existingMessage);

                existingMessage.Body = "";
                existingMessage.Sent = DateTime.Now;
                existingMessage.MessageStatus = MessageStatus.Received;

                //check for validation rules
                //existingMessage.Body = "";
                //existingMessage.Sent = DateTime.Now;
                //existingMessage.MessageStatus = MessageStatus.Not_Specified;

                messageRep.Attach(existingMessage);
                uow.Entry(existingMessage).State = EntityState.Modified;

                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 MessageRepository(uow1);
            var savedMessages = repository.GetAll().ToList();

            Assert.AreEqual(savedMessages[0].MessageId, 1);
        }
Esempio n. 10
0
        public void UpdatePayment()
        {
            using (var uow = new CapriconContext())
            {
                var paymentRep = new PaymentRepository(uow);

                var existingPayments = paymentRep.GetAll().ToList();

                var existingPayment = existingPayments.Find(p => p.PaymentId == 3);

                Assert.IsNotNull(existingPayment);

                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                existingPayment.PaymentDate = DateTime.Now;
                existingPayment.Amount = 350;
                existingPayment.Message = existingMessage;

                //check for validation rules
                //existingPayment.PaymentDate = DateTime.Now;

                paymentRep.Attach(existingPayment);
                uow.Entry(existingPayment).State = EntityState.Modified;

                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 PaymentRepository(uow1);
            var savedPayments = repository.GetAll().ToList();

            Assert.AreEqual(savedPayments[0].Amount, 350);
        }
Esempio n. 11
0
        public void UpdateUser()
        {
            using (var uow = new CapriconContext())
            {
                var userRep = new UserRepository(uow);

                var existingUsers = userRep.GetAll().ToList();

                var existingUser = existingUsers.Find(a => a.UserId == 3);

                Assert.IsNotNull(existingUser);

                existingUser.FirstName = "Aaron";
                existingUser.LastName = "Mukasa";
                existingUser.OtherName = "Gad";
                existingUser.Gender = Gender.Male;
                existingUser.DateOfBirth = DateTime.Now.AddYears(-60);
                existingUser.MobilePhone = "0777 700 700";
                existingUser.Email = "*****@*****.**";
                existingUser.Town = "Bugembe";
                existingUser.District = "Jinja";

                //check for validation rules
                //existingUser.FirstName = "";
                //existingUser.LastName = "";
                //existingUser.Gender = Gender.Not_Specified;
                //existingUser.Email = "";
                //existingUser.Town = "";
                //existingUser.District = "";

                userRep.Attach(existingUser);
                uow.Entry(existingUser).State = EntityState.Modified;

                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 UserRepository(uow1);
            var savedUsers = repository.GetAll().ToList();

            Assert.AreEqual(savedUsers[0].LastName, "Mawa");
        }