diff options
| author | transtrike <transtrike@gmail.com> | 2021-01-21 22:13:16 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-01-21 22:13:16 +0200 |
| commit | 13a2ceda912f961a232c87236f1b29aa29bb6160 (patch) | |
| tree | 59f8d2bf63b03bacc76f98114d2aed78e420ddcd /src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs | |
| parent | a47ea20ab91017da53437f750ed8e0f939f5cdba (diff) | |
| parent | bda98b96433d7a9952524fab4ec65f96998b55de (diff) | |
| download | DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar.gz DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.zip | |
Merge branch 'refactor_user_updating' into dev
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs')
| -rw-r--r-- | src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs | 144 |
1 files changed, 56 insertions, 88 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs index 18d72b9..289d846 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs +++ b/src/DevHive.Tests/DevHive.Data.Tests/TechnologyRepository.Tests.cs @@ -1,4 +1,4 @@ -using DevHive.Data.Models; +using DevHive.Data.Models; using DevHive.Data.Repositories; using Microsoft.EntityFrameworkCore; using NUnit.Framework; @@ -35,11 +35,10 @@ 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,154 +47,123 @@ namespace DevHive.Data.Tests #endregion #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 = new Guid(); + 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"); - }).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 = new Guid(); + 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"; - Guid id = new Guid(); - 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 = TECHNOLOGY_NAME + }; Technology newTechnology = new Technology + { + Name = newName + }; + + 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 Task 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); + await 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 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 //Task.Run(async () => //{ - // + //}).GetAwaiter().GetResult(); } } |
