Exemplo n.º 1
0
        public ActionResult Data(int location)
        {
            // get locations this user has access to
            var locations = new LinqMetaData().Location.WithPermissions().ToList();

            Location = locations.ElementAt(Math.Abs(location % locations.Count()));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            return(View(this));
        }
Exemplo n.º 2
0
        public ActionResult Reset(ResetModel model)
        {
            string message;

            // Email address must be specified.
            if (!string.IsNullOrWhiteSpace(model.Email))
            {
                // Get all accounts with that email address; check if there are any.
                var accounts = new LinqMetaData().User.Where(u => u.EmailAddress == model.Email);
                if (accounts.Any())
                {
                    // Have some accounts. Filter out all but the unrestricted ones.
                    accounts = GetUnrestictedOnly(accounts, model.UserName, out message);
                    if (accounts.Any())
                    {
                        // Have unrestricted accounts. They will be reset. Assume there's
                        // more than one. If more than one, we don't necessarily know the
                        // person's name.
                        string firstName = null;
                        string lastName  = null;
                        if (accounts.Count() == 1)
                        {
                            // Only one. So get person's name.
                            var account = accounts.First();
                            firstName = account.FirstName;
                            lastName  = account.LastName;
                        }

                        // Create restriction on each account, send email and tell user it's done.
                        var key = CreateRestriction(accounts, model.Email, firstName != null);
                        SendResetEmail(model.Email, key, firstName, lastName);
                        return(RedirectToAction("ResetSuccess"));
                    }
                }
                else
                {
                    // No accounts with the specified email address. Tell user.
                    message = Account.Invalid_EmailNotMatched;
                }
            }
            else
            {
                // No email address. Tell user to enter one.
                message = Account.Invalid_EmailNotSpecified;
            }

            ModelState.AddModelError("", message);

            // If we got this far, something failed, redisplay form.
            return(View());
        }
        public void User_Can_Delete_Message()
        {
            // pick two users to send to
            var users = new LinqMetaData().Organization.First(x => x.Users.Count(y => y.Settings.Any(z => z.Name == "SupportUser")) > 1).Users;

            Assert.IsTrue(users.Count() > 1);
            var fromUser = users.First(x => x.Settings.Any(y => y.Name == "SupportUser"));
            var toUser   = users.Last(x => x.Settings.Any(y => y.Name == "SupportUser"));

            var controller = Mock();
            var request    = controller.Mock(x => x.HttpContext.Request);

            request.SetupGet(x => x["Send"]).Returns("true");
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(fromUser.Username));
            controller.Invoke(x => x.Compose(new ComposeMail
            {
                Body    = "This is a test.",
                Subject = "Test Subject",
                To      =
                    toUser.Settings.First(y => y.Name == "SupportUser").Value + '@' +
                    SupportController.DOMAIN
            }));
            Thread.Sleep(5000); // give exchange time to deliver it

            // check the inbox of the receiver
            using (var imap = SupportController.EnsureConnection(toUser))
            {
                var msgCount = imap.SelectMailbox("INBOX").NumMsg;
                Assert.IsTrue(msgCount > 0);

                var msgs =
                    imap.Search(SearchCondition.Deleted().Not()).Select(
                        x =>
                        imap.GetMessage(x, true, true,
                                        new[] { "date", "subject", "from", "content-type", "to", "cc", "message-id" }));
                var message =
                    msgs.Where(x => x.Subject.Contains("Test Subject")).
                    OrderByDescending(x => x.Date).FirstOrDefault();
                Assert.IsNotNull(message);

                message = imap.GetMessage(message.Uid, false, false);
                Assert.IsTrue(message.Body.Contains("This is a test."));

                controller = Mock();
                controller.Invoke(x => x.Delete("INBOX", message.Uid));
            }
        }
        public void User_Can_View_Patient_Treatments()
        {
            // find a unique count of treatments
            var counts =
                new LinqMetaData().Patient
                .Where(x => x.Location.Organization.Users.Any())
                .Select(x => new { Patient = x, Count = x.Treatments.Count() }).ToList();
            var patientCount = counts.FirstOrDefault(x => counts.Count(y => y.Count == x.Count) == 1);

            Assert.IsNotNull(patientCount);
            var patient = patientCount.Patient;

            // make sure search is accessible
            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(patient.Location.Organization.Users.First().Username));
            controller.Invoke(x => x.Index(null, patient.PatientId, null));

            // get user from controller
            var user = new LinqMetaData().User.SingleOrDefault(x => x.Username == controller.HttpContext.User.Identity.Name);

            Assert.IsNotNull(user);
            Assert.IsFalse(user.Username == "");

            // make sure the data table information was added to view data properly
            Assert.IsNotNull(controller.ViewData["DataTablesModels"] as Dictionary <string, object>);
            Assert.IsNotNull(((Dictionary <string, object>)
                              controller.ViewData["DataTablesModels"]).FirstOrDefault());

            var id = ((IDataTablesInitializationModel)
                      ((Dictionary <string, object>)
                       controller.ViewData["DataTablesModels"]).First().Value).ID;

            // do a search for that patient id
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(patient.Location.Organization.Users.First().Username));
            controller.Invoke(x => x.Index(null, patient.PatientId, new DataTablesRequestModel
            {
                sEcho       = 1,
                epicTableId = id
            }));

            // look for count of records
            Assert.IsTrue(controller.Response.Output.ToString().Contains("\"iTotalRecords\":" + patient.Treatments.Count()));
        }
Exemplo n.º 5
0
        public void Minimum_Of_Three_Roles()
        {
            var roles = new LinqMetaData().Role;

            Assert.IsTrue(roles.Count() >= 3);
        }