aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-26 15:58:53 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-26 15:58:53 +0200
commitb5316d00cbaee97a2c4a74005de87cd1bc26ec28 (patch)
tree64503ace7fd22b3ebf3052715572d2122e80f53e
parentacf0e2f3908ba45dca1ff04cc1e5a892cc2cdbf0 (diff)
downloadDevHive-b5316d00cbaee97a2c4a74005de87cd1bc26ec28.tar
DevHive-b5316d00cbaee97a2c4a74005de87cd1bc26ec28.tar.gz
DevHive-b5316d00cbaee97a2c4a74005de87cd1bc26ec28.zip
Removing tests for deleted User Repository methods
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs129
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/PostService.Tests.cs237
-rw-r--r--src/DevHive.Tests/DevHive.Web.Tests/PostController.Tests.cs235
3 files changed, 1 insertions, 600 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
index 832cccd..7c3ba87 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
@@ -110,38 +110,6 @@ namespace DevHive.Data.Tests
}
#endregion
- #region GetUserLanguages
- [Test]
- public async Task GetUserLanguages_ReturnsAllSavedUserLanguages_WhenTheyExist()
- {
- //Arrange
- User dummyUser = CreateDummyUser();
- await this._userRepository.AddAsync(dummyUser);
- HashSet<Language> dummyUserLanguages = dummyUser.Languages;
-
- //Act
- HashSet<Language> languages = this._userRepository.GetUserLanguages(dummyUser);
-
- //Assert
- Assert.AreEqual(dummyUserLanguages, languages, "Method doesn't query languages properly");
- }
-
- [Test]
- public async Task GetUserLanguages_EmptyList_WhenNoLanguagesExist()
- {
- //Arrange
- User dummyUser = CreateDummyUser();
- dummyUser.Languages.RemoveWhere(x => x.Name == "csharp");
- await this._userRepository.AddAsync(dummyUser);
-
- //Act
- HashSet<Language> languages = this._userRepository.GetUserLanguages(dummyUser);
-
- //Assert
- Assert.IsEmpty(languages, "Method doesn't query languages properly");
- }
- #endregion
-
#region DoesUserExistAsync
[Test]
public async Task DoesUserExistAsync_ReturnsTrue_WhenUserExists()
@@ -270,107 +238,12 @@ namespace DevHive.Data.Tests
this._context.Users.Add(dummyUser);
await this._context.SaveChangesAsync();
- bool result = this._userRepository.DoesUserHaveThisUsername(dummyUser.Id, username);
+ bool result = this._userRepository.DoesUserHaveThisUsername(dummyUser.Id, username);
Assert.IsFalse(result, "DoesUserNameExistAsync does not return false when user doesnt have the given name");
}
#endregion
- #region DoesUserHaveFriends
- [Test]
- public async Task DoesUserHaveFriends_ReturnsTrue_WhenUserHasFriends()
- {
- User dummyUser = this.CreateDummyUser();
- User anotherDummyUser = this.CreateAnotherDummyUser();
- HashSet<User> friends = new HashSet<User>();
- friends.Add(anotherDummyUser);
- dummyUser.Friends = friends;
-
- this._context.Users.Add(dummyUser);
- this._context.Users.Add(anotherDummyUser);
- await this._context.SaveChangesAsync();
-
- bool result = this._userRepository.DoesUserHaveFriends(dummyUser);
-
- Assert.IsTrue(result, "DoesUserHaveFriends does not return true when user has friends");
- }
-
- [Test]
- public async Task DoesUserHaveFriends_ReturnsFalse_WhenUserDoesNotHaveTheGivenFriend()
- {
- User dummyUser = this.CreateDummyUser();
-
- this._context.Users.Add(dummyUser);
- await this._context.SaveChangesAsync();
-
- bool result = this._userRepository.DoesUserHaveFriends(dummyUser);
-
- Assert.IsFalse(result, "DoesUserHaveFriends does not return false when user des not have friends");
- }
- #endregion
-
- #region DoesUserHaveThisLanguage
- [Test]
- public async Task DoesUserHaveThisLanguage_ReturnsTrue_WhenUserHasTheGivenLanguage()
- {
- User dummyUser = this.CreateDummyUser();
-
- this._context.Users.Add(dummyUser);
- await this._context.SaveChangesAsync();
-
- Language language = dummyUser.Languages.FirstOrDefault();
-
- bool result = this._userRepository.DoesUserHaveThisLanguage(dummyUser, language);
-
- Assert.IsTrue(result, "DoesUserHaveThisLanguage does not return true when user has the given language");
- }
-
- [Test]
- public async Task DoesUserHaveThisLanguage_ReturnsFalse_WhenUserDoesNotHaveTheGivenLanguage()
- {
- User dummyUser = this.CreateDummyUser();
- this._context.Users.Add(dummyUser);
- await this._context.SaveChangesAsync();
-
- Language language = new Language();
-
- bool result = this._userRepository.DoesUserHaveThisLanguage(dummyUser, language);
-
- Assert.IsFalse(result, "DoesUserHaveThisLanguage does not return false when user does not have the given language");
- }
- #endregion
-
- #region DoesUserHaveThisTechnology
- [Test]
- public async Task DoesUserHaveThisTechnology_ReturnsTrue_WhenUserHasTheGivenTechnology()
- {
- User dummyUser = this.CreateDummyUser();
-
- this._context.Users.Add(dummyUser);
- await this._context.SaveChangesAsync();
-
- Technology technology = dummyUser.Technologies.FirstOrDefault();
-
- bool result = this._userRepository.DoesUserHaveThisTechnology(dummyUser, technology);
-
- Assert.IsTrue(result, "DoesUserHaveThisLanguage does not return true when user has the given technology");
- }
-
- [Test]
- public async Task DoesUserHaveThisTechnology_ReturnsFalse_WhenUserDoesNotHaveTheGivenTechnology()
- {
- User dummyUser = this.CreateDummyUser();
- this._context.Users.Add(dummyUser);
- await this._context.SaveChangesAsync();
-
- Technology technology = new Technology();
-
- bool result = this._userRepository.DoesUserHaveThisTechnology(dummyUser, technology);
-
- Assert.IsFalse(result, "DoesUserHaveThisLanguage does not return false when user does not have the given technology");
- }
- #endregion
-
#region HelperMethods
private User CreateDummyUser()
{
diff --git a/src/DevHive.Tests/DevHive.Services.Tests/PostService.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/PostService.Tests.cs
deleted file mode 100644
index 9864c5b..0000000
--- a/src/DevHive.Tests/DevHive.Services.Tests/PostService.Tests.cs
+++ /dev/null
@@ -1,237 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using AutoMapper;
-using DevHive.Data.Interfaces.Repositories;
-using DevHive.Data.Models;
-using DevHive.Services.Models.Post.Comment;
-using DevHive.Services.Models.Post.Post;
-using DevHive.Services.Services;
-using Moq;
-using NUnit.Framework;
-
-namespace DevHive.Services.Tests
-{
- [TestFixture]
- public class PostServiceTests
- {
- private const string MESSAGE = "Gosho Trapov";
- private Mock<IPostRepository> PostRepositoryMock { get; set; }
- private Mock<IUserRepository> UserRepositoryMock { get; set; }
- private Mock<IMapper> MapperMock { get; set; }
- private PostService PostService { get; set; }
-
- [SetUp]
- public void Setup()
- {
- this.PostRepositoryMock = new Mock<IPostRepository>();
- this.MapperMock = new Mock<IMapper>();
- this.UserRepositoryMock = new Mock<IUserRepository>();
- this.PostService = new PostService(this.PostRepositoryMock.Object, this.UserRepositoryMock.Object, this.MapperMock.Object);
- }
-
- #region Comment
- #region Create
- [Test]
- public async Task AddComment_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
- {
- Guid id = Guid.NewGuid();
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
- {
- Message = MESSAGE
- };
- Comment comment = new Comment
- {
- Message = MESSAGE,
- Id = id
- };
-
- this.PostRepositoryMock.Setup(p => p.AddCommentAsync(It.IsAny<Comment>())).Returns(Task.FromResult(true));
- this.PostRepositoryMock.Setup(p => p.GetCommentByIssuerAndTimeCreatedAsync(It.IsAny<Guid>(), It.IsAny<DateTime>())).Returns(Task.FromResult(comment));
- this.MapperMock.Setup(p => p.Map<Comment>(It.IsAny<CreateCommentServiceModel>())).Returns(comment);
-
- Guid result = await this.PostService.AddComment(createCommentServiceModel);
-
- Assert.AreEqual(id, result);
- }
-
- [Test]
- public async Task CreateLanguage_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
- {
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
- {
- Message = MESSAGE
- };
- Comment comment = new Comment
- {
- Message = MESSAGE,
- };
-
- this.PostRepositoryMock.Setup(p => p.AddCommentAsync(It.IsAny<Comment>())).Returns(Task.FromResult(false));
- this.MapperMock.Setup(p => p.Map<Comment>(It.IsAny<CreateCommentServiceModel>())).Returns(comment);
-
- Guid result = await this.PostService.AddComment(createCommentServiceModel);
-
- Assert.IsTrue(result == Guid.Empty);
- }
- #endregion
-
- #region Read
- [Test]
- public async Task GetCommentById_ReturnsTheComment_WhenItExists()
- {
- Guid id = new Guid();
- Comment comment = new Comment
- {
- Message = MESSAGE
- };
- CommentServiceModel commentServiceModel = new CommentServiceModel
- {
- Message = MESSAGE
- };
-
- this.PostRepositoryMock.Setup(p => p.GetCommentByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(comment));
- this.MapperMock.Setup(p => p.Map<CommentServiceModel>(It.IsAny<Comment>())).Returns(commentServiceModel);
-
- CommentServiceModel result = await this.PostService.GetCommentById(id);
-
- Assert.AreEqual(MESSAGE, result.Message);
- }
-
- [Test]
- public void GetLanguageById_ThrowsException_WhenLanguageDoesNotExist()
- {
- string exceptionMessage = "The comment does not exist";
- Guid id = new Guid();
- this.PostRepositoryMock.Setup(p => p.GetCommentByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult<Comment>(null));
-
- Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.PostService.GetCommentById(id));
-
- Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
- }
- #endregion
-
- #region Update
- [Test]
- [TestCase(true)]
- [TestCase(false)]
- public async Task UpdateComment_ReturnsIfUpdateIsSuccessfull_WhenCommentExistsy(bool shouldPass)
- {
- Comment comment = new Comment
- {
- Message = MESSAGE
- };
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
- {
- Message = MESSAGE
- };
-
- this.PostRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny<Guid>())).Returns(Task.FromResult(true));
- this.PostRepositoryMock.Setup(p => p.EditCommentAsync(It.IsAny<Comment>())).Returns(Task.FromResult(shouldPass));
- this.MapperMock.Setup(p => p.Map<Comment>(It.IsAny<UpdateCommentServiceModel>())).Returns(comment);
-
- bool result = await this.PostService.UpdateComment(updateCommentServiceModel);
-
- Assert.AreEqual(shouldPass, result);
- }
-
- [Test]
- public void UpdateLanguage_ThrowsArgumentException_WhenCommentDoesNotExist()
- {
- string exceptionMessage = "Comment does not exist!";
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
- {
- };
-
- this.PostRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny<Guid>())).Returns(Task.FromResult(false));
-
- Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.PostService.UpdateComment(updateCommentServiceModel));
-
- Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
- }
- #endregion
-
- #region Delete
- [Test]
- [TestCase(true)]
- [TestCase(false)]
- public async Task DeleteComment_ShouldReturnIfDeletionIsSuccessfull_WhenCommentExists(bool shouldPass)
- {
- Guid id = new Guid();
- Comment comment = new Comment();
-
- this.PostRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny<Guid>())).Returns(Task.FromResult(true));
- this.PostRepositoryMock.Setup(p => p.GetCommentByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(comment));
- this.PostRepositoryMock.Setup(p => p.DeleteCommentAsync(It.IsAny<Comment>())).Returns(Task.FromResult(shouldPass));
-
- bool result = await this.PostService.DeleteComment(id);
-
- Assert.AreEqual(shouldPass, result);
- }
-
- [Test]
- public void DeleteLanguage_ThrowsException_WhenLanguageDoesNotExist()
- {
- string exceptionMessage = "Comment does not exist!";
- Guid id = new Guid();
-
- this.PostRepositoryMock.Setup(p => p.DoesCommentExist(It.IsAny<Guid>())).Returns(Task.FromResult(false));
-
- Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.PostService.DeleteComment(id));
-
- Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
- }
- #endregion
-
- #region ValidateJwtForComment
- //TO DO: Implement
- #endregion
- #endregion
-
- #region Posts
- #region Create
- [Test]
- public async Task CreatePost_ReturnsIdOfThePost_WhenItIsSuccessfullyCreated()
- {
- Guid id = Guid.NewGuid();
- CreatePostServiceModel createPostServiceModel = new CreatePostServiceModel
- {
- };
- Post post = new Post
- {
- Message = MESSAGE,
- Id = id
- };
-
- this.PostRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Post>())).Returns(Task.FromResult(true));
- this.PostRepositoryMock.Setup(p => p.GetPostByIssuerAndTimeCreatedAsync(It.IsAny<Guid>(), It.IsAny<DateTime>())).Returns(Task.FromResult(post));
- this.MapperMock.Setup(p => p.Map<Post>(It.IsAny<CreatePostServiceModel>())).Returns(post);
-
- Guid result = await this.PostService.CreatePost(createPostServiceModel);
-
- Assert.AreEqual(id, result, "CreatePost does not return the correct id");
- }
-
- [Test]
- public async Task CreatePost_ReturnsEmptyGuid_WhenItIsNotSuccessfullyCreated()
- {
- CreatePostServiceModel createPostServiceModel = new CreatePostServiceModel
- {
- };
- Post post = new Post
- {
- Message = MESSAGE,
- };
-
- this.PostRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Post>())).Returns(Task.FromResult(false));
- this.MapperMock.Setup(p => p.Map<Post>(It.IsAny<CreatePostServiceModel>())).Returns(post);
-
- Guid result = await this.PostService.CreatePost(createPostServiceModel);
-
- Assert.AreEqual(Guid.Empty, result, "CreatePost does not return empty id");
- }
- #endregion
-
-
- #endregion
- }
-}
diff --git a/src/DevHive.Tests/DevHive.Web.Tests/PostController.Tests.cs b/src/DevHive.Tests/DevHive.Web.Tests/PostController.Tests.cs
deleted file mode 100644
index ace1cae..0000000
--- a/src/DevHive.Tests/DevHive.Web.Tests/PostController.Tests.cs
+++ /dev/null
@@ -1,235 +0,0 @@
-using System;
-using System.Linq;
-using System.Threading.Tasks;
-using AutoMapper;
-using DevHive.Services.Interfaces;
-using DevHive.Services.Models.Post.Comment;
-using DevHive.Web.Controllers;
-using DevHive.Web.Models.Post.Comment;
-using Microsoft.AspNetCore.Mvc;
-using Moq;
-using NUnit.Framework;
-
-namespace DevHive.Web.Tests
-{
- [TestFixture]
- public class PostControllerTests
- {
- const string MESSAGE = "Gosho Trapov";
- private Mock<IPostService> PostServiceMock { get; set; }
- private Mock<IMapper> MapperMock { get; set; }
- private PostController PostController { get; set; }
-
- [SetUp]
- public void SetUp()
- {
- this.PostServiceMock = new Mock<IPostService>();
- this.MapperMock = new Mock<IMapper>();
- this.PostController = new PostController(this.PostServiceMock.Object, this.MapperMock.Object);
- }
-
- #region Comment
- #region Create
- [Test]
- public void AddComment_ReturnsOkObjectResult_WhenCommentIsSuccessfullyCreated()
- {
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
- {
- Message = MESSAGE
- };
- Guid id = Guid.NewGuid();
-
- this.MapperMock.Setup(p => p.Map<CreateCommentServiceModel>(It.IsAny<CommentWebModel>())).Returns(createCommentServiceModel);
- this.PostServiceMock.Setup(p => p.AddComment(It.IsAny<CreateCommentServiceModel>())).Returns(Task.FromResult(id));
-
- IActionResult result = this.PostController.AddComment(commentWebModel).Result;
-
- Assert.IsInstanceOf<OkObjectResult>(result);
-
- var splitted = (result as OkObjectResult).Value
- .ToString()
- .Split('{', '}', '=', ' ')
- .Where(x => !string.IsNullOrEmpty(x))
- .ToArray();
-
- Guid resultId = Guid.Parse(splitted[1]);
-
- Assert.AreEqual(id, resultId);
- }
-
- [Test]
- public void AddComment_ReturnsBadRequestObjectResult_WhenCommentIsNotCreatedSuccessfully()
- {
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
- {
- Message = MESSAGE
- };
- Guid id = Guid.Empty;
- string errorMessage = $"Could not create comment";
-
- this.MapperMock.Setup(p => p.Map<CreateCommentServiceModel>(It.IsAny<CommentWebModel>())).Returns(createCommentServiceModel);
- this.PostServiceMock.Setup(p => p.AddComment(It.IsAny<CreateCommentServiceModel>())).Returns(Task.FromResult(id));
-
- IActionResult result = this.PostController.AddComment(commentWebModel).Result;
-
- Assert.IsInstanceOf<BadRequestObjectResult>(result);
-
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
-
- Assert.AreEqual(errorMessage, resultMessage);
- }
- #endregion
-
- #region Read
- [Test]
- public void GetCommentById_ReturnsTheComment_WhenItExists()
- {
- Guid id = Guid.NewGuid();
-
- CommentServiceModel commentServiceModel = new CommentServiceModel
- {
- Message = MESSAGE
- };
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
-
- this.PostServiceMock.Setup(p => p.GetCommentById(It.IsAny<Guid>())).Returns(Task.FromResult(commentServiceModel));
- this.MapperMock.Setup(p => p.Map<CommentWebModel>(It.IsAny<CommentServiceModel>())).Returns(commentWebModel);
-
- IActionResult result = this.PostController.GetCommentById(id).Result;
-
- Assert.IsInstanceOf<OkObjectResult>(result);
-
- OkObjectResult okObjectResult = result as OkObjectResult;
- CommentWebModel resultModel = okObjectResult.Value as Models.Post.Comment.CommentWebModel;
-
- Assert.AreEqual(MESSAGE, resultModel.Message);
- }
- #endregion
-
- #region Update
- [Test]
- public void UpdateComment_ShouldReturnOkResult_WhenCommentIsUpdatedSuccessfully()
- {
- Guid id = Guid.NewGuid();
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
- {
- Message = MESSAGE
- };
-
- this.PostServiceMock.Setup(p => p.UpdateComment(It.IsAny<UpdateCommentServiceModel>())).Returns(Task.FromResult(true));
- this.MapperMock.Setup(p => p.Map<UpdateCommentServiceModel>(It.IsAny<CommentWebModel>())).Returns(updateCommentServiceModel);
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true));
-
- IActionResult result = this.PostController.UpdateComment(id, commentWebModel, null).Result;
-
- Assert.IsInstanceOf<OkResult>(result);
- }
-
- [Test]
- public void UpdateComment_ShouldReturnBadObjectResult_WhenCommentIsNotUpdatedSuccessfully()
- {
- Guid id = Guid.NewGuid();
- string message = "Could not update Comment";
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
- {
- Message = MESSAGE
- };
-
- this.PostServiceMock.Setup(p => p.UpdateComment(It.IsAny<UpdateCommentServiceModel>())).Returns(Task.FromResult(false));
- this.MapperMock.Setup(p => p.Map<UpdateCommentServiceModel>(It.IsAny<CommentWebModel>())).Returns(updateCommentServiceModel);
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true));
-
- IActionResult result = this.PostController.UpdateComment(id, commentWebModel, null).Result;
- Assert.IsInstanceOf<BadRequestObjectResult>(result);
-
- BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
- string resultModel = badRequestObjectResult.Value.ToString();
-
- Assert.AreEqual(message, resultModel);
- }
-
- [Test]
- public void UpdateComment_ShouldReturnUnauthorizedResult_WhenJwtIsNotValid()
- {
- Guid id = Guid.NewGuid();
-
- CommentWebModel commentWebModel = new CommentWebModel
- {
- Message = MESSAGE
- };
-
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false));
-
- IActionResult result = this.PostController.UpdateComment(id, commentWebModel, null).Result;
- Assert.IsInstanceOf<UnauthorizedResult>(result);
- }
- #endregion
-
- #region Delete
- [Test]
- public void DeleteComment_ReturnsOkResult_WhenLanguageIsDeletedSuccessfully()
- {
- Guid id = Guid.NewGuid();
-
- this.PostServiceMock.Setup(p => p.DeleteComment(It.IsAny<Guid>())).Returns(Task.FromResult(true));
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true));
-
- IActionResult result = this.PostController.DeleteComment(id, null).Result;
-
- Assert.IsInstanceOf<OkResult>(result);
- }
-
- [Test]
- public void DeletComment_ReturnsBadRequestObjectResult_WhenLanguageIsNotDeletedSuccessfully()
- {
- string message = "Could not delete Comment";
- Guid id = Guid.NewGuid();
-
- this.PostServiceMock.Setup(p => p.DeleteComment(It.IsAny<Guid>())).Returns(Task.FromResult(false));
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(true));
-
- IActionResult result = this.PostController.DeleteComment(id, null).Result;
-
- Assert.IsInstanceOf<BadRequestObjectResult>(result);
-
- BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
- string resultModel = badRequestObjectResult.Value.ToString();
-
- Assert.AreEqual(message, resultModel);
- }
-
- [Test]
- public void DeletComment_ReturnsUnauthorizedResult_WhenJwtIsNotValid()
- {
- Guid id = Guid.NewGuid();
-
- this.PostServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false));
-
- IActionResult result = this.PostController.DeleteComment(id, null).Result;
-
- Assert.IsInstanceOf<UnauthorizedResult>(result);
- }
- #endregion
- #endregion
- }
-}