public void Do_not_start_new_round_when_start_date_less_than_one_week_ago()
        {
            // Assign
            var       mockedEmailService         = new Mock <IEmailService>();
            const int lengthOfReviewRoundInWeeks = 1;
            const int reviewLengthMinusOneDay    = lengthOfReviewRoundInWeeks * 7 - 1;
            var       configuration = new ReviewConfiguration
            {
                Name = "test config",
                LengthOfReviewRoundInWeeks = lengthOfReviewRoundInWeeks,
                ReviewRounds = new List <ReviewRound>
                {
                    new ReviewRound {
                        StartDate = DateTime.UtcNow.AddDays(-reviewLengthMinusOneDay), Active = true
                    }
                }
            };

            DatabaseContext.ReviewConfigurations.Add(configuration);
            DatabaseContext.SaveChanges();
            IReviewService reviewService = new ReviewService(DatabaseContext, mockedEmailService.Object);

            // Act
            reviewService.StartNewReviewRounds();

            // Assert
            Assert.AreEqual(1, DatabaseContext.ReviewConfigurations.First().ReviewRounds.Count());
            var currentReviewRound = DatabaseContext.ReviewConfigurations.First().GetCurrentReviewRound();

            Assert.IsNotNull(currentReviewRound);
            Assert.LessOrEqual(currentReviewRound.StartDate, DateTime.UtcNow.AddDays(-5));
        }
示例#2
0
        private static void AddSumsToReportData(ReviewConfiguration review, Report report)
        {
            var stackRankingSums = new ReportDataRow {
                Title  = "Total",
                Values = GetSums(review.ReviewRoundsInOrder.Count(), report.ReportData)
            };

            report.ReportData.Add(stackRankingSums);
        }
示例#3
0
 private static Report CreateReport(string title, ReviewConfiguration review, ReviewCategory category)
 {
     return(new Report {
         CategoryCount = 1,
         Title = title,
         ReviewName = review.Name,
         Description = category.Description,
         XAxisLabels = review.ReviewRoundsInOrder.Select(round => round.StartDate.ToShortDateString()).ToList()
     });
 }
示例#4
0
        private static UserProfile RetrieveValidPeerOrFail(int peerId, ReviewConfiguration review)
        {
            var peer = review.Peers.SingleOrDefault(p => p.Id == peerId);

            if (peer == null)
            {
                throw new ArgumentNullException("peerId", "No peer with the given id exists in this review!");
            }
            return(peer);
        }
示例#5
0
        private static ReviewCategory RetrieveValidCategoryOrFail(int categoryId, ReviewConfiguration review)
        {
            var category = review.Categories.SingleOrDefault(p => p.Id == categoryId);

            if (category == null)
            {
                throw new ArgumentNullException("categoryId", "No category with the given id exists in this review!");
            }
            return(category);
        }
        private static void SaveFeedback(IFeedbackService feedbackService, ReviewConfiguration review,
                                         AssessmentInfo assessment, int rating, string category)
        {
            var userNameReviewer     = assessment.Reviewer == "(me)" ? DefaultUserName : assessment.Reviewer;
            var userNameReviewedPeer = assessment.ReviewedPeer == "(me)" ? DefaultUserName : assessment.ReviewedPeer;

            feedbackService.SaveFeedback(review.Peers.First(p => p.UserName == userNameReviewer).EmailAddress,
                                         GetFeedback(review, rating, category,
                                                     review.Peers.First(p => p.UserName == userNameReviewedPeer)));
        }
示例#7
0
        private void GivenIOwnAReview(string reviewName)
        {
            var thisIsMe            = ScenarioContext.Current.Get <UserProfile>();
            var reviewConfiguration = new ReviewConfiguration {
                Name = reviewName, LengthOfReviewRoundInWeeks = 1
            };

            using (var ctx = new DelayedDatabaseContext()) {
                Console.WriteLine("Writing review to DB");
                reviewConfiguration.Peers.Add(ctx.UserProfiles.Find(thisIsMe.Id));
                ctx.ReviewConfigurations.Add(reviewConfiguration);
                ctx.SaveChanges();
                ScenarioContext.Current.Set(reviewConfiguration);
            }
        }
示例#8
0
        public void GivenIAmNotPartOfReview(string reviewName)
        {
            var reviewConfiguration = new ReviewConfiguration {
                Name = reviewName, LengthOfReviewRoundInWeeks = 1
            };

            using (var ctx = new DelayedDatabaseContext()) {
                Console.WriteLine("Writing review to DB");
                reviewConfiguration.Peers.Add(new UserProfile {
                    EmailAddress = "*****@*****.**", UserName = "******"
                });
                ctx.ReviewConfigurations.Add(reviewConfiguration);
                ctx.SaveChanges();
                ScenarioContext.Current.Set(reviewConfiguration);
            }
        }
        private static FeedbackViewModel GetFeedback(ReviewConfiguration review, int rating,
                                                     string categoryName = "Speed", UserProfile reviewedPeer = null)
        {
            ReviewCategory category = review.Categories.First(cat => cat.Name == categoryName);
            var            feedback = new FeedbackViewModel
            {
                ReviewId = review.Id,
                CategoriesWithPeersAndRatings =
                {
                    new CategoryWithPeersAndRatings
                    {
                        Category = new CategoryShowModel{
                            Id = category.Id, Name = category.Name
                        },
                        PeersWithRatings = reviewedPeer != null
                                                                                                                  ? new List <PeerWithRating>
                        {
                            new PeerWithRating
                            {
                                Peer = new PeerShowModel
                                {
                                    Id           = reviewedPeer.Id,
                                    UserName     = reviewedPeer.UserName,
                                    EmailAddress = reviewedPeer.EmailAddress
                                },
                                Rating = rating
                            }
                        }
                                                                                                                  : review.Peers.Select(
                            peer => new PeerWithRating
                        {
                            Peer = new PeerShowModel
                            {
                                Id           = peer.Id,
                                UserName     = peer.UserName,
                                EmailAddress = peer.EmailAddress
                            },
                            Rating = rating
                        }).ToList()
                    }
                }
            };

            return(feedback);
        }
示例#10
0
        private void AddAndStartNewRound(ReviewConfiguration reviewConfiguration)
        {
            var activeRound = reviewConfiguration.GetCurrentReviewRound();

            if (activeRound != null)
            {
                activeRound.Active = false;
            }

            reviewConfiguration.ReviewRounds.Add(new ReviewRound
            {
                Active    = true,
                StartDate = activeRound != null
                                                                                                 ? activeRound.StartDate.AddDays(
                    reviewConfiguration.LengthOfReviewRoundInWeeks * 7).Date
                                                                                                 : DateTime.UtcNow.Date
            });

            _databaseContext.SaveChanges();
            //_emailService.SendInvitationEmailsForReview(reviewConfiguration.Id);
        }
示例#11
0
        public void GivenIOwnAReviewWithTwoPeers()
        {
            var peers = new List <UserProfile>();

            peers.Add(ScenarioContext.Current.Get <UserProfile>());
            peers.Add(new UserProfile {
                EmailAddress = "Anton" + _emailDomain, UserName = "******"
            });
            peers.Add(new UserProfile {
                EmailAddress = "Admin" + _emailDomain, UserName = "******"
            });
            var reviewConfiguration = new ReviewConfiguration {
                Name = "NewReview", LengthOfReviewRoundInWeeks = 1, Peers = peers
            };

            using (var ctx = new DelayedDatabaseContext()) {
                Console.WriteLine("Writing review to DB");
                ctx.ReviewConfigurations.Add(reviewConfiguration);
                ctx.SaveChanges();
            }
            ScenarioContext.Current.Set(reviewConfiguration);
        }
        public void Should_save_review_with_two_feedback_rounds()
        {
            var configuration = new ReviewConfiguration
            {
                Name = "test config",
                LengthOfReviewRoundInWeeks = 1,
                ReviewRounds = new List <ReviewRound>
                {
                    new ReviewRound {
                        StartDate = DateTime.UtcNow.AddDays(-1), Active = true
                    },
                    new ReviewRound {
                        StartDate = DateTime.UtcNow.AddDays(30), Active = false
                    },
                }
            };

            DatabaseContext.ReviewConfigurations.Add(configuration);
            DatabaseContext.SaveChanges();
            CreateNewContext();

            Assert.AreEqual(2, DatabaseContext.ReviewConfigurations.First().ReviewRounds.Count());
        }
        private void SendMailToPeersIfAllHaveProvidedFeedback(ReviewConfiguration review)
        {
            //_db.Entry(review).Collection(c => c.Peers).Load();
            //_db.Entry(review).Collection(c => c.Feedback).Load();

            if (review.Peers.Any(peer => review.GetCurrentFeedback().Select(f => f.Reviewer).All(r => r.Id != peer.Id)))
            {
                return;
            }

            var smtpClient = new SmtpClient();

            foreach (var peer in review.Peers)
            {
                var message = new MailMessage(EmailService.DefaultContactEmail, peer.EmailAddress)
                {
                    Subject = "Review Complete",
                    Body    = GetMailBodyForFinishedReview(peer.UserName, review.Id, review.Name)
                };

                smtpClient.Send(message);
            }
        }
示例#14
0
 private static ReviewCategory RetrieveValidCategoryOrFail(int categoryId, ReviewConfiguration review)
 {
     var category = review.Categories.SingleOrDefault(p => p.Id == categoryId);
     if (category == null) {
         throw new ArgumentNullException("categoryId", "No category with the given id exists in this review!");
     }
     return category;
 }
示例#15
0
 private static UserProfile RetrieveValidPeerOrFail(int peerId, ReviewConfiguration review)
 {
     var peer = review.Peers.SingleOrDefault(p => p.Id == peerId);
     if (peer == null) {
         throw new ArgumentNullException("peerId", "No peer with the given id exists in this review!");
     }
     return peer;
 }
示例#16
0
 private static Report CreateReport(string title, ReviewConfiguration review, ReviewCategory category)
 {
     return new Report {
         CategoryCount = 1,
         Title = title,
         ReviewName = review.Name,
         Description = category.Description,
         XAxisLabels = review.ReviewRoundsInOrder.Select(round => round.StartDate.ToShortDateString()).ToList()
     };
 }
示例#17
0
 private static string GetCommaSeparatedUserNames(IEnumerable<int> selectedUserIds, ReviewConfiguration review)
 {
     var userNames = "";
     foreach (var id in selectedUserIds) {
         if (userNames != "") {
             userNames += ", ";
         }
         userNames += RetrieveValidPeerOrFail(id, review).UserName;
     }
     return userNames;
 }
示例#18
0
 private static void AddSumsToReportData(ReviewConfiguration review, Report report)
 {
     var stackRankingSums = new ReportDataRow {
         Title = "Total",
         Values = GetSums(review.ReviewRoundsInOrder.Count(), report.ReportData)
     };
     report.ReportData.Add(stackRankingSums);
 }
        private static List <int> SelectedPeerIds(string peer, ReviewConfiguration review)
        {
            var peers = Regex.Split(peer, @" and ");

            return(peers.Select(userName => review.Peers.First(p => p.UserName == userName).Id).ToList());
        }
 private static FeedbackViewModel GetFeedback(ReviewConfiguration review, int rating,
     string categoryName = "Speed", UserProfile reviewedPeer = null)
 {
     ReviewCategory category = review.Categories.First(cat => cat.Name == categoryName);
     var feedback = new FeedbackViewModel
                        {
                            ReviewId = review.Id,
                            CategoriesWithPeersAndRatings =
                                {
                                    new CategoryWithPeersAndRatings
                                        {
                                            Category = new CategoryShowModel {Id = category.Id, Name = category.Name},
                                            PeersWithRatings = reviewedPeer != null
                                                                   ? new List<PeerWithRating>
                                                                         {
                                                                             new PeerWithRating
                                                                                 {
                                                                                     Peer = new PeerShowModel
                                                                                                {
                                                                                                    Id = reviewedPeer.Id,
                                                                                                    UserName = reviewedPeer.UserName,
                                                                                                    EmailAddress = reviewedPeer.EmailAddress
                                                                                                },
                                                                                     Rating = rating
                                                                                 }
                                                                         }
                                                                   : review.Peers.Select(
                                                                       peer => new PeerWithRating
                                                                                   {
                                                                                       Peer = new PeerShowModel
                                                                                                  {
                                                                                                      Id = peer.Id,
                                                                                                      UserName = peer.UserName,
                                                                                                      EmailAddress = peer.EmailAddress
                                                                                                  },
                                                                                       Rating = rating
                                                                                   }).ToList()
                                        }
                                }
                        };
     return feedback;
 }
        private static void SaveFeedback(IFeedbackService feedbackService, ReviewConfiguration review,
            AssessmentInfo assessment, int rating, string category)
        {
            var userNameReviewer = assessment.Reviewer == "(me)" ? DefaultUserName : assessment.Reviewer;
            var userNameReviewedPeer = assessment.ReviewedPeer == "(me)" ? DefaultUserName : assessment.ReviewedPeer;

            feedbackService.SaveFeedback(review.Peers.First(p => p.UserName == userNameReviewer).EmailAddress,
                                         GetFeedback(review, rating, category,
                                                     review.Peers.First(p => p.UserName == userNameReviewedPeer)));
        }
示例#22
0
        private static string GetCommaSeparatedUserNames(IEnumerable <int> selectedUserIds, ReviewConfiguration review)
        {
            var userNames = "";

            foreach (var id in selectedUserIds)
            {
                if (userNames != "")
                {
                    userNames += ", ";
                }
                userNames += RetrieveValidPeerOrFail(id, review).UserName;
            }
            return(userNames);
        }