From 6b15673c61d3b1d94012c449c243f98bc3ff13fc Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Thu, 21 Jan 2021 21:16:05 +0200 Subject: Made all Technology Layer Tests async again --- .../TechnologyServices.Tests.cs | 171 ++++++++++----------- 1 file changed, 78 insertions(+), 93 deletions(-) (limited to 'src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs') 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())).Returns(Task.FromResult(false)); - this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(true)); - this.TechnologyRepositoryMock.Setup(p => p.GetByNameAsync(It.IsAny())).Returns(Task.FromResult(technology)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(false)); + this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(true)); + this.TechnologyRepositoryMock.Setup(p => p.GetByNameAsync(It.IsAny())).Returns(Task.FromResult(technology)); + this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(false)); - this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(false)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(technology); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this.TechnologyRepositoryMock.Setup(p => p.AddAsync(It.IsAny())).Returns(Task.FromResult(false)); + this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(technology)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(technology)); + this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(true)); - this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(false)); - this.TechnologyRepositoryMock.Setup(p => p.EditAsync(It.IsAny())).Returns(Task.FromResult(shouldPass)); - this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(true)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this.TechnologyRepositoryMock.Setup(p => p.EditAsync(It.IsAny())).Returns(Task.FromResult(shouldPass)); + this.MapperMock.Setup(p => p.Map(It.IsAny())).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())).Returns(Task.FromResult(true)); - this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(technology)); - this.TechnologyRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).Returns(Task.FromResult(shouldPass)); + this.TechnologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + this.TechnologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(technology)); + this.TechnologyRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny())).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] -- cgit v1.2.3