aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-21 19:42:40 +0200
committertranstrike <transtrike@gmail.com>2021-01-21 19:42:40 +0200
commit78884a445ec3f21d06e5859d03009b7d71bbb784 (patch)
tree9bdb300525bd9f9fa5bbc1cd85f7beb70d954349
parent58178d5036f65bb4896fea08bbec9388a8ab8c20 (diff)
parent833c4e183581bc69102d66872b4b5bb157d80821 (diff)
downloadDevHive-78884a445ec3f21d06e5859d03009b7d71bbb784.tar
DevHive-78884a445ec3f21d06e5859d03009b7d71bbb784.tar.gz
DevHive-78884a445ec3f21d06e5859d03009b7d71bbb784.zip
Code cleanup, consistency and merge conflict resolved
-rw-r--r--src/DevHive.Data/Repositories/TechnologyRepository.cs3
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs5
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs147
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs179
-rw-r--r--src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs35
5 files changed, 165 insertions, 204 deletions
diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs
index 597a532..35ee567 100644
--- a/src/DevHive.Data/Repositories/TechnologyRepository.cs
+++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs
@@ -44,8 +44,7 @@ namespace DevHive.Data.Repositories
#region Edit
public async Task<bool> EditAsync(Technology newEntity)
{
- this._context.Technologies
- .Update(newEntity);
+ this._context.Technologies.Update(newEntity);
return await this.SaveChangesAsync(this._context);
}
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
index 1b2f0ff..88ed702 100644
--- a/src/DevHive.Services/Services/TechnologyService.cs
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -20,7 +20,6 @@ namespace DevHive.Services.Services
}
#region Create
-
public async Task<Guid> Create(CreateTechnologyServiceModel technologyServiceModel)
{
if (await this._technologyRepository.DoesTechnologyNameExistAsync(technologyServiceModel.Name))
@@ -29,7 +28,7 @@ namespace DevHive.Services.Services
Technology technology = this._technologyMapper.Map<Technology>(technologyServiceModel);
bool success = await this._technologyRepository.AddAsync(technology);
- if(success)
+ if (success)
{
Technology newTechnology = await this._technologyRepository.GetByNameAsync(technologyServiceModel.Name);
return newTechnology.Id;
@@ -40,7 +39,6 @@ namespace DevHive.Services.Services
#endregion
#region Read
-
public async Task<CreateTechnologyServiceModel> GetTechnologyById(Guid id)
{
Technology technology = await this._technologyRepository.GetByIdAsync(id);
@@ -53,7 +51,6 @@ namespace DevHive.Services.Services
#endregion
#region Update
-
public async Task<bool> UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel)
{
if (!await this._technologyRepository.DoesTechnologyExistAsync(updateTechnologyServiceModel.Id))
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
index 98f2b2f..9c95c6d 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
@@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
using System;
using System.Linq;
-using System.Threading.Tasks;
namespace DevHive.Data.Tests
{
@@ -35,7 +34,6 @@ namespace DevHive.Data.Tests
}
#region AddAsync
-
[Test]
public void AddAsync_AddsTheGivenTechnologyToTheDatabase()
{
@@ -50,153 +48,122 @@ namespace DevHive.Data.Tests
#region GetByIdAsync
[Test]
- public void GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists()
+ public async void GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- Guid id = technology.Id;
+ AddEntity();
+ Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
+ Guid id = technology.Id;
- Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
+ Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
- Assert.AreEqual(TECHNOLOGY_NAME, technologyReturned.Name, "GetByIdAsync does not return the correct Technology when id is valid");
- }).GetAwaiter().GetResult();
+ Assert.AreEqual(TECHNOLOGY_NAME, technologyReturned.Name, "GetByIdAsync does not return the correct Technology when id is valid");
}
[Test]
- public void GetByIdAsync_ReturnsNull_IfIdDoesNotExists()
+ public async void GetByIdAsync_ReturnsNull_IfIdDoesNotExists()
{
- Task.Run(async () =>
- {
- Guid id = Guid.NewGuid();
- Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
+ Guid id = Guid.NewGuid();
+
+ Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
+
+ Assert.IsNull(technologyReturned, "GetByIdAsync returns Technology when it should be null");
- Assert.IsNull(technologyReturned, "GetByIdAsync returns Technology when it should be null");
- }).GetAwaiter().GetResult();
}
#endregion
#region DoesTechnologyExistAsync
[Test]
- public void DoesTechnologyExist_ReturnsTrue_IfIdExists()
+ public async void DoesTechnologyExist_ReturnsTrue_IfIdExists()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- Guid id = technology.Id;
+ AddEntity();
+ Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
+ Guid id = technology.Id;
- bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
+ bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
- Assert.IsTrue(result, "DoesTechnologyExistAsync returns flase hwen technology exists");
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result, "DoesTechnologyExistAsync returns flase hwen technology exists");
}
[Test]
- public void DoesTechnologyExist_ReturnsFalse_IfIdDoesNotExists()
+ public async void DoesTechnologyExist_ReturnsFalse_IfIdDoesNotExists()
{
- Task.Run(async () =>
- {
- Guid id = Guid.NewGuid();
+ Guid id = Guid.NewGuid();
- bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
+ bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
- Assert.IsFalse(result, "DoesTechnologyExistAsync returns true when technology does not exist");
- }).GetAwaiter().GetResult();
+ Assert.IsFalse(result, "DoesTechnologyExistAsync returns true when technology does not exist");
}
#endregion
#region DoesTechnologyNameExistAsync
[Test]
- public void DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists()
+ public async void DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists()
{
- Task.Run(async () =>
- {
- AddEntity();
+ AddEntity();
- bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
+ bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
- Assert.IsTrue(result, "DoesTechnologyNameExists returns true when technology name does not exist");
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result, "DoesTechnologyNameExists returns true when technology name does not exist");
}
[Test]
- public void DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists()
+ public async void DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists()
{
- Task.Run(async () =>
- {
- bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
+ bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
- Assert.False(result, "DoesTechnologyNameExistAsync returns true when technology name does not exist");
- }).GetAwaiter().GetResult();
+ Assert.False(result, "DoesTechnologyNameExistAsync returns true when technology name does not exist");
}
#endregion
#region EditAsync
- //TO DO fix
+ //TO DO fix: check UserRepo
[Test]
- public void EditAsync_UpdatesEntity()
+ public async void EditAsync_UpdatesEntity()
{
- Task.Run(async () =>
+ string newName = "New name";
+ Guid id = Guid.NewGuid();
+ Technology technology = new Technology
+ {
+ Name = TECHNOLOGY_NAME,
+ Id = id
+ }; Technology newTechnology = new Technology
{
- string newName = "New name";
- Guid id = Guid.NewGuid();
- Technology technology = new Technology
- {
- Name = TECHNOLOGY_NAME,
- Id = id
- }; Technology newTechnology = new Technology
- {
- Name = newName,
- Id = id
- };
-
- await this.TechnologyRepository.AddAsync(technology);
-
- bool result = await this.TechnologyRepository.EditAsync(newTechnology);
-
- Assert.IsTrue(result);
- }).GetAwaiter().GetResult();
+ Name = newName,
+ Id = id
+ };
+
+ await this.TechnologyRepository.AddAsync(technology);
+
+ bool result = await this.TechnologyRepository.EditAsync(newTechnology);
+
+ Assert.IsTrue(result);
}
#endregion
#region DeleteAsync
[Test]
- public void DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull()
+ public async void DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
-
- bool result = await this.TechnologyRepository.DeleteAsync(technology);
+ AddEntity();
+ Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- Assert.IsTrue(result, "DeleteAsync returns false when deletion is successfull");
+ bool result = await this.TechnologyRepository.DeleteAsync(technology);
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result, "DeleteAsync returns false when deletion is successfull");
}
#endregion
#region HelperMethods
- private void AddEntity(string name = TECHNOLOGY_NAME)
+ private async void AddEntity(string name = TECHNOLOGY_NAME)
{
- Task.Run(async () =>
+ Technology technology = new Technology
{
- Technology technology = new Technology
- {
- Name = name
- };
+ Name = name
+ };
- await this.TechnologyRepository.AddAsync(technology);
- }).GetAwaiter().GetResult();
+ await this.TechnologyRepository.AddAsync(technology);
}
#endregion
-
- //Task.Run(async () =>
- //{
- //
- //}).GetAwaiter().GetResult();
}
}
diff --git a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
index 9a780c1..20aceb5 100644
--- a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
@@ -26,62 +26,54 @@ namespace DevHive.Services.Tests
}
#region Create
-
[Test]
- public void Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
+ public async void Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
{
- Task.Run(async () =>
+ string technologyName = "Gosho Trapov";
+ Guid id = Guid.NewGuid();
+ CreateTechnologyServiceModel createTechnologyServiceModel = new()
{
- string technologyName = "Gosho Trapov";
- Guid id = Guid.NewGuid();
- CreateTechnologyServiceModel createTechnologyServiceModel = new()
- {
- Name = technologyName
- };
- Technology technology = new()
- {
- Name = technologyName,
- Id = id
- };
-
- this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(false));
- this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Technology>())).Returns(Task.FromResult(true));
- this.TechnologyRepositoryMock.Setup(p => p.GetByNameAsync(It.IsAny<string>())).Returns(Task.FromResult(technology));
- this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<CreateTechnologyServiceModel>())).Returns(technology);
-
- Guid result = await this.TechnologyService.Create(createTechnologyServiceModel);
-
- Assert.AreEqual(id, result);
- }).GetAwaiter().GetResult();
+ Name = technologyName
+ };
+ Technology technology = new()
+ {
+ Name = technologyName,
+ Id = id
+ };
+
+ this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(false));
+ this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Technology>())).Returns(Task.FromResult(true));
+ this.TechnologyRepositoryMock.Setup(p => p.GetByNameAsync(It.IsAny<string>())).Returns(Task.FromResult(technology));
+ this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<CreateTechnologyServiceModel>())).Returns(technology);
+
+ Guid result = await this.TechnologyService.Create(createTechnologyServiceModel);
+
+ Assert.AreEqual(id, result);
}
[Test]
- public void Create_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
+ public async void Create_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
{
- Task.Run(async () =>
- {
- string technologyName = "Gosho Trapov";
+ string technologyName = "Gosho Trapov";
- CreateTechnologyServiceModel createTechnologyServiceModel = new()
- {
- 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<string>())).Returns(Task.FromResult(false));
- this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Technology>())).Returns(Task.FromResult(false));
- this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<CreateTechnologyServiceModel>())).Returns(technology);
+ this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(false));
+ this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny<Technology>())).Returns(Task.FromResult(false));
+ this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<CreateTechnologyServiceModel>())).Returns(technology);
- Guid result = await this.TechnologyService.Create(createTechnologyServiceModel);
+ Guid result = await this.TechnologyService.Create(createTechnologyServiceModel);
- Assert.IsTrue(result == Guid.Empty);
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result == Guid.Empty);
}
-
[Test]
public void Create_ThrowsArgumentException_WhenEntityAlreadyExists()
{
@@ -106,30 +98,26 @@ namespace DevHive.Services.Tests
#endregion
#region Read
-
[Test]
- public void GetTechnologyById_ReturnsTheTechnology_WhenItExists()
+ public async void GetTechnologyById_ReturnsTheTechnology_WhenItExists()
{
- Task.Run(async () =>
+ Guid id = new Guid();
+ string name = "Gosho Trapov";
+ Technology technology = new()
+ {
+ Name = name
+ };
+ CreateTechnologyServiceModel createTechnologyServiceModel = new()
{
- Guid id = new Guid();
- string name = "Gosho Trapov";
- Technology technology = new()
- {
- Name = name
- };
- CreateTechnologyServiceModel createTechnologyServiceModel = new()
- {
- Name = name
- };
-
- this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(technology));
- this.MapperMock.Setup(p => p.Map<CreateTechnologyServiceModel>(It.IsAny<Technology>())).Returns(createTechnologyServiceModel);
-
- CreateTechnologyServiceModel result = await this.TechnologyService.GetTechnologyById(id);
-
- Assert.AreEqual(name, result.Name);
- }).GetAwaiter().GetResult();
+ Name = name
+ };
+
+ this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(technology));
+ this.MapperMock.Setup(p => p.Map<CreateTechnologyServiceModel>(It.IsAny<Technology>())).Returns(createTechnologyServiceModel);
+
+ CreateTechnologyServiceModel result = await this.TechnologyService.GetTechnologyById(id);
+
+ Assert.AreEqual(name, result.Name);
}
[Test]
@@ -146,33 +134,29 @@ namespace DevHive.Services.Tests
#endregion
#region Update
-
[Test]
[TestCase(true)]
[TestCase(false)]
- public void UpdateTechnology_ReturnsIfUpdateIsSuccessfull_WhenTechnologyExistsy(bool shouldPass)
+ public async void UpdateTechnology_ReturnsIfUpdateIsSuccessfull_WhenTechnologyExistsy(bool shouldPass)
{
- Task.Run(async () =>
+ string name = "Gosho Trapov";
+ Technology technology = new Technology
{
- string name = "Gosho Trapov";
- Technology technology = new Technology
- {
- Name = name
- };
- UpdateTechnologyServiceModel updatetechnologyServiceModel = new UpdateTechnologyServiceModel
- {
- Name = name,
- };
-
- this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(true));
- this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(false));
- this.TechnologyRepositoryMock.Setup(p => p.EditAsync(It.IsAny<Technology>())).Returns(Task.FromResult(shouldPass));
- this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<UpdateTechnologyServiceModel>())).Returns(technology);
-
- bool result = await this.TechnologyService.UpdateTechnology(updatetechnologyServiceModel);
-
- Assert.AreEqual(shouldPass, result);
- }).GetAwaiter().GetResult();
+ Name = name
+ };
+ UpdateTechnologyServiceModel updatetechnologyServiceModel = new UpdateTechnologyServiceModel
+ {
+ Name = name,
+ };
+
+ this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(true));
+ this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(false));
+ this.TechnologyRepositoryMock.Setup(p => p.EditAsync(It.IsAny<Technology>())).Returns(Task.FromResult(shouldPass));
+ this.MapperMock.Setup(p => p.Map<Technology>(It.IsAny<UpdateTechnologyServiceModel>())).Returns(technology);
+
+ bool result = await this.TechnologyService.UpdateTechnology(updatetechnologyServiceModel);
+
+ Assert.AreEqual(shouldPass, result);
}
[Test]
@@ -212,21 +196,18 @@ namespace DevHive.Services.Tests
[Test]
[TestCase(true)]
[TestCase(false)]
- public void DeleteTechnology_ShouldReturnIfDeletionIsSuccessfull_WhenTechnologyExists(bool shouldPass)
+ public async void DeleteTechnology_ShouldReturnIfDeletionIsSuccessfull_WhenTechnologyExists(bool shouldPass)
{
- Task.Run(async () =>
- {
- Guid id = new Guid();
- Technology technology = new Technology();
+ Guid id = new Guid();
+ Technology technology = new Technology();
- this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(true));
- this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(technology));
- this.TechnologyRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny<Technology>())).Returns(Task.FromResult(shouldPass));
+ this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(true));
+ this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(technology));
+ this.TechnologyRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny<Technology>())).Returns(Task.FromResult(shouldPass));
- bool result = await this.TechnologyService.DeleteTechnology(id);
+ bool result = await this.TechnologyService.DeleteTechnology(id);
- Assert.AreEqual(shouldPass, result);
- }).GetAwaiter().GetResult();
+ Assert.AreEqual(shouldPass, result);
}
[Test]
@@ -242,9 +223,5 @@ namespace DevHive.Services.Tests
Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
}
#endregion
- //Task.Run(async () =>
- //{
- //
- //}).GetAwaiter().GetResult();
}
}
diff --git a/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs
index 7e6b3a2..3087f5d 100644
--- a/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Web.Tests/TechnologyController.Tests.cs
@@ -1,12 +1,15 @@
using AutoMapper;
+using DevHive.Common.Models.Misc;
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 Newtonsoft.Json;
using NUnit.Framework;
using System;
+using System.Linq;
using System.Threading.Tasks;
namespace DevHive.Web.Tests
@@ -30,7 +33,7 @@ namespace DevHive.Web.Tests
#region Create
[Test]
public void Create_ReturnsOkObjectResult_WhenTechnologyIsSuccessfullyCreated()
- {
+ {
CreateTechnologyWebModel createTechnologyWebModel = new CreateTechnologyWebModel
{
Name = NAME
@@ -39,13 +42,24 @@ namespace DevHive.Web.Tests
{
Name = NAME
};
+ Guid id = Guid.NewGuid();
this.MapperMock.Setup(p => p.Map<CreateTechnologyServiceModel>(It.IsAny<CreateTechnologyWebModel>())).Returns(createTechnologyServiceModel);
- this.TechnologyServiceMock.Setup(p => p.Create(It.IsAny<CreateTechnologyServiceModel>())).Returns(Task.FromResult(true));
+ this.TechnologyServiceMock.Setup(p => p.Create(It.IsAny<CreateTechnologyServiceModel>())).Returns(Task.FromResult(id));
IActionResult result = this.TechnologyController.Create(createTechnologyWebModel).Result;
- Assert.IsInstanceOf<OkResult>(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]
@@ -59,13 +73,20 @@ namespace DevHive.Web.Tests
{
Name = NAME
};
+ Guid id = Guid.Empty;
+ string errorMessage = $"Could not create technology {NAME}";
this.MapperMock.Setup(p => p.Map<CreateTechnologyServiceModel>(It.IsAny<CreateTechnologyWebModel>())).Returns(createTechnologyServiceModel);
- this.TechnologyServiceMock.Setup(p => p.Create(It.IsAny<CreateTechnologyServiceModel>())).Returns(Task.FromResult(false));
+ this.TechnologyServiceMock.Setup(p => p.Create(It.IsAny<CreateTechnologyServiceModel>())).Returns(Task.FromResult(id));
IActionResult result = this.TechnologyController.Create(createTechnologyWebModel).Result;
Assert.IsInstanceOf<BadRequestObjectResult>(result);
+
+ BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequsetObjectResult.Value.ToString();
+
+ Assert.AreEqual(errorMessage, resultMessage);
}
#endregion
@@ -112,7 +133,7 @@ namespace DevHive.Web.Tests
Name = NAME
};
- this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny<Guid>(), It.IsAny<UpdateTechnologyServiceModel>())).Returns(Task.FromResult(true));
+ this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny<UpdateTechnologyServiceModel>())).Returns(Task.FromResult(true));
this.MapperMock.Setup(p => p.Map<UpdateTechnologyServiceModel>(It.IsAny<UpdateTechnologyWebModel>())).Returns(updateTechnologyServiceModel);
IActionResult result = this.TechnologyController.Update(id, updateTechnologyWebModel).Result;
@@ -121,7 +142,7 @@ namespace DevHive.Web.Tests
}
[Test]
- public void Update_ShouldReturnOkResult_WhenTechnologyIsNotUpdatedSuccessfully ()
+ public void Update_ShouldReturnOkResult_WhenTechnologyIsNotUpdatedSuccessfully()
{
Guid id = Guid.NewGuid();
string message = "Could not update Technology";
@@ -134,7 +155,7 @@ namespace DevHive.Web.Tests
Name = NAME
};
- this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny<Guid>(), It.IsAny<UpdateTechnologyServiceModel>())).Returns(Task.FromResult(false));
+ this.TechnologyServiceMock.Setup(p => p.UpdateTechnology(It.IsAny<UpdateTechnologyServiceModel>())).Returns(Task.FromResult(false));
this.MapperMock.Setup(p => p.Map<UpdateTechnologyServiceModel>(It.IsAny<UpdateTechnologyWebModel>())).Returns(updateTechnologyServiceModel);
IActionResult result = this.TechnologyController.Update(id, updateTechnologyWebModel).Result;