aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs')
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs166
1 files changed, 86 insertions, 80 deletions
diff --git a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
index d028957..abd43ed 100644
--- a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
@@ -26,33 +26,52 @@ namespace DevHive.Services.Tests
}
#region Create
-
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void Create_ReturnsTrue_WhenEntityIsAddedSuccessfully(bool shouldFail)
+ public async Task Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
{
- Task.Run(async () =>
+ string technologyName = "Gosho Trapov";
+ Guid id = Guid.NewGuid();
+ CreateTechnologyServiceModel createTechnologyServiceModel = new()
{
- string technologyName = "Gosho Trapov";
+ 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);
+ }
- CreateTechnologyServiceModel createTechnologyServiceModel = new()
- {
- Name = technologyName
- };
- Technology technology = new()
- {
- Name = technologyName
- };
+ [Test]
+ public async Task Create_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
+ {
+ string technologyName = "Gosho Trapov";
+
+ 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(shouldFail));
- 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);
- bool result = await this.TechnologyService.Create(createTechnologyServiceModel);
+ Guid result = await this.TechnologyService.Create(createTechnologyServiceModel);
- Assert.AreEqual(shouldFail, result);
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result == Guid.Empty);
}
[Test]
@@ -79,30 +98,26 @@ namespace DevHive.Services.Tests
#endregion
#region Read
-
[Test]
- public void GetTechnologyById_ReturnsTheTechnology_WhenItExists()
+ public async Task GetTechnologyById_ReturnsTheTechnology_WhenItExists()
{
- Task.Run(async () =>
+ Guid id = new Guid();
+ string name = "Gosho Trapov";
+ Technology technology = 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
+ };
+ 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);
}
[Test]
@@ -119,48 +134,42 @@ namespace DevHive.Services.Tests
#endregion
#region Update
-
[Test]
[TestCase(true)]
[TestCase(false)]
- public void UpdateTechnology_ReturnsIfUpdateIsSuccessfull_WhenTechnologyExistsy(bool shouldPass)
+ public async Task UpdateTechnology_ReturnsIfUpdateIsSuccessfull_WhenTechnologyExistsy(bool shouldPass)
{
- Task.Run(async () =>
+ string name = "Gosho Trapov";
+ Technology technology = new Technology
+ {
+ Name = name
+ };
+ UpdateTechnologyServiceModel updatetechnologyServiceModel = new UpdateTechnologyServiceModel
{
- Guid id = new Guid();
- 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(id, updatetechnologyServiceModel);
-
- Assert.AreEqual(shouldPass, result);
- }).GetAwaiter().GetResult();
+ 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]
public void UpdateTechnology_ThrowsException_WhenTechnologyDoesNotExist()
{
string exceptionMessage = "Technology does not exist!";
- Guid id = new Guid();
UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel
{
};
this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(false));
- Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel));
+ Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.TechnologyService.UpdateTechnology(updateTechnologyServiceModel));
Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
}
@@ -169,7 +178,6 @@ namespace DevHive.Services.Tests
public void UpdateTechnology_ThrowsException_WhenTechnologyNameAlreadyExists()
{
string exceptionMessage = "Technology name already exists!";
- Guid id = new Guid();
UpdateTechnologyServiceModel updateTechnologyServiceModel = new UpdateTechnologyServiceModel
{
};
@@ -177,7 +185,7 @@ namespace DevHive.Services.Tests
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(true));
- Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.TechnologyService.UpdateTechnology(id, updateTechnologyServiceModel));
+ Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.TechnologyService.UpdateTechnology(updateTechnologyServiceModel));
Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
}
@@ -188,21 +196,18 @@ namespace DevHive.Services.Tests
[Test]
[TestCase(true)]
[TestCase(false)]
- public void DeleteTechnology_ShouldReturnIfDeletionIsSuccessfull_WhenTechnologyExists(bool shouldPass)
+ public async Task 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]
@@ -218,9 +223,10 @@ namespace DevHive.Services.Tests
Assert.AreEqual(exceptionMessage, ex.Message, "Incorecct exception message");
}
#endregion
+
//Task.Run(async () =>
//{
- //
+
//}).GetAwaiter().GetResult();
}
}