aboutsummaryrefslogtreecommitdiff
path: root/src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs
diff options
context:
space:
mode:
authorVictor S <57849063+transtrike@users.noreply.github.com>2021-04-02 23:55:25 +0300
committerGitHub <noreply@github.com>2021-04-02 23:55:25 +0300
commitbad7456b379bcc683431e2279591f7c5227bd55a (patch)
treeb82e15d10e28759dcd066b38ccdd16c23753b33c /src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs
parent2448c4d31188aed26605c5e3c282bacc3bd71ae5 (diff)
parentb0c6c6e1795a1cc8fe82a60ce16a263ab4cad397 (diff)
downloadDevHive-bad7456b379bcc683431e2279591f7c5227bd55a.tar
DevHive-bad7456b379bcc683431e2279591f7c5227bd55a.tar.gz
DevHive-bad7456b379bcc683431e2279591f7c5227bd55a.zip
Merge pull request #24 from Team-Kaleidoscope/feature/profile_picture_implementation
- Removed InsertProfilePicture from Service layer (unneeded) - ReadProfilePicture endpoint implemented
Diffstat (limited to 'src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs')
-rw-r--r--src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs b/src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs
new file mode 100644
index 0000000..a7a2963
--- /dev/null
+++ b/src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs
@@ -0,0 +1,84 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using DevHive.Data;
+using DevHive.Data.Interfaces;
+using DevHive.Data.Models;
+using DevHive.Data.Repositories;
+using DevHive.Services.Interfaces;
+using DevHive.Services.Models.ProfilePicture;
+using DevHive.Services.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.EntityFrameworkCore;
+using Moq;
+using NUnit.Framework;
+
+namespace DevHive.Services.Tests
+{
+ [TestFixture]
+ public class ProfilePictureServiceTests
+ {
+ private DevHiveContext _context;
+ private Mock<IUserRepository> _userRepositoryMock;
+ private Mock<ProfilePictureRepository> _profilePictureRepository;
+ private Mock<ICloudService> _cloudService;
+ private ProfilePictureService _profilePictureService;
+
+ [SetUp]
+ public void Setup()
+ {
+ DbContextOptionsBuilder<DevHiveContext> options = new DbContextOptionsBuilder<DevHiveContext>()
+ .UseInMemoryDatabase("DevHive_UserRepository_Database");
+ this._context = new DevHiveContext(options.Options);
+ this._userRepositoryMock = new Mock<IUserRepository>();
+ this._profilePictureRepository = new Mock<ProfilePictureRepository>(this._context);
+ this._cloudService = new Mock<ICloudService>();
+
+ this._profilePictureService = new ProfilePictureService(
+ this._userRepositoryMock.Object,
+ this._profilePictureRepository.Object,
+ this._cloudService.Object
+ );
+ }
+
+ [Test]
+ public async Task InsertProfilePicture_ShouldInsertProfilePicToDatabaseAndUploadToCloud()
+ {
+ //Arrange
+ Guid userId = Guid.NewGuid();
+ Mock<IFormFile> fileMock = new();
+
+ //File mocking setup
+ var content = "Hello World from a Fake File";
+ var fileName = "test.jpg";
+ var ms = new MemoryStream();
+ var writer = new StreamWriter(ms);
+ writer.Write(content);
+ writer.Flush();
+ ms.Position = 0;
+ fileMock.Setup(p => p.FileName).Returns(fileName);
+ fileMock.Setup(p => p.Length).Returns(ms.Length);
+ fileMock.Setup(p => p.OpenReadStream()).Returns(ms);
+
+ //User Setup
+ this._userRepositoryMock
+ .Setup(p => p.GetByIdAsync(userId))
+ .ReturnsAsync(new User()
+ {
+ Id = userId
+ });
+
+ ProfilePictureServiceModel profilePictureServiceModel = new()
+ {
+ UserId = userId,
+ ProfilePictureFormFile = fileMock.Object
+ };
+
+ //Act
+ string profilePicURL = await this._profilePictureService.InsertProfilePicture(profilePictureServiceModel);
+
+ //Assert
+ Assert.IsNotEmpty(profilePicURL);
+ }
+ }
+}