コード例 #1
0
        public async Task AlredyFriendOrSendFriendRequestAsyncShouldReturnCorrectBool()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var newFriendShip = new Friend
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            var newFriendShipRequest = new FriendRequest
            {
                SenderId   = "5",
                ReceiverId = "6",
                Status     = FriendRequestStatus.Pending,
            };

            await friendRepository.AddAsync(newFriendShip);

            await friendRepository.SaveChangesAsync();

            await friendRequestRepository.AddAsync(newFriendShipRequest);

            await friendRequestRepository.SaveChangesAsync();

            var service = new FriendService(friendRequestRepository, friendRepository);

            var resultTrueAlreadyFriend = await service.AlredyFriendOrSendFriendRequestAsync("1", "2");

            var resultTrueSendFriendToHim = await service.AlredyFriendOrSendFriendRequestAsync("1", "1");

            var resultTrueAlredySendFriend = await service.AlredyFriendOrSendFriendRequestAsync("5", "6");

            var resultFalse = await service.AlredyFriendOrSendFriendRequestAsync("10", "11");

            Assert.True(resultTrueAlreadyFriend);
            Assert.True(resultTrueSendFriendToHim);
            Assert.True(resultTrueAlredySendFriend);
            Assert.False(resultFalse);
        }