diff options
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests')
| -rw-r--r-- | src/DevHive.Tests/DevHive.Data.Tests/LenguageRepository.Tests.cs | 1 | ||||
| -rw-r--r-- | src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs | 134 |
2 files changed, 82 insertions, 53 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/LenguageRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/LenguageRepository.Tests.cs index 0a99bf1..aefeddd 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/LenguageRepository.Tests.cs +++ b/src/DevHive.Tests/DevHive.Data.Tests/LenguageRepository.Tests.cs @@ -6,5 +6,6 @@ namespace DevHive.Data.Tests [TestFixture] public class LenguageRepositoryTests { + // pending repo refactoring } } diff --git a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs index 9c95c6d..c0aaa93 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs +++ b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System; using System.Linq; +using System.Threading.Tasks; namespace DevHive.Data.Tests { @@ -46,124 +47,151 @@ namespace DevHive.Data.Tests #endregion #region GetByIdAsync - [Test] - public async void GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists() + public void GetByIdAsync_ReturnsTheCorrectTechnology_IfIdExists() { - AddEntity(); - Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault(); - Guid id = technology.Id; + Task.Run(async () => + { + 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"); + Assert.AreEqual(TECHNOLOGY_NAME, technologyReturned.Name, "GetByIdAsync does not return the correct Technology when id is valid"); + }).GetAwaiter().GetResult(); } [Test] - public async void GetByIdAsync_ReturnsNull_IfIdDoesNotExists() + public void GetByIdAsync_ReturnsNull_IfIdDoesNotExists() { + Task.Run(async () => + { + Guid id = Guid.NewGuid(); - Guid id = Guid.NewGuid(); - - Technology technologyReturned = await this.TechnologyRepository.GetByIdAsync(id); + 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 async void DoesTechnologyExist_ReturnsTrue_IfIdExists() + public void DoesTechnologyExist_ReturnsTrue_IfIdExists() { - AddEntity(); - Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault(); - Guid id = technology.Id; + Task.Run(async () => + { + 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"); + Assert.IsTrue(result, "DoesTechnologyExistAsync returns flase hwen technology exists"); + }).GetAwaiter().GetResult(); } [Test] - public async void DoesTechnologyExist_ReturnsFalse_IfIdDoesNotExists() + public void DoesTechnologyExist_ReturnsFalse_IfIdDoesNotExists() { - Guid id = Guid.NewGuid(); + Task.Run(async () => + { + 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"); + Assert.IsFalse(result, "DoesTechnologyExistAsync returns true when technology does not exist"); + }).GetAwaiter().GetResult(); } #endregion #region DoesTechnologyNameExistAsync [Test] - public async void DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists() + public void DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists() { - AddEntity(); + Task.Run(async () => + { + 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"); + Assert.IsTrue(result, "DoesTechnologyNameExists returns true when technology name does not exist"); + }).GetAwaiter().GetResult(); } [Test] - public async void DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists() + public void DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists() { - bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME); + Task.Run(async () => + { + bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME); - Assert.False(result, "DoesTechnologyNameExistAsync returns true when technology name does not exist"); + Assert.False(result, "DoesTechnologyNameExistAsync returns true when technology name does not exist"); + }).GetAwaiter().GetResult(); } #endregion #region EditAsync //TO DO fix: check UserRepo [Test] - public async void EditAsync_UpdatesEntity() + public void EditAsync_UpdatesEntity() { - string newName = "New name"; - Guid id = Guid.NewGuid(); - Technology technology = new Technology - { - Name = TECHNOLOGY_NAME, - Id = id - }; Technology newTechnology = new Technology + Task.Run(async () => { - Name = newName, - Id = id - }; + string newName = "New name"; + Technology technology = new Technology + { + 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); + Assert.IsTrue(result); + }).GetAwaiter().GetResult(); } #endregion #region DeleteAsync [Test] - public async void DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull() + public void DeleteAsync_ReturnsTrue_IfDeletionIsSuccesfull() { - AddEntity(); - Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault(); + Task.Run(async () => + { + 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"); + Assert.IsTrue(result, "DeleteAsync returns false when deletion is successfull"); + }).GetAwaiter().GetResult(); } #endregion #region HelperMethods - private async void AddEntity(string name = TECHNOLOGY_NAME) + private void AddEntity(string name = TECHNOLOGY_NAME) { - Technology technology = new Technology + Task.Run(async () => { - Name = name - }; + Technology technology = new Technology + { + Name = name + }; - await this.TechnologyRepository.AddAsync(technology); + await this.TechnologyRepository.AddAsync(technology); + }).GetAwaiter().GetResult(); } #endregion + + //Task.Run(async () => + //{ + + //}).GetAwaiter().GetResult(); } } |
