public async Task GetUserInfoForHeaderAsyncReturnDtoWithoutScientificWorkId() { var userId = 1u; var user = new User() { Id = userId, Name = _faker.Person.FirstName, Surname = _faker.Person.LastName, UserName = UserHelper.GetUserName(UserTypeEnum.Participant, _faker.Person.Email) }; var expectedDto = _mapper.Map <HeaderUserInfoDto>(user); HeaderUserInfoDto returnedDto = null; _userManagerMock.Setup(x => x.FindByIdAsync(userId.ToString())).ReturnsAsync(user); _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync((ScientificWork)null); var err = await Record.ExceptionAsync(async() => returnedDto = await _userService.GetUserInfoForHeaderAsync(userId.ToString())); err.Should().BeNull(); returnedDto.Should().NotBeNull(); returnedDto.Should().BeEquivalentTo(expectedDto); _userManagerMock.Verify(x => x.FindByIdAsync(userId.ToString()), Times.Once); _scientificWorkRepositoryMock.Verify(x => x.GetByAuthorIdAsync(userId), Times.Once); }
public async Task GetUserInfoForHeaderAsyncReturnDtoWithPhoto() { var userId = 1u; var randomBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(_faker.Random.String(7))); var photoExtension = "png"; var user = new User() { Id = userId, Name = _faker.Person.FirstName, Surname = _faker.Person.LastName, UserName = UserHelper.GetUserName(UserTypeEnum.Participant, _faker.Person.Email), Photo = _faker.System.FileName(photoExtension) }; var expectedDto = _mapper.Map <HeaderUserInfoDto>(user); expectedDto.PhotoBase64 = $"data:image/{photoExtension};base64,{randomBase64}"; HeaderUserInfoDto returnedDto = null; _userManagerMock.Setup(x => x.FindByIdAsync(userId.ToString())).ReturnsAsync(user); _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync((ScientificWork)null); _fileManagerMock.Setup(x => x.GetBase64FileAsync(user.Photo)).ReturnsAsync(randomBase64); var err = await Record.ExceptionAsync(async() => returnedDto = await _userService.GetUserInfoForHeaderAsync(userId.ToString())); err.Should().BeNull(); returnedDto.Should().NotBeNull(); returnedDto.Should().BeEquivalentTo(expectedDto); _userManagerMock.Verify(x => x.FindByIdAsync(userId.ToString()), Times.Once); _scientificWorkRepositoryMock.Verify(x => x.GetByAuthorIdAsync(userId), Times.Once); _fileManagerMock.Verify(x => x.GetBase64FileAsync(user.Photo), Times.Once); }