コード例 #1
0
        public async Task User_Should_Follow_Another_User()
        {
            User   followerUser = new User((Nickname)"user1", (FullName)"test1 user1", Password.Create("password").Value, (Email)"*****@*****.**", "bio1");
            User   followedUser = new User((Nickname)"user2", (FullName)"test2 user2", Password.Create("password").Value, (Email)"*****@*****.**", "bio2");
            Result followResult;

            using (var session = _testFixture.OpenSession(_output))
            {
                await session.SaveAsync(followerUser);

                await session.SaveAsync(followedUser);
            }

            var followCommand = new FollowCommand(followerUser.ID, followedUser.Nickname);

            using (var session = _testFixture.OpenSession(_output))
            {
                var handler = new FollowCommandHandler(session, Log.Logger);
                followResult = await handler.Handle(followCommand, default);
            }

            using (new AssertionScope())
            {
                followResult.IsSuccess.Should().BeTrue();
                using (var session = _testFixture.OpenSession(_output))
                {
                    (await session.GetAsync <User>(followerUser.ID)).Followed.Count().Should().Be(1);
                    (await session.GetAsync <User>(followedUser.ID)).Followers.Count().Should().Be(1);
                }
            }
        }
コード例 #2
0
		public void Setup()
		{
			_consoleMock = new ConsoleMock();
			_userRepositoryMock = new UserRepositoryMock();

			_followCommandHandler = new FollowCommandHandler(_consoleMock.Object, _userRepositoryMock.Object);
		}
コード例 #3
0
        public async Task Should_Not_Follow_User_Twice()
        {
            User   followerUser = new User((Nickname)"user5", (FullName)"test5 user5", Password.Create("password").Value, (Email)"*****@*****.**", "bio5");
            User   followedUser = new User((Nickname)"user6", (FullName)"test6 user6", Password.Create("password").Value, (Email)"*****@*****.**", "bio6");
            Result followResult;

            using (var session = _testFixture.OpenSession(_output))
            {
                await session.SaveAsync(followerUser);

                await session.SaveAsync(followedUser);
            }

            var followCommand = new FollowCommand(followerUser.ID, followedUser.Nickname);

            using (var session = _testFixture.OpenSession(_output))
            {
                var handler = new FollowCommandHandler(session, Log.Logger);
                followResult = await handler.Handle(followCommand, default);
            }

            using (var session = _testFixture.OpenSession(_output))
            {
                var handler = new FollowCommandHandler(session, Log.Logger);
                followResult = await handler.Handle(followCommand, default);
            }

            using (new AssertionScope())
            {
                followResult.IsSuccess.Should()
                .BeFalse($"User [{followedUser.Nickname}] is already followed by user [{followerUser.Nickname}].");
                using (var session = _testFixture.OpenSession(_output))
                {
                    (await session.GetAsync <User>(followerUser.ID)).Followed.Count().Should().Be(1);
                    (await session.GetAsync <User>(followedUser.ID)).Followers.Count().Should().Be(1);
                }
            }
        }