public bool ChangeReviewStatus(string identity, int topicId, TopicReviewStatus status)
 {
     try
     {
         var user = GetUserByIdentity(identity);
         if (!DbContext.TopicReviews.Any(rs => rs.TopicId == topicId && rs.ReviewerId == user.Id))
         {
             var review = new TopicReview()
             {
                 TopicId    = topicId,
                 ReviewerId = user.Id,
                 Status     = status.Status
             };
             DbContext.TopicReviews.Add(review);
         }
         else
         {
             var review =
                 DbContext.TopicReviews.Include(r => r.Reviewer)
                 .Single(rs => rs.TopicId == topicId && rs.ReviewerId == user.Id);
             review.Status = status.Status;
             DbContext.Update(review);
         }
         DbContext.SaveChanges();
         return(true);
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
 }
        public void ChangeTopicStatusTestForConflict()
        {
            TopicStatus.Status = "Done";
            var reviewer = new User
            {
                Id    = 4,
                Email = "*****@*****.**",
                Role  = "Reviewer"
            };
            var reviewerUser = new TopicUser
            {
                TopicId = _tester.TopicOne.Id,
                UserId  = reviewer.Id,
                Role    = reviewer.Role
            };
            var topicReview = new TopicReview
            {
                TopicId    = _tester.TopicOne.Id,
                ReviewerId = reviewer.Id
            };

            _tester.TestControllerWithMockData()
            .WithDbContext(dbContext => dbContext
                           .WithSet <User>(db => db.Add(reviewer))
                           .WithSet <TopicUser>(db => db.Add(reviewerUser))
                           .WithSet <TopicReview>(db => db.Add(topicReview)))
            .Calling(c => c.ChangeStatus(_tester.TopicOne.Id, TopicStatus))
            .ShouldReturn()
            .StatusCode(409);
        }
Ejemplo n.º 3
0
 public TopicReviewResult(TopicReview review)
 {
     Status = new TopicReviewStatus()
     {
         Status = review.Status
     };
     TimeStamp = review.TimeStamp;
     if (review.Reviewer != null)
     {
         Reviewer = new UserResult(review.Reviewer);
     }
 }
Ejemplo n.º 4
0
 public TopicsControllerReviewsTest()
 {
     _tester           = new ControllerTester <TopicsController>();
     TopicReviewStatus = new TopicReviewStatus {
         Status = "Reviewed"
     };
     TopicReview = new TopicReview
     {
         TopicId    = _tester.TopicOne.Id,
         ReviewerId = _tester.Reviewer.Id,
         Status     = "InReview"
     };
 }