From 036aa41657c4ddf35b9c1f1bd43627b22aba23f9 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 10 Jan 2021 10:55:01 +0200 Subject: Fixed test projects --- .../DevHive.Web.Tests/DevHive.Web.Tests.csproj | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj (limited to 'src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj') diff --git a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj new file mode 100644 index 0000000..bdcca5d --- /dev/null +++ b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -0,0 +1,19 @@ + + + + net5.0 + + false + + + + + + + + + + + + + -- cgit v1.2.3 From 623bb66183be1349325ca9364f5bbf2e451f7578 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 13 Jan 2021 23:05:57 +0200 Subject: Added .csproj wide code analyzer support --- src/DevHive.Common/DevHive.Common.csproj | 5 ++++- src/DevHive.Data/DevHive.Data.csproj | 15 ++++++++++----- src/DevHive.Services/DevHive.Services.csproj | 17 ++++++++++------- .../DevHive.Data.Tests/DevHive.Data.Tests.csproj | 4 ++++ .../DevHive.Services.Tests.csproj | 4 ++++ .../DevHive.Web.Tests/DevHive.Web.Tests.csproj | 4 ++++ src/DevHive.Web/DevHive.Web.csproj | 5 +++++ 7 files changed, 41 insertions(+), 13 deletions(-) (limited to 'src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj') diff --git a/src/DevHive.Common/DevHive.Common.csproj b/src/DevHive.Common/DevHive.Common.csproj index 1aca8a6..ace4997 100644 --- a/src/DevHive.Common/DevHive.Common.csproj +++ b/src/DevHive.Common/DevHive.Common.csproj @@ -8,5 +8,8 @@ - + + true + latest + diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj index 34a5431..d91728d 100644 --- a/src/DevHive.Data/DevHive.Data.csproj +++ b/src/DevHive.Data/DevHive.Data.csproj @@ -10,16 +10,21 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all - - + + + + true + latest + + diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj index 19f67d8..52f0323 100644 --- a/src/DevHive.Services/DevHive.Services.csproj +++ b/src/DevHive.Services/DevHive.Services.csproj @@ -5,9 +5,9 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all @@ -16,9 +16,12 @@ - - + + - - + + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj index c414811..509ceef 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -17,4 +17,8 @@ + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj index fb94b61..c96dfb8 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -18,4 +18,8 @@ + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj index bdcca5d..e527713 100644 --- a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -16,4 +16,8 @@ + + true + latest + diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 515d2f5..84cd92f 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -21,4 +21,9 @@ + + + true + latest + \ No newline at end of file -- cgit v1.2.3 From 6c9719d60ad88368bfa5b62b8133ce065f6cc5eb Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Thu, 14 Jan 2021 17:37:20 +0200 Subject: Refactoed technology service tests to use Assert.Throw instead of try catch --- src/DevHive.Services/Services/TechnologyService.cs | 1 - .../TechnologyServices.Tests.cs | 129 +++++++-------------- .../DevHive.Web.Tests/DevHive.Web.Tests.csproj | 1 + .../TechnologyController.Tests.cs | 55 +++++++++ .../Controllers/TechnologyController.cs | 6 +- src/DevHive.sln | 11 +- 6 files changed, 109 insertions(+), 94 deletions(-) create mode 100644 src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs (limited to 'src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj') diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index bdcf70f..7fd0b2f 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -65,7 +65,6 @@ namespace DevHive.Services.Services #endregion #region Delete - public async Task DeleteTechnology(Guid technologyId) { if (!await this._technologyRepository.DoesTechnologyExistAsync(technologyId)) diff --git a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs index 9e0876d..1f0b01e 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs +++ b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs @@ -58,32 +58,23 @@ namespace DevHive.Services.Tests [Test] public void Create_ThrowsArgumentException_WhenEntityAlreadyExists() { - Task.Run(async () => + string exceptionMessage = "Technology already exists!"; + string technologyName = "Gosho Trapov"; + + CreateTechnologyServiceModel createTechnologyServiceModel = new() { - string expectedExceptionMessage = "Technology already exists!"; - string technologyName = "Gosho Trapov"; + Name = technologyName + }; + Technology technology = new() + { + Name = technologyName + }; - CreateTechnologyServiceModel createTechnologyServiceModel = new() - { - Name = technologyName - }; - Technology technology = new() - { - Name = technologyName - }; + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + Exception ex = Assert.ThrowsAsync(() => this.TechnologyService.Create(createTechnologyServiceModel)); - try - { - await this.TechnologyService.Create(createTechnologyServiceModel); - Assert.Fail("Create does not throw exception when technology already exists"); - } - catch (ArgumentException ex) - { - Assert.AreEqual(expectedExceptionMessage, ex.Message); - } - }).GetAwaiter().GetResult(); + Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } #endregion @@ -117,22 +108,13 @@ namespace DevHive.Services.Tests [Test] public void GetTechnologyById_ThrowsException_WhenTechnologyDoesNotExist() { - Task.Run(async () => - { - string exceptionMessage = "The technology does not exist"; - Guid id = new Guid(); - this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); + string exceptionMessage = "The technology does not exist"; + Guid id = new Guid(); + this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); - try - { - await this.TechnologyService.GetTechnologyById(id); - Assert.Fail("GetTechnologyById does not throw exception when technology does not exist"); - } - catch (ArgumentException ex) - { - Assert.AreEqual(exceptionMessage, ex.Message, "Exception messege is nto correct"); - } - }).GetAwaiter().GetResult(); + Exception ex = Assert.ThrowsAsync(() => this.TechnologyService.GetTechnologyById(id)); + + Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } #endregion @@ -170,52 +152,34 @@ namespace DevHive.Services.Tests [Test] public void UpdateTechnology_ThrowsException_WhenTechnologyDoesNotExist() { - Task.Run(async () => + string exceptionMessage = "Technology does not exist!"; + Guid id = new Guid(); + UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel { - string exceptionMessage = "Technology does not exist!"; - Guid id = new Guid(); - UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel - { - }; + }; - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); - try - { - await this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel); - Assert.Fail("UpdateTechnology does not throw exception when technology does not exist"); - } - catch (ArgumentException ex) - { - Assert.AreEqual(exceptionMessage, ex.Message, "Exception Message is not correct"); - } - }).GetAwaiter().GetResult(); + Exception ex = Assert.ThrowsAsync(() => this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel)); + + Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } [Test] public void UpdateTechnology_ThrowsException_WhenTechnologyNameAlreadyExists() { - Task.Run(async () => + string exceptionMessage = "Technology name already exists!"; + Guid id = new Guid(); + UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel { - string exceptionMessage = "Technology name already exists!"; - Guid id = new Guid(); - UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel - { - }; + }; - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(true)); - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); - try - { - await this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel); - Assert.Fail("UpdateTechnology does not throw exception when technology name already exist"); - } - catch (ArgumentException ex) - { - Assert.AreEqual(exceptionMessage, ex.Message, "Exception Message is not correct"); - } - }).GetAwaiter().GetResult(); + Exception ex = Assert.ThrowsAsync(() => this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel)); + + Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } #endregion @@ -244,23 +208,14 @@ namespace DevHive.Services.Tests [Test] public void DeleteTechnology_ThrowsException_WhenTechnologyDoesNotExist() { - Task.Run(async () => - { - string exceptionMessage = "Technology does not exist!"; - Guid id = new Guid(); + string exceptionMessage = "Technology does not exist!"; + Guid id = new Guid(); - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); - try - { - await this.TechnologyService.DeleteTechnology(id); - Assert.Fail("DeleteTechnology does not throw exception when technology does not exist"); - } - catch (ArgumentException ex) - { - Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); - } - }).GetAwaiter().GetResult(); + Exception ex = Assert.ThrowsAsync(() => this.TechnologyService.DeleteTechnology(id)); + + Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message"); } #endregion //Task.Run(async () => diff --git a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj index e527713..47f40ee 100644 --- a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -7,6 +7,7 @@ + diff --git a/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs new file mode 100644 index 0000000..711f66f --- /dev/null +++ b/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -0,0 +1,55 @@ +using AutoMapper; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.Technology; +using DevHive.Web.Controllers; +using DevHive.Web.Models.Technology; +using Microsoft.AspNetCore.Mvc; +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace DevHive.Web.Tests +{ + [TestFixture] + public class TechnologyControllerTests + { + private Mock TechnologyServiceMock { get; set; } + private Mock MapperMock { get; set; } + private TechnologyController TechnologyController { get; set; } + + [SetUp] + public void SetUp() + { + this.TechnologyServiceMock = new Mock(); + this.MapperMock = new Mock(); + this.TechnologyController = new TechnologyController(this.TechnologyServiceMock.Object, this.MapperMock.Object); + } + + #region Create + [Test] + public void Create_ReturnsOkObjectResult_WhenTechnologyIsSuccessfullyCreated() + { + string name = "Gosho Trapov"; + + CreateTechnologyWebModel createTechnologyWebModel = new CreateTechnologyWebModel + { + Name = name + }; + CreateTechnologyServiceModel createTechnologyServiceModel = new CreateTechnologyServiceModel + { + Name = name + }; + + this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(createTechnologyServiceModel); + this.TechnologyServiceMock.Setup(p => p.Create(It.IsAny())).Returns(Task.FromResult(true)); + + IActionResult result = this.TechnologyController.Create(createTechnologyWebModel).Result; + + Assert.IsInstanceOf(result); + } + + + #endregion + + } +} diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs index ecac318..6c51730 100644 --- a/src/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/DevHive.Web/Controllers/TechnologyController.cs @@ -37,10 +37,10 @@ namespace DevHive.Web.Controllers [HttpGet] public async Task GetById(Guid technologyId) { - TechnologyServiceModel technologyServiceModel = await this._technologyService.GetTechnologyById(technologyId); - TechnologyWebModel technologyWebModel = this._technologyMapper.Map(technologyServiceModel); + CreateTechnologyServiceModel createTechnologyServiceModel = await this._technologyService.GetTechnologyById(technologyId); + CreateTechnologyWebModel createTechnologyWebModel = this._technologyMapper.Map(createTechnologyServiceModel); - return new OkObjectResult(technologyWebModel); + return new OkObjectResult(createTechnologyWebModel); } [HttpPut] diff --git a/src/DevHive.sln b/src/DevHive.sln index 19ebbc2..aa58d9c 100644 --- a/src/DevHive.sln +++ b/src/DevHive.sln @@ -13,11 +13,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHive.Common", "DevHive.C EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DevHive.Tests", "DevHive.Tests", "{8ED705F9-7038-472C-B53F-5B1480A74A37}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevHive.Data.Tests", "DevHive.Tests\DevHive.Data.Tests\DevHive.Data.Tests.csproj", "{346876CE-2C9B-4538-BE82-EA2017F7D405}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHive.Data.Tests", "DevHive.Tests\DevHive.Data.Tests\DevHive.Data.Tests.csproj", "{346876CE-2C9B-4538-BE82-EA2017F7D405}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevHive.Services.Tests", "DevHive.Tests\DevHive.Services.Tests\DevHive.Services.Tests.csproj", "{9BBB8A48-C5AF-4F35-925F-3404A74E47F4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHive.Services.Tests", "DevHive.Tests\DevHive.Services.Tests\DevHive.Services.Tests.csproj", "{9BBB8A48-C5AF-4F35-925F-3404A74E47F4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevHive.Web.Tests", "DevHive.Tests\DevHive.Web.Tests\DevHive.Web.Tests.csproj", "{2574CDBE-CC99-4BF8-BF7F-34C131788036}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHive.Web.Tests", "DevHive.Tests\DevHive.Web.Tests\DevHive.Web.Tests.csproj", "{2574CDBE-CC99-4BF8-BF7F-34C131788036}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2E5E3F99-7936-4F3B-974E-A98000D1564B}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -- cgit v1.2.3 From 293b4ed2c24855cf01239c3dd27b93a325e648c3 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 19 Jan 2021 21:14:20 +0200 Subject: Updated Moq to newer version --- src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj | 2 +- src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj | 2 +- src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj') diff --git a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj index 81e7b2b..d320450 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj index c96dfb8..ce5cb62 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj index 47f40ee..a171e0b 100644 --- a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -7,7 +7,7 @@ - + -- cgit v1.2.3