public async Task GivenValidRequest_WhenTheFollowerTriesToUnfollowThemselves_ThrowsApiException()
        {
            // Arrange, verify the user is not currently being followed by the requester
            var followUserCommand = new FollowUserCommand(TestConstants.TestUserName);

            // Act
            var request = new FollowUserCommandHandler(CurrentUserContext, Context, Mapper, UserManager, new DateTimeTest());

            // Assert
            await Should.ThrowAsync <ConduitApiException>(async() =>
            {
                await request.Handle(followUserCommand, CancellationToken.None);
            });
        }
        public async Task GivenValidRequest_WhenTheFollowerDoesNotExist_ThrowsApiException()
        {
            // Arrange, verify the user is not currently being followed by the requester
            var followUserCommand = new FollowUserCommand("this.user.does.not.exist");

            // Act
            var request = new FollowUserCommandHandler(CurrentUserContext, Context, Mapper, UserManager, new DateTimeTest());

            // Assert
            await Should.ThrowAsync <ConduitApiException>(async() =>
            {
                await request.Handle(followUserCommand, CancellationToken.None);
            });
        }
        public async Task GivenValidRequest_WhenTheFollowerExists_ReturnsProfileViewModelAndAddsFollowee()
        {
            // Arrange, verify the user is not currently being followed by the requester
            var followUserCommand = new FollowUserCommand("test.user2");
            var user2             = Context.Users.FirstOrDefault(u => u.UserName == "test.user2");

            user2.ShouldNotBeNull();
            user2.Followers.ShouldBeEmpty();

            // Act
            var request  = new FollowUserCommandHandler(CurrentUserContext, Context, Mapper, UserManager, new DateTimeTest());
            var response = await request.Handle(followUserCommand, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <ProfileViewModel>();
            response.Profile.ShouldNotBeNull();
            response.Profile.ShouldBeOfType <ProfileDto>();
            user2.Followers.ShouldNotBeEmpty();
        }
コード例 #4
0
        public async Task InputDataOk_Called_ReturnUnit()
        {
            // Arrange
            var userId  = Guid.NewGuid();
            var fixture = new Fixture();

            var followUserInputModel = fixture.Create <FollowUserInputModel>();

            var userRepositoryMock = new Mock <IUserRepository>();

            var followUserCommand = new FollowUserCommand(userId, followUserInputModel.FolloweeId);

            var followUserCommandHandler = new FollowUserCommandHandler(userRepositoryMock.Object);

            // Act
            var unitValue = await followUserCommandHandler.Handle(followUserCommand, new CancellationToken());

            // Assert
            var userFollower = new UserFollower(userId, followUserInputModel.FolloweeId);

            userRepositoryMock.Verify(ur => ur.AddFollowee(userId, followUserInputModel.FolloweeId), Times.Once);
        }