示例#1
0
        public void DALTest2()
        {
            using (StepMapDbContext ctx = new StepMapDbContext())
            {
                User u = new User();
                u.Email = "*****@*****.**";
                u.LastLogin = DateTime.UtcNow;
                u.Name = "test user";
                u.PasswordHash = "hash";
                u.UserRole = UserRole.Member;
                u.UserState = UserState.Active;

                Project p = new Project();
                p.Name = "test project";
                p.User = u;

                Step s = new Step();
                s.Name = "test step name";
                s.Project = p;

                Reminder r = new Reminder();
                r.Step = s;
                r.EmailAddress = "*****@*****.**";
                r.Message = "test message";
                r.SentDate = DateTime.UtcNow;
                r.Subject = "test subject";

                ctx.Projects.Add(p);
                ctx.Steps.Add(s);
                ctx.Reminders.Add(r);

                ctx.SaveChanges();

                try
                {
                    Project dp = ctx.Projects.Single(tu => tu.Name == "test project");
                    Assert.AreEqual(p.UserId, dp.UserId);
                    Step ds = dp.FinishedSteps.Single();
                    Assert.AreEqual(s.Name, ds.Name);
                    Reminder dr = ds.SentReminders.Single();
                    Assert.AreEqual(dr.EmailAddress, r.EmailAddress);
                    Assert.AreEqual(dr.Message, r.Message);
                    Assert.AreEqual(dr.SentDate, r.SentDate);
                    Assert.AreEqual(dr.Subject, r.Subject);
                }
                finally
                {
                    s.SentReminders.Clear();
                    p.FinishedSteps.Clear();
                    ctx.Reminders.Remove(r);
                    ctx.Steps.Remove(s);
                    ctx.Projects.Remove(p);
                    ctx.Users.Remove(u);
                    ctx.SaveChanges();
                }
            }
        }
示例#2
0
 private void SentFirstReminder(User user, Project project, Step step)
 {
     using (var ctx = new StepMapDbContext())
     {
         //TODO: Config, customize, randomize
         Reminder reminder = new Reminder()
         {
             EmailAddress = user.Email,
             Message = string.Format("Your current step ({0}) in project {1} is delayed! Get yourself together!", step.Name, project.Name), //LOCSTR
             Subject = "First reminder", //LOCSTR
             SentDate = DateTime.UtcNow,
             StepId = step.Id
         };
         ctx.Reminders.Add(reminder);
         notificationManager.SendEmail(user, reminder.Subject, reminder.Message);
         ctx.SaveChanges();
     }
 }