private void SetupUnitOfWork()
        {
            _unitOfWork = new Mock <IUnitOfWork>();
            _unitOfWork.MockRepositories();

            _activity = Activity.ActivityFollowTopic("1", 1);
            _unitOfWork.Setup(
                u => u.ActivityRepository.Single(It.IsAny <Expression <Func <Activity, bool> > >(), It.IsAny <string>()))
            .Returns(() => _activity);
        }
        public IHttpActionResult Follow([FromBody] int topicId)
        {
            var userId = User.Identity.GetUserId();

            if (_unitOfWork.TopicFollowingRepository.Any(f => f.UserId == userId && f.TopicId == topicId))
            {
                return(BadRequest("User has already followed this topic."));
            }

            _unitOfWork.TopicFollowingRepository.Add(new TopicFollowing(userId, topicId));

            _unitOfWork.ActivityRepository.Add(Activity.ActivityFollowTopic(userId, topicId));

            _unitOfWork.Complete();

            return(Ok());
        }
Example #3
0
 public void ActviityAddQuestion_QuestionIdIsZeroOrNegativeOrUserIdIsNull_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Activity.ActivityAddQuestion("1", 0));
     Assert.Throws <ArgumentException>(() => Activity.ActivityAddQuestion("1", -1));
     Assert.Throws <ArgumentNullException>(() => Activity.ActivityFollowTopic(null, 1));
 }
Example #4
0
        public static Activity AddTestActivityTopicFollowingToDatabase(this iKnowContext context, int topicId)
        {
            var activity = Activity.ActivityFollowTopic(context.Users.First().Id, topicId);

            return(AddActivity(context, activity));
        }
Example #5
0
        public void ActviityFollowTopic_WhenCalled_ShouldReturnFollowTopicActivity()
        {
            var result = Activity.ActivityFollowTopic("1", 1);

            Assert.That(result.Type, Is.EqualTo(ActivityType.FollowTopic));
        }