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);
            };
        }
        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 DeleteMessage()
        {
            using (var uow = new CapriconContext())
            {
                var messageRep = new MessageRepository(uow);
                var existingMessage = messageRep.Find(m => m.MessageId == 2).FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                int messageId;
                if (existingMessage != null)
                {
                    messageId = existingMessage.MessageId;

                    //Delete message
                    messageRep.Delete(existingMessage);

                    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(messageRep.Find(m => m.MessageId == messageId).FirstOrDefault());
                }
                else //no messages were selected
                    Assert.Fail("No message was selected");
            }
        }
        public void DeletePayment()
        {
            using (var uow = new CapriconContext())
            {
                var paymentRep = new PaymentRepository(uow);
                var existingPayment = paymentRep.Find(p => p.PaymentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingPayment);

                int paymentId;
                if (existingPayment != null)
                {
                    paymentId = existingPayment.PaymentId;

                    //Delete payment
                    paymentRep.Delete(existingPayment);

                    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(paymentRep.Find(p => p.PaymentId == paymentId).FirstOrDefault());
                }
                else //no payments were selected
                    Assert.Fail("No payment was selected");
            }
        }
示例#7
0
        public void DeleteUser()
        {
            using (var uow = new CapriconContext())
            {
                var userRep = new UserRepository(uow);
                var existingUser = userRep.Find(u => u.UserId == 2).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                int userId;
                if (existingUser != null)
                {
                    userId = existingUser.UserId;

                    //Delete employee
                    userRep.Delete(existingUser);

                    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(userRep.Find(u => u.UserId == userId).FirstOrDefault());
                }
                else //no userss were selected
                    Assert.Fail("No user 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);
            };
        }
        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);
        }
        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);
        }
示例#12
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");
        }