Beispiel #1
0
        public void UsersController_Put_SimulateServerFailure()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                var organization = new Organization()
                {
                    Name = "Ariel Partners"
                };
                context.Organizations.Add(organization);
                var organization2 = new Organization()
                {
                    Name = "Acme"
                };
                context.Organizations.Add(organization2);
                var user = new HighFiveUser()
                {
                    Email = "*****@*****.**", Organization = organization
                };
                context.Users.Add(user);
                context.SaveChanges();

                var             repo       = new Mock <IHighFiveRepository>();
                UsersController controller = new UsersController(repo.Object, _controllerLogger);
                repo.Setup(r => r.GetUserByEmail(It.IsAny <String>())).Returns(user);
                repo.Setup(r => r.UpdateUser(It.IsAny <HighFiveUser>())).Throws <Exception>();

                var updatedUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "IDontExist"
                };
                var result = controller.Put("*****@*****.**", updatedUser);
                result.Should().BeOfType <NotFoundObjectResult>();
                var notFoundResult = result as NotFoundObjectResult;
                AssertMessageProperty("Organization IDontExist not found", notFoundResult.Value);
            }
        }
Beispiel #2
0
        public void UsersController_Put_NoChange()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                var organization = new Organization()
                {
                    Name = "Ariel Partners"
                };
                context.Organizations.Add(organization);
                var organization2 = new Organization()
                {
                    Name = "Acme"
                };
                context.Organizations.Add(organization2);
                context.Users.Add(new HighFiveUser()
                {
                    Email = "*****@*****.**", Organization = organization
                });
                context.SaveChanges();
            }

            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo       = new HighFiveRepository(context, _repoLogger);
                UsersController    controller = new UsersController(repo, _controllerLogger);

                var updatedUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "Ariel Partners"
                };
                var result = controller.Put("*****@*****.**", updatedUser);
                result.Should().BeOfType <OkObjectResult>();
                var okObjectResult = result as OkObjectResult;
                AssertMessageProperty("User [email protected] was not changed", okObjectResult.Value);
            }
        }
Beispiel #3
0
        public void UsersController_Put_OrganizationNotFound()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                var organization = 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 "
                        }
                    }
                };
                context.Organizations.Add(organization);
                var organization2 = new Organization()
                {
                    Name   = "Acme",
                    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 "
                        }
                    }
                };
                context.Organizations.Add(organization2);
                context.Users.Add(new HighFiveUser()
                {
                    Email = "*****@*****.**", Organization = organization
                });
                context.SaveChanges();

                var repo       = new HighFiveRepository(context, _repoLogger);
                var controller = new UsersController(repo, _controllerLogger);

                var updatedUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "IDontExist"
                };
                var result = controller.Put("*****@*****.**", updatedUser);
                result.Should().BeOfType <NotFoundObjectResult>();
                var notFoundResult = result as NotFoundObjectResult;
                AssertMessageProperty("Organization IDontExist not found", notFoundResult.Value);
            }
        }