aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Services.Tests
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 19:30:25 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 19:30:25 +0200
commit4417b86ccd570f1f5637afc7460ef70fcf1c47c2 (patch)
tree57494e95274e7725334c9176c4c2901ef760a11d /src/DevHive.Tests/DevHive.Services.Tests
parent9e86699c9b3aff17e0c4d19850b41b792a9625ef (diff)
downloadDevHive-4417b86ccd570f1f5637afc7460ef70fcf1c47c2.tar
DevHive-4417b86ccd570f1f5637afc7460ef70fcf1c47c2.tar.gz
DevHive-4417b86ccd570f1f5637afc7460ef70fcf1c47c2.zip
Refactored technology layer tests to be async
Diffstat (limited to 'src/DevHive.Tests/DevHive.Services.Tests')
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs179
1 files changed, 78 insertions, 101 deletions
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();
}
}