コード例 #1
0
        public void SetCorrectIsFriend_WhenUserIdIsNotEmpty()
        {
            // Arrange
            var mockedMapperService = new Mock <IMapperService>();

            mockedMapperService.Setup(x => x.MapObject <SearchUserViewModel>(It.IsAny <CustomUser>())).Returns(() => new SearchUserViewModel());
            var mockedImageService = new Mock <IImageService>();

            mockedImageService.Setup(x => x.ByteArrayToImageUrl(It.IsAny <byte[]>())).Returns("some-url");
            var mockedUserService = new Mock <IUserService>();
            var user = new CustomUser()
            {
                Id = 1
            };

            mockedUserService.Setup(x => x.GetByIndentityId(It.IsAny <string>())).Returns(user);
            var mockedFriendService = new Mock <IFriendService>();

            mockedFriendService.Setup(x => x.GetAllUserFriendsIds(It.IsAny <int>())).Returns(new List <int>()
            {
                2, 3
            });

            var viewModelService = new ViewModelService(
                mockedMapperService.Object,
                mockedImageService.Object,
                mockedUserService.Object,
                mockedFriendService.Object);
            var users = new List <CustomUser>()
            {
                new CustomUser()
                {
                    Id = 1, ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    Id = 2, ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    Id = 3, ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                }
            };
            string userId = "user-xx-id";

            // Act
            var result = viewModelService.GetMappedSearchedUsers(users, userId);

            // Assert
            Assert.That(result.Where(x => x.IsFriend == true).Count() == 2);
        }
コード例 #2
0
        public void CallFriendService_GetAllUserFriendsIdsOnce_WhenUserIdIsNotEmpty()
        {
            // Arrange
            var mockedMapperService = new Mock <IMapperService>();
            var mappedUser          = new SearchUserViewModel();

            mockedMapperService.Setup(x => x.MapObject <SearchUserViewModel>(It.IsAny <CustomUser>())).Returns(mappedUser);
            var mockedImageService = new Mock <IImageService>();

            mockedImageService.Setup(x => x.ByteArrayToImageUrl(It.IsAny <byte[]>())).Returns("some-url");
            var mockedUserService = new Mock <IUserService>();
            var user = new CustomUser()
            {
                Id = 1
            };

            mockedUserService.Setup(x => x.GetByIndentityId(It.IsAny <string>())).Returns(user);
            var mockedFriendService = new Mock <IFriendService>();

            mockedFriendService.Setup(x => x.GetAllUserFriendsIds(It.IsAny <int>())).Returns(new List <int>());

            var viewModelService = new ViewModelService(
                mockedMapperService.Object,
                mockedImageService.Object,
                mockedUserService.Object,
                mockedFriendService.Object);
            var users = new List <CustomUser>()
            {
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                }
            };
            string userId = "user-xx-id";

            // Act
            viewModelService.GetMappedSearchedUsers(users, userId);

            // Assert
            mockedFriendService.Verify(x => x.GetAllUserFriendsIds(It.Is <int>(i => i == user.Id)), Times.Once);
        }
コード例 #3
0
        public void CallImageService_ByteArrayToImageUrlUsersCountTimes()
        {
            // Arrange
            var mockedMapperService = new Mock <IMapperService>();
            var mappedUser          = new SearchUserViewModel();

            mockedMapperService.Setup(x => x.MapObject <SearchUserViewModel>(It.IsAny <CustomUser>())).Returns(mappedUser);
            var mockedImageService = new Mock <IImageService>();

            mockedImageService.Setup(x => x.ByteArrayToImageUrl(It.IsAny <byte[]>())).Returns("some-url");
            var mockedUserService   = new Mock <IUserService>();
            var mockedFriendService = new Mock <IFriendService>();

            var viewModelService = new ViewModelService(
                mockedMapperService.Object,
                mockedImageService.Object,
                mockedUserService.Object,
                mockedFriendService.Object);
            var users = new List <CustomUser>()
            {
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                },
                new CustomUser()
                {
                    ProfileImage = new ProfileImage()
                    {
                        Content = new byte[] { 1, 2 }
                    }
                }
            };

            // Act
            viewModelService.GetMappedSearchedUsers(users, string.Empty);

            // Assert
            mockedImageService.Verify(x => x.ByteArrayToImageUrl(It.IsAny <byte[]>()), Times.Exactly(users.Count));
        }