public async Task AddImage_ValidRequest_ReturnsImageDto() { //Arrange var request = _postRequests[0]; _userManagerMock.Setup(x => x.FindByIdAsync(request.UserId)) .ReturnsAsync(new User { Id = request.UserId }); _uowMock.Setup(x => x.ImageRepository) .Returns(_imagesRepoMock.Object); //Act var image = await _imagesService.AddImage(request); //Assert Assert.True( image.UserId == request.UserId && image.Description == request.Description && image.ShortDescription == request.ShortDescription ); }
public void AddImage_ShouldReturn_Success() { // Arrange ImagesModel image = new ImagesModel() { FileName = "somefile.png", ProductId = 1, LinkWebStore = "some weblink", LinkSupplier = "some suppliers link", LocalPath = "some local path" }; fakeImagesRepository.Setup(a => a.Add(image)); imagesService = new ImagesService(fakeImagesRepository.Object, new Mock <ICommonRepository>().Object); ImagesDtoModel imageDto = new ImagesDtoModel { FileName = image.FileName, ProductId = image.ProductId, ProductName = "Product name", LinkWebStore = image.LinkWebStore, LinkSupplier = image.LinkSupplier, LocalPath = image.LocalPath }; try { // Act imagesService.AddImage(imageDto); operationSucceeded = true; } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } // Assert Assert.IsTrue(operationSucceeded, errorMessage); }