aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 21:16:05 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 21:16:05 +0200
commit6b15673c61d3b1d94012c449c243f98bc3ff13fc (patch)
tree77aef918fed9861f96365860089d7831f3213d5e /src/DevHive.Tests
parentbd67366f41a25e868053bf3c71ed2917f25a8a6f (diff)
downloadDevHive-6b15673c61d3b1d94012c449c243f98bc3ff13fc.tar
DevHive-6b15673c61d3b1d94012c449c243f98bc3ff13fc.tar.gz
DevHive-6b15673c61d3b1d94012c449c243f98bc3ff13fc.zip
Made all Technology Layer Tests async again
Diffstat (limited to 'src/DevHive.Tests')
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs128
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/LanguageService.Tests.cs13
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs171
3 files changed, 138 insertions, 174 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
index c0aaa93..289d846 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs
@@ -36,9 +36,9 @@ namespace DevHive.Data.Tests
#region AddAsync
[Test]
- public void AddAsync_AddsTheGivenTechnologyToTheDatabase()
+ public async Task AddAsync_AddsTheGivenTechnologyToTheDatabase()
{
- AddEntity();
+ await AddEntity();
int numberOfTechnologies = Context.Technologies.Count();
@@ -48,144 +48,116 @@ namespace DevHive.Data.Tests
#region GetByIdAsync
[Test]
- public void GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists()
+ public async Task GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- Guid id = technology.Id;
+ await 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 Task GetByIdAsync_ReturnsNull_IfIdDoesNotExists()
{
- Task.Run(async () =>
- {
- Guid id = Guid.NewGuid();
-
- Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
+ Guid id = Guid.NewGuid();
- Assert.IsNull(technologyReturned, "GetByIdAsync returns Technology when it should be null");
+ Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id);
- }).GetAwaiter().GetResult();
+ Assert.IsNull(technologyReturned, "GetByIdAsync returns Technology when it should be null");
}
#endregion
#region DoesTechnologyExistAsync
[Test]
- public void DoesTechnologyExist_ReturnsTrue_IfIdExists()
+ public async Task DoesTechnologyExist_ReturnsTrue_IfIdExists()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- Guid id = technology.Id;
+ await 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 Task 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 Task DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists()
{
- Task.Run(async () =>
- {
- AddEntity();
+ await 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 Task 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: check UserRepo
[Test]
- public void EditAsync_UpdatesEntity()
+ public async Task EditAsync_UpdatesEntity()
{
- Task.Run(async () =>
+ string newName = "New name";
+ Technology technology = new Technology
{
- string newName = "New name";
- Technology technology = new Technology
- {
- Name = TECHNOLOGY_NAME
- }; Technology newTechnology = new Technology
- {
- Name = newName
- };
+ Name = TECHNOLOGY_NAME
+ }; Technology newTechnology = new Technology
+ {
+ Name = newName
+ };
- await this.TechnologyRepository.AddAsync(technology);
+ await this.TechnologyRepository.AddAsync(technology);
- bool result = await this.TechnologyRepository.EditAsync(newTechnology);
+ bool result = await this.TechnologyRepository.EditAsync(newTechnology);
- Assert.IsTrue(result);
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result);
}
#endregion
#region DeleteAsync
[Test]
- public void DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull()
+ public async Task DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull()
{
- Task.Run(async () =>
- {
- AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
+ await AddEntity();
+ Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
- bool result = await this.TechnologyRepository.DeleteAsync(technology);
+ bool result = await this.TechnologyRepository.DeleteAsync(technology);
- Assert.IsTrue(result, "DeleteAsync returns false when deletion is successfull");
- }).GetAwaiter().GetResult();
+ Assert.IsTrue(result, "DeleteAsync returns false when deletion is successfull");
}
#endregion
#region HelperMethods
- private void AddEntity(string name = TECHNOLOGY_NAME)
+ private async Task 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
diff --git a/src/DevHive.Tests/DevHive.Services.Tests/LanguageService.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/LanguageService.Tests.cs
index 2ebff58..6366cc6 100644
--- a/src/DevHive.Tests/DevHive.Services.Tests/LanguageService.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Services.Tests/LanguageService.Tests.cs
@@ -27,7 +27,7 @@ namespace DevHive.Services.Tests
#region Create
[Test]
- public async void Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
+ public async Task Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
{
string technologyName = "Gosho Trapov";
Guid id = Guid.NewGuid();
@@ -52,7 +52,7 @@ namespace DevHive.Services.Tests
}
[Test]
- public async void Create_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
+ public async Task Create_ReturnsEmptyGuid_WhenEntityIsNotAddedSuccessfully()
{
string languageName = "Gosho Trapov";
@@ -72,12 +72,13 @@ namespace DevHive.Services.Tests
Guid result = await this.LanguageService.CreateLanguage(createLanguageServiceModel);
Assert.IsTrue(result == Guid.Empty);
+
}
[Test]
public void Create_ThrowsArgumentException_WhenEntityAlreadyExists()
{
- string exceptionMessage = "Technology already exists!";
+ string exceptionMessage = "Language already exists!";
string languageName = "Gosho Trapov";
CreateLanguageServiceModel createLanguageServiceModel = new()
@@ -96,5 +97,11 @@ 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.Services.Tests/TechnologyServices.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
index b04e213..abd43ed 100644
--- a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs
@@ -27,57 +27,51 @@ namespace DevHive.Services.Tests
#region Create
[Test]
- public void Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
+ public async Task Create_ReturnsNonEmptyGuid_WhenEntityIsAddedSuccessfully()
{
- Task.Run(async () =>
+ string technologyName = "Gosho Trapov";
+ Guid id = Guid.NewGuid();
+ CreateTechnologyServiceModel createTechnologyServiceModel = new()
+ {
+ Name = technologyName
+ };
+ Technology technology = 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,
+ 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 Task 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]
@@ -105,28 +99,25 @@ namespace DevHive.Services.Tests
#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()
+ {
+ 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,29 +137,26 @@ namespace DevHive.Services.Tests
[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
{
- 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]
@@ -208,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]