Ejemplo n.º 1
0
        public async Task GetPhoto_ShouldReturnPhoto()
        {
            // Arrange
            var photoId     = 1;
            var dateAdded   = DateTime.Now;
            var description = "Test";
            var photo       = new Photo()
            {
                Id          = photoId,
                Description = description,
                DateAdded   = dateAdded
            };

            var photoToReturn = new PhotoToReturnDto()
            {
                Id          = photoId,
                DateAdded   = dateAdded,
                Description = description
            };

            _unitOfWorkMock.Setup(x => x.Photos.GetById(It.IsAny <int>()))
            .ReturnsAsync(photo);

            _mapperMock.Setup(x => x.Map <PhotoToReturnDto>(photo))
            .Returns(photoToReturn);
            // Act
            var result = await _sut.GetPhoto(photoId);

            // Assert
            Assert.Equal(photoId, result.Id);
            Assert.Equal(dateAdded, result.DateAdded);
            Assert.Equal(description, result.Description);
        }
Ejemplo n.º 2
0
        public async Task MakePhotoMain_ShouldMake_WhenMainPhotoIsNotNull()
        {
            // Arrange
            var responseMessage      = "Photo successfully set to main.";
            var photoId              = 1;
            var userId               = 1;
            var dateAdded            = DateTime.Now;
            var description          = "Test";
            var mainPhotoDescription = "Main photo";
            var photo = new Photo()
            {
                Id          = photoId,
                Description = description,
                DateAdded   = dateAdded
            };

            var mainPhoto = new Photo()
            {
                Id          = photoId,
                Description = mainPhotoDescription,
                DateAdded   = dateAdded
            };

            var photoToReturn = new PhotoToReturnDto()
            {
                Id          = photoId,
                DateAdded   = dateAdded,
                Description = description
            };

            _unitOfWorkMock.Setup(x => x.Photos.GetById(photoId))
            .ReturnsAsync(photo);

            _unitOfWorkMock.Setup(x => x.Photos.GetMainPhotoForUser(userId))
            .ReturnsAsync(mainPhoto);

            _unitOfWorkMock.Setup(x => x.Complete())
            .ReturnsAsync(true);

            // Act
            var result = await _sut.MakePhotoMain(photoId, userId);

            // Assert
            Assert.Equal(responseMessage, result.Value);
        }