コード例 #1
0
        public void UsersController_Post_SimulatedServerFailure()
        {
            var options = CreateNewContextOptions();

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

                var repo = new Mock <IHighFiveRepository>();
                repo.Setup(r => r.GetOrganizationByName(It.IsAny <String>())).Returns(organization);
                repo.Setup(r => r.AddUser(It.IsAny <HighFiveUser>())).Throws <HighFiveException>();
                UsersController controller = new UsersController(repo.Object, _controllerLogger);

                var newUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "Ariel Partners"
                };
                var result = controller.Post(newUser);
                result.Should().BeOfType <BadRequestObjectResult>();
                var badRequestResult = result as BadRequestObjectResult;
                AssertMessageProperty("Failed to add new user [email protected]", badRequestResult.Value);
            }
        }
コード例 #2
0
        public void UsersController_Post_DuplicateUser()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                var organization = new Organization()
                {
                    Name = "Ariel Partners"
                };
                context.Organizations.Add(organization);
                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 duplicateUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "Ariel Partners"
                };
                var result = controller.Post(duplicateUser);
                result.Should().BeOfType <BadRequestObjectResult>();
                var badRequestResult = result as BadRequestObjectResult;
                AssertMessageProperty("Failed to add new user [email protected]", badRequestResult.Value);
            }
        }
コード例 #3
0
        public void UsersController_Post_SunnyDay()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                var organization = new Organization()
                {
                    Name = "Ariel Partners"
                };
                context.Organizations.Add(organization);
                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 newUser = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "Ariel Partners"
                };
                var result = controller.Post(newUser);
                result.Should().BeOfType <CreatedResult>();
                var createdResult = result as CreatedResult;
                var user          = createdResult.Value as UserViewModel;
                user.Email.Should().Be("*****@*****.**");
            }
        }
コード例 #4
0
        public void UsersController_Post_UnknownOrganization()
        {
            var options = CreateNewContextOptions();

            using (var context = new HighFiveContext(_config, options))
            {
                HighFiveRepository repo       = new HighFiveRepository(context, _repoLogger);
                UsersController    controller = new UsersController(repo, _controllerLogger);
                var unknownOrgUser            = new UserViewModel()
                {
                    Email = "*****@*****.**", OrganizationName = "Bad Guys"
                };
                var result = controller.Post(unknownOrgUser);
                result.Should().BeOfType <NotFoundObjectResult>();
                var notFoundResult = result as NotFoundObjectResult;
                AssertMessageProperty("Unable to find organization Bad Guys", notFoundResult.Value);
            }
        }