public static void ClassCleanup()
        {
            Mock<IUserHelper> UserHelper = new Mock<IUserHelper>(); ;
            UserHelper.Setup(x => x.GetLoggedUserRole(It.IsAny<HttpRequestMessage>())).Returns(new Role { Id = 1, Name = "Administrator" });

            var userController = new UserController(UserHelper.Object);

            using (var context = new TravelPlannerEntities())
            {
                var users = context.User.Where(x => x.Username == TestUserAdmnistratorName
                    || x.Username == TestUserManagerName
                    || x.Username == TestUserRegularUserName
                    || x.Username.Contains(RegisterUserTestName));

                /// Remove trips
                foreach (var user in users)
                {
                    var trips = context.Trip.Where(x => x.UserId == user.Id);
                    context.Trip.RemoveRange(trips);
                }

                /// Remove users
                context.User.RemoveRange(users);
                context.SaveChanges();
            }
        }
        public UserControllerTest()
        {
            var dataDirectory = ConfigurationManager.AppSettings["DataDirectory"];
            var absoluteDataDirectory = Path.GetFullPath(dataDirectory);
            AppDomain.CurrentDomain.SetData("DataDirectory", absoluteDataDirectory);

            SetCurrentIdentity(GetInitialAdminUser(), AdminRole);

            UserController = new UserController(UserHelper.Object);
        }
        internal void SetCurrentIdentity(User user, Role role)
        {
            var identity = new GenericIdentity(user.Username);
            identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", user.Id.ToString()));

            Thread.CurrentPrincipal = new GenericPrincipal(identity, new[] { role.Name });

            UserHelper.Setup(x => x.GetLoggedUser(It.IsAny<HttpRequestMessage>())).Returns(user);
            UserHelper.Setup(x => x.GetLoggedUserRole(It.IsAny<HttpRequestMessage>())).Returns(new Role { Id = role.Id, Name = role.Name });

            UserController = new UserController(UserHelper.Object);
        }
        public static void ClassSetup(TestContext context)
        {
            Mock<IUserHelper> UserHelper = new Mock<IUserHelper>(); ;
            UserHelper.Setup(x => x.GetLoggedUser(It.IsAny<HttpRequestMessage>())).Returns(GetInitialAdminUser());
            UserHelper.Setup(x => x.GetLoggedUserRole(It.IsAny<HttpRequestMessage>())).Returns(new Role { Id = 1, Name = "Administrator" });

            var userController = new UserController(UserHelper.Object);

            using (var entityContext = new TravelPlannerEntities())
            {
                if (!entityContext.User.Any(x => x.Username == TestUserAdmnistratorName))
                {
                    userController.CreateOrUpdateUser(GetAdministratorTestUser());
                }
                if (!entityContext.User.Any(x => x.Username == TestUserManagerName))
                {
                    userController.CreateOrUpdateUser(GetManagerTestUser());
                }
                if (!entityContext.User.Any(x => x.Username == TestUserRegularUserName))
                {
                    userController.CreateOrUpdateUser(GetRegularUserTestUser());
                }
            }
        }