Example #1
0
        /// <summary>
        /// Ensures that the User with the specified userName
        /// exists in the database
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="emailAddress"></param>
        /// <returns></returns>
        public static User Ensure(string userName, Database db = null)
        {
            User user = GetByUserName(userName, db);

            if (user == null)
            {
                user = User.Create(userName, db);
            }

            return(user);
        }
Example #2
0
        private static User SetCurrentUser(string userName, ApplicationRegistryService svc)
        {
            IHttpContext ctx = Substitute.For <IHttpContext>();

            ctx.Request = Substitute.For <IRequest>();
            ctx.Request.Url.Returns(new Uri("http://test.cxm"));
            NameValueCollection headers = new NameValueCollection();

            headers["REMOTE_ADDR"] = "127.0.0.1";
            ctx.Request.Headers.Returns(headers);
            ctx.Response = Substitute.For <IResponse>();
            CookieCollection Cookies       = new CookieCollection();
            Cookie           sessionCookie = new Cookie(Session.CookieName, "0368c7fde0a40272d42e14e224d37761dbccef665116ccb063ae31aaa7708d72");

            Cookies.Add(sessionCookie);
            ctx.Request.Cookies.Returns(Cookies);
            ctx.Response.Cookies.Returns(Cookies);
            svc.HttpContext = ctx;
            SessionCollection sessions = Session.LoadAll();

            sessions.Delete();
            UserCollection users = User.LoadAll();

            users.Delete();
            User    result  = User.Create(userName);
            Session session = Session.Get(ctx);

            session.UserId = result.Id;
            session.Save();
            IEnumerable <Organization> organizations = svc.ApplicationRegistrationRepository.RetrieveAll <Organization>();

            organizations.Each(o => svc.ApplicationRegistrationRepository.Delete(o));
            Expect.AreEqual(0, svc.ApplicationRegistrationRepository.RetrieveAll <Organization>().Count());
            IEnumerable <ApplicationRegistration.Data.Application> apps = svc.ApplicationRegistrationRepository.RetrieveAll <ApplicationRegistration.Data.Application>();

            apps.Each(a => svc.ApplicationRegistrationRepository.Delete(a));
            Expect.AreEqual(0, svc.ApplicationRegistrationRepository.RetrieveAll <ApplicationRegistration.Data.Application>().Count());
            svc.ApplicationRegistrationRepository.RetrieveAll <Machine>().Each(h => svc.ApplicationRegistrationRepository.Delete(h));
            return(result);
        }