public void Repository_GetUserByEmail()
        {
            var options = CreateNewContextOptions();

            // add a user
            HighFiveUser highFiveUser = new HighFiveUser();

            highFiveUser.Organization      = new Organization();
            highFiveUser.Email             = "*****@*****.**";
            highFiveUser.Organization.Name = "Ariel Partners";

            using (var context = new HighFiveContext(_config, options))
            {
                context.Users.Add(highFiveUser);
                context.SaveChanges();
            }

            highFiveUser = null;

            // make sure the user was added
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser = repo.GetUserByEmail("*****@*****.**");
                Assert.IsNotNull(highFiveUser);
            }
        }
        public void Repository_UpdateUser()
        {
            var options = CreateNewContextOptions();

            // add the user
            HighFiveUser highFiveUser = new HighFiveUser();

            highFiveUser.Organization      = new Organization();
            highFiveUser.Email             = "*****@*****.**";
            highFiveUser.Organization.Name = "Ariel Partners";

            using (var context = new HighFiveContext(_config, options))
            {
                context.Users.Add(highFiveUser);
                context.SaveChanges();
            }

            highFiveUser = null;

            // update the user's email address
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser       = repo.GetUserByEmail("*****@*****.**");
                highFiveUser.Email = "*****@*****.**";
                context.Update(highFiveUser);
                context.SaveChanges();
            }

            //TODO - add a test too make sure original email [email protected] is not on file

            // read the user and make sure the email was updated
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser = null;
                highFiveUser = repo.GetUserByEmail("*****@*****.**");
                Assert.AreEqual("*****@*****.**", highFiveUser.Email);
            }
        }
        public void Repository_AddUser()
        {
            var options = CreateNewContextOptions();

            HighFiveUser highFiveUser;

            // make sure this user is not on file
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser = repo.GetUserByEmail("*****@*****.**");
                //Assert.IsNull(highFiveUser);
                highFiveUser.Should().BeNull();
            }

            // add the user
            highFiveUser = new HighFiveUser();
            highFiveUser.Organization      = new Organization();
            highFiveUser.Email             = "*****@*****.**";
            highFiveUser.Organization.Name = "Ariel Partners";

            using (var context = new HighFiveContext(_config, options))
            {
                context.Users.Add(highFiveUser);
                context.SaveChanges();
            }

            highFiveUser = null;

            // get the user by email
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser = repo.GetUserByEmail("*****@*****.**");
                Assert.IsNotNull(highFiveUser);
                highFiveUser.Email.Should().Be("*****@*****.**");
                Assert.AreEqual("Ariel Partners", highFiveUser.Organization.Name);
            }
        }
        public void Repository_ForDuplicateUserEmails()
        {
            var options = CreateNewContextOptions();

            HighFiveUser highFiveUser;

            // make sure this user is not on file
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                highFiveUser = repo.GetUserByEmail("*****@*****.**");
                Assert.IsNull(highFiveUser);
            }

            // add the user
            highFiveUser = new HighFiveUser();
            highFiveUser.Organization      = new Organization();
            highFiveUser.Email             = "*****@*****.**";
            highFiveUser.Organization.Name = "Ariel Partners";

            using (var context = new HighFiveContext(_config, options))
            {
                context.Users.Add(highFiveUser);
                context.SaveChanges();
            }

            // check the repo add user method won't add a duplicate email
            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo = new HighFiveRepository(context, _repoLogger);
                //Assert.Throws<Exception>(() => { repo.AddUser(highFiveUser); });

                repo.Invoking(y => y.AddUser(highFiveUser))
                .ShouldThrow <HighFiveException>()
                .WithMessage("User [email protected] already exists in the database");
            }
        }
        public void Given_the_following_recognitions_exist_in_the_system(Table table)
        {
            var recognitionsLst = table.CreateSet <RecognitionViewModel>();

            // add recognitions to the in memory repository
            using (var context = new HighFiveContext(_config, _options))
            {
                //Add Organization
                var org = new Organization
                {
                    Name   = "Ariel Partners",
                    Values = new List <CorporateValue>
                    {
                        new CorporateValue {
                            Name = "Commitment", Description = "Committed to the long term success and happiness of our customers, our people, and our partners"
                        },
                        new CorporateValue {
                            Name = "Courage", Description = "To take on difficult challenges, to accept new ideas, to accept incremental failure"
                        },
                        new CorporateValue {
                            Name = "Excellence", Description = "Always strive to exceed expectations and continuously improve"
                        },
                        new CorporateValue {
                            Name = "Integrity", Description = "Always act honestly, ethically, and do the right thing even when it hurts"
                        },
                        new CorporateValue {
                            Name = "Honesty", Description = "Always act honestly, ethically, and do the right thing even when it hurts"
                        },
                        new CorporateValue {
                            Name = "Vigilance", Description = "Always act honestly, ethically, and do the right thing even when it hurts"
                        },
                        new CorporateValue {
                            Name = "Respect", Description = "Always act honestly, ethically, and do the right thing even when it hurts"
                        }
                    }
                };
                context.Organizations.Add(org);
                context.SaveChanges();
                org = context.Organizations.FirstOrDefault();
                //Add Users
                var testUsersLst = new List <HighFiveUser>
                {
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "joe", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "suresh", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "matthew", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "sue", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "dave", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "nikhil", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "jose", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "tom", LastName = "", Organization = org
                    },
                    new HighFiveUser {
                        UserName = "******", Email = "*****@*****.**", FirstName = "john", LastName = "", Organization = org
                    }
                };
                foreach (var usr in testUsersLst)
                {
                    context.Users.Add(usr);
                }
                context.SaveChanges();
                //Create the Recognitions
                var repo = new HighFiveRepository(context, _repoLogger);
                // for each item in the table, create a recognition
                foreach (RecognitionViewModel recViewModel in recognitionsLst)
                {
                    var obj = Mapper.Map <Recognition>(recViewModel);
                    obj.Sender       = repo.GetUserByEmail(recViewModel.SenderEmail);
                    obj.Receiver     = repo.GetUserByEmail(recViewModel.ReceiverEmail);
                    obj.Organization = repo.GetOrganizationByName(recViewModel.OrganizationName);
                    obj.Value        = repo.GetCorporateValueByName(recViewModel.CorporateValueName);
                    _recognitions.Add(obj);
                }
                context.Recognitions.AddRange(_recognitions);
                context.SaveChangesAsync();
            }
        }