aboutsummaryrefslogtreecommitdiff
path: root/src/Services/DevHive.Services.Tests
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-04-07 18:41:30 +0300
committertranstrike <transtrike@gmail.com>2021-04-07 18:41:30 +0300
commitb8d1edfc582bee2ef648757bcad1bbadd075bb08 (patch)
tree0042a44c3091af36994cdc9b91a835ed1d803eaa /src/Services/DevHive.Services.Tests
parentf4eac9c89bef0c21d7ccb29cb0841fa621c79f46 (diff)
parentda7d6223c261aac8e8f18458c11fb48cf9ca4cfe (diff)
downloadDevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.tar
DevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.tar.gz
DevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.zip
Merged from dev
Diffstat (limited to 'src/Services/DevHive.Services.Tests')
-rw-r--r--src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj4
-rw-r--r--src/Services/DevHive.Services.Tests/ProfilePictureService.Tests.cs84
-rw-r--r--src/Services/DevHive.Services.Tests/UserService.Tests.cs2
3 files changed, 87 insertions, 3 deletions
diff --git a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj
index d85eea2..4a7237b 100644
--- a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj
+++ b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj
@@ -4,12 +4,12 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.3"/>
+ <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.4"/>
<PackageReference Include="Moq" Version="4.16.1"/>
<PackageReference Include="NUnit" Version="3.13.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1"/>
- <PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253"/>
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.20.0.28934"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DevHive.Services\DevHive.Services.csproj"/>
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);
+ }
+ }
+}
diff --git a/src/Services/DevHive.Services.Tests/UserService.Tests.cs b/src/Services/DevHive.Services.Tests/UserService.Tests.cs
index 7990b32..9d1bca5 100644
--- a/src/Services/DevHive.Services.Tests/UserService.Tests.cs
+++ b/src/Services/DevHive.Services.Tests/UserService.Tests.cs
@@ -344,7 +344,7 @@ namespace DevHive.Services.Tests
// }
// else
// {
- // const string EXCEPTION_MESSAGE = "Unable to edit user!";
+ // const string EXCEPTION_MESSAGE = string.Format(ErrorMessages.CannotEdit, ClassesConstants.User.ToLower());
//
// Exception ex = Assert.ThrowsAsync<InvalidOperationException>(() => this._userService.UpdateUser(updateUserServiceModel);
//