Beispiel #1
0
 /// <summary>
 /// Convert a SimpleUser to an Invitee with no response status.
 /// </summary>
 /// <param name="u"></param>
 /// <returns></returns>
 public static Invitee FromSimpleUser(SimpleUser u)
 {
     return new Invitee
                {
                    FullName = u.FullName,
                    RelationshipName = u.RelationshipName,
                    UserId = u.UserId,
                    EmailAddress = u.EmailAddress,
                    MobilePhoneNumber = u.MobilePhoneNumber,
                    Response = null
                };
 }
        public void TestStatement()
        {
            //var store = new DocumentStore { ConnectionStringName = "RavenServer" };


            //store.Initialize();
            var store = GetTestStore();

            var subjectUser = CreateAndSaveTestUser(store,User1Id);
            
            var rewardGiver = new SimpleUser
            {
                UserId = User2Id,
                FullName = "Bloh bloh"
            };
            CreateRewardsForUser(10,subjectUser.ToSimpleUser(),store,100,rewardGiver,null);
            CreateRedeemsForUser(2,subjectUser.ToSimpleUser(),store,200);

            using (var session = store.OpenSession())
            {
                var rewards=session.Query<Reward>().ToList();
                var redeemed = session.Query<Redeem>().ToList();
            }

            var statement=RewardStatement.GetRewardStatementForUser(subjectUser.Id,store);

            Assert.AreEqual(statement.User.UserId,subjectUser.Id);
            Assert.AreEqual(statement.StatementCreatedDate.Date , DateTime.UtcNow.Date);
            
            Assert.AreEqual(statement.RewardStatementLines.Count,12);

            Assert.AreEqual(statement.RewardStatementLines.Count(sl => sl.LineType=="reward"),10);
            Assert.AreEqual(statement.RewardStatementLines.Count(sl => sl.LineType == "redeem"), 2);

            Assert.AreEqual(statement.RedeemedPointsTotal,400);
            Assert.AreEqual(statement.RewardPointsTotal, 1000);
            Assert.AreEqual(statement.TotalPoints, 600);
        }
Beispiel #3
0
 /// <summary>
 /// Generate an approval
 /// </summary>
 /// <param name="user">The user who made the approval</param>
 /// <returns>The generated approval object</returns>
 public static Approval CreateApproval(SimpleUser user)
 {
     return new Approval{ApprovalDate = DateTime.Now, ApprovedBy = user};
 }
Beispiel #4
0
 public static string GetRewardEmailBody(SimpleUser targetUser, SimpleUser fromUser, string message, int points)
 {
     return string.Format(@"<html><body><p>Congratulations {0}.</p><p>{1} gave you a reward worth {2} points! Message is {3}</p><p></p><p>Many thanks - The Illuminate Team</p></body></html>", targetUser.FullName, fromUser.FullName,points,message);
 }
Beispiel #5
0
        public static void TestNotification()
        {
            var store = new DocumentStore {ConnectionStringName = "RavenServer"};


            store.Initialize();
            using (var orgSession = store.OpenSession())
            {

                //alert! Alert!
                var simpleUser = new SimpleUser {FullName = "andy"};
                var recipients = new NotificationRecipient[] {new NotificationRecipient(),};
                var notify = new Notification
                                 {
                                     Body = "body",

                                     SendDate = DateTime.Now,
                                     Title = "HIG Alert",
                                     NotificationRecipients = new NotificationRecipient[]
                                                                  {
                                                                      new NotificationRecipient
                                                                          {

                                                                              NotificationDeliveryTypes =
                                                                                  NotificationDeliveryTypes
                                                                                      .Toast |
                                                                                  NotificationDeliveryTypes
                                                                                      .Email,
                                                                              Users = new SimpleUser[]
                                                                                          {
                                                                                              new SimpleUser
                                                                                                  {
                                                                                                      FullName
                                                                                                          =
                                                                                                          "andy"
                                                                                                  }
                                                                                          }
                                                                          }
                                                                  },
                                 };
                orgSession.Store(notify);
                orgSession.SaveChanges();


            }
        }
Beispiel #6
0
 public static void AddTasksToDB()
 {
     // create some tasks with no associated date in order to try and see the 0 dates. 
     var tasks = new List<Task>();
     for (int i = 0; i < 5; i++)
     {
         var task = new Task();
         var AssignedRoles = new List<Role>();
         var role = new Role();
         role.Name = "LineManager";
         AssignedRoles.Add(role);
         task.AssignedRoles = AssignedRoles;
         var ColsolidatedAssignees = new List<SimpleUser>();
         var user = new SimpleUser
                        {
                            EmailAddress = "*****@*****.**",
                            UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644",
                            RelationshipName = "LineManager"
                        };
         ColsolidatedAssignees.Add(user);
         task.ConsolidatedAssignees = ColsolidatedAssignees;
         //task.ConsolidatedAssignees[0].UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644";
         //task.ConsolidatedAssignees[0].EmailAddress = "*****@*****.**";
         task.ParentItemId = "sickness_d020fc7b-087d-43cb-93c4-8a89604958aa";
         var createdBy = new SimpleUser
                             {
                                 UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644",
                                 EmailAddress = "*****@*****.**"
                             };
         task.CreatedBy = createdBy;
         //task.DueDate = DateTime.MinValue;
         //task.ConsolidatedCompletionDate = DateTime.MinValue;
         var assignedUser = new SimpleUser();
         assignedUser.UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644";
         assignedUser.EmailAddress = "*****@*****.**";
         assignedUser.FullName = "Andy Evans";
         var assignedUsers = new List<SimpleUser> {assignedUser};
         task.AssignedUsers = assignedUsers;
         task.DueDate = DateTime.Now.Date;
         task.ConsolidatedCompletionDate = DateTime.Now.Date;
         task.Id = i.ToString();
         tasks.Add(task);
     }
     var store = new DocumentStore { ConnectionStringName = "RavenServer" };
     store.Initialize();
     using (var session = store.OpenSession())
     {
         foreach (var task in tasks)
         {
             session.Store(task);
             task.UpdateAssignees(session);
         }
         session.SaveChanges();
     }
 }
Beispiel #7
0
            void AddNotificationsToDB()
        {
            var notifications = new List<Notification>();
            for (var i = 0; i < 30; i++)
            {
                var notification = new Notification {Title = "notification"};
                var about = new SimpleUser
                                {
                                    FullName = "Andy Evans",
                                    EmailAddress = "*****@*****.**",
                                    UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644"
                                };
                notification.About = about;
                notification.Body = "you have a notification";
                notification.Id = i + "notification";
                var notificationrecipients = new List<NotificationRecipient>();
                var notificationrecipient = new NotificationRecipient();
                notification.NotificationRecipients = new[] {new NotificationRecipient { NotificationDeliveryTypes =
                                      NotificationDeliveryTypes.Email,
                                   Users =
                                       new []
                                           {
                                               new SimpleUser {EmailAddress = "*****@*****.**",FullName = "Andy Evans",UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644"}
                                               
                                           }}};
                notification.Read = true;
                notification.Sent = true;
                notification.SendDate = DateTime.Now;
                notification.ActualSentDate = DateTime.Now;
                notification.From = null;
                //notificationrecipient.Users = new IEnumerable<SimpleUser>();
                //var recipient = new SimpleUser();
                //recipient.EmailAddress= "*****@*****.**";
                //recipient.UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644"
                //var recipients = new IEnumerable<SimpleUser>();
                //notificationrecipient.Users = new IEnumerable<recipient>();
                ////notification.NotificationRecipients
                notifications.Add(notification);
            }
            var store = new DocumentStore { ConnectionStringName = "RavenServer" };
            store.Initialize();
            using (var session = store.OpenSession())
            {
                foreach (var notification in notifications)
                {
                    session.Store(notification);
                }

                session.SaveChanges();
            }
        }
        public void AggregateMultiUserMultiDayMultiHig2()
        {
            var otheruser = new SimpleUser { UserId = IlluminateDatabase.GenerateId<User>() };
            var otheruser2 = new SimpleUser { UserId = IlluminateDatabase.GenerateId<User>() };
            //ARRANGE
            var higs = new List<HIGEntry>
                           {
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now,
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = 1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddMilliseconds(1),
                                       Subject = otheruser,
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddMilliseconds(2),
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = 1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddMilliseconds(2),
                                       Subject = otheruser2,
                                       Value = 1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(1).AddMilliseconds(1),
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(1).AddMilliseconds(2),
                                       Subject = otheruser,
                                       Value = 0
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(1).AddMilliseconds(2),
                                       Subject = otheruser2,
                                       Value = 1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(2).AddMilliseconds(1),
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(2).AddMilliseconds(2),
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(2).AddMilliseconds(2),
                                       Subject = otheruser2,
                                       Value = 1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(3).AddMilliseconds(1),
                                       Subject = otheruser,
                                       Value = -2
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(3).AddMilliseconds(2),
                                       Subject = Orguser.ToSimpleUser(),
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(3).AddMilliseconds(3),
                                       Subject = otheruser,
                                       Value = -1
                                   },
                               new HIGEntry
                                   {
                                       CaptureDate = DateTime.Now.AddDays(3).AddMilliseconds(2),
                                       Subject = otheruser2,
                                       Value = 1
                                   }
                           };
            //1,-1, 1
            //-1,0, 1
            //-1,null, 1
            //-1,-1, 1


            //ACT
            var result = HIGHelper.Aggregate(higs);

            //-0.5, -0.66, 1

            //ASSERT
            Assert.AreEqual(0, result.Value);

        }
        public void TestPersona()
        {
            var store = GetTestStore();

            var subjectUser = CreateAndSaveTestUser(store,User1Id);
            var subjectUser2 = CreateAndSaveTestUser(store, User2Id);
            CreateAndSaveTestUser(store, User3Id);
            var attributes1 = new List<Attribute>
                                 {
                                     new Attribute {Id = "1", Name = "att1"},
                                     new Attribute {Id = "2", Name = "att2"}
                                 };
            var attributes2 = new List<Attribute>
                                 {
                                     new Attribute {Id = "1", Name = "att1"},
                                     new Attribute {Id = "3", Name = "att3"}
                                 };
            var rewardGiver1 = new SimpleUser
            {
                UserId = User2Id,
                FullName = "Bloh bloh"
            };
            var rewardGiver2= new SimpleUser
            {
                UserId = User3Id,
                FullName = "Blah blah"
            };
            CreateRewardsForUser(1,subjectUser.ToSimpleUser(),store,1,rewardGiver1,attributes1);
            CreateRewardsForUser(1, subjectUser.ToSimpleUser(), store, 1, rewardGiver2, attributes2);
            CreateRewardsForUser(1, subjectUser2.ToSimpleUser(), store, 1, rewardGiver1, attributes1);
            CreateRewardsForUser(1, subjectUser2.ToSimpleUser(), store, 1, rewardGiver2, attributes2);
            var personas=AttributePersona.GetAttributePersonasForUser(subjectUser.Id, store);
            Assert.AreEqual(3,personas.Count());
            Assert.AreEqual(2, personas.First(p => p.AttributeName == "att1").Total);
            Assert.AreEqual(1, personas.First(p => p.AttributeName == "att2").Total);
            Assert.AreEqual(1, personas.First(p => p.AttributeName == "att3").Total);
            Assert.IsTrue( personas.First(p => p.AttributeName == "att1").Givers.Select(o=>o.User.UserId).Contains(rewardGiver1.UserId));
            Assert.IsTrue(personas.First(p => p.AttributeName == "att1").Givers.Select(o => o.User.UserId).Contains(rewardGiver2.UserId));
            Assert.IsTrue(personas.First(p => p.AttributeName == "att2").Givers.Select(o => o.User.UserId).Contains(rewardGiver1.UserId));
            Assert.IsTrue(personas.First(p => p.AttributeName == "att3").Givers.Select(o => o.User.UserId).Contains(rewardGiver2.UserId));
            Assert.IsFalse(personas.First(p => p.AttributeName == "att2").Givers.Select(o => o.User.UserId).Contains(rewardGiver2.UserId));
            Assert.IsFalse(personas.First(p => p.AttributeName == "att3").Givers.Select(o => o.User.UserId).Contains(rewardGiver1.UserId));
        }
        public static void CreateRedeemsForUser(int number, SimpleUser user, IDocumentStore store, int pointsPer)
        {
            using (var session = store.OpenSession())
            {
                for (var i = 0; i < number; i++)
                {
                    var redeem = new Redeem()
                    {
                        Id = IlluminateDatabase.GenerateId<Redeem>(),
                        Message = "test message",
                        Points = pointsPer,
                        Date = DateTime.Now,
                        SubjectUser = user
                    };
                    session.Store(redeem);
                    session.SaveChanges();
                }

            }
        }
 public static void CreateRewardsForUser(int number,SimpleUser user,IDocumentStore store, int pointsPer,SimpleUser rewardGiver,List<Attribute> attributes)
 {
     using (var session = store.OpenSession())
     {
         for (var i = 0; i < number; i++)
         {
             var reward = new Reward
                          {
                              Id = IlluminateDatabase.GenerateId<Reward>(),
                              Message = "test message",
                              Points = pointsPer,
                              Date = DateTime.Now,
                              SubjectUser = user,
                              RewardGiver = rewardGiver,
                              Attributes = attributes
                          };
             session.Store(reward);
             session.SaveChanges();
         }
         
     }
 }