From 5372fa5e7cd1a3d97a61052cd87f2105c65b143a Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 11:39:23 +0200 Subject: Updated code style of mock setups in Service layer tests --- .../TechnologyServices.Tests.cs | 104 +++++++++++++++------ 1 file changed, 78 insertions(+), 26 deletions(-) (limited to 'src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs') diff --git a/src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs b/src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs index 8cc78f1..6df26f1 100644 --- a/src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs +++ b/src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs @@ -44,10 +44,18 @@ namespace DevHive.Services.Tests 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); + 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.CreateTechnology(createTechnologyServiceModel); @@ -68,9 +76,15 @@ namespace DevHive.Services.Tests 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.CreateTechnology(createTechnologyServiceModel); @@ -88,7 +102,9 @@ namespace DevHive.Services.Tests Name = technologyName }; - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())) + .Returns(Task.FromResult(true)); Exception ex = Assert.ThrowsAsync(() => this._technologyService.CreateTechnology(createTechnologyServiceModel)); @@ -111,8 +127,12 @@ namespace DevHive.Services.Tests Name = name }; - this._technologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(technology)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(readTechnologyServiceModel); + this._technologyRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .Returns(Task.FromResult(technology)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(readTechnologyServiceModel); ReadTechnologyServiceModel result = await this._technologyService.GetTechnologyById(id); @@ -124,7 +144,9 @@ namespace DevHive.Services.Tests { string exceptionMessage = "The technology does not exist"; Guid id = Guid.NewGuid(); - this._technologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny())).Returns(Task.FromResult(null)); + this._technologyRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny())) + .Returns(Task.FromResult(null)); Exception ex = Assert.ThrowsAsync(() => this._technologyService.GetTechnologyById(id)); @@ -142,8 +164,12 @@ namespace DevHive.Services.Tests technologies.Add(firstTechnology); technologies.Add(secondTechnology); - this._technologyRepositoryMock.Setup(p => p.GetTechnologies()).Returns(new HashSet()); - this._mapperMock.Setup(p => p.Map>(It.IsAny>())).Returns(technologies); + this._technologyRepositoryMock + .Setup(p => p.GetTechnologies()) + .Returns(new HashSet()); + this._mapperMock + .Setup(p => p.Map>(It.IsAny>())) + .Returns(technologies); HashSet result = this._technologyService.GetTechnologies(); @@ -153,8 +179,12 @@ namespace DevHive.Services.Tests [Test] public void GetLanguages_ReturnsEmptyHashSet_IfNoLanguagesExist() { - this._technologyRepositoryMock.Setup(p => p.GetTechnologies()).Returns(new HashSet()); - this._mapperMock.Setup(p => p.Map>(It.IsAny>())).Returns(new HashSet()); + this._technologyRepositoryMock + .Setup(p => p.GetTechnologies()) + .Returns(new HashSet()); + this._mapperMock + .Setup(p => p.Map>(It.IsAny>())) + .Returns(new HashSet()); HashSet result = this._technologyService.GetTechnologies(); @@ -180,10 +210,18 @@ namespace DevHive.Services.Tests 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(), It.IsAny())).Returns(Task.FromResult(shouldPass)); - this._mapperMock.Setup(p => p.Map(It.IsAny())).Returns(technology); + 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(), It.IsAny())) + .Returns(Task.FromResult(shouldPass)); + this._mapperMock + .Setup(p => p.Map(It.IsAny())) + .Returns(technology); bool result = await this._technologyService.UpdateTechnology(updatetechnologyServiceModel); @@ -198,7 +236,9 @@ namespace DevHive.Services.Tests { }; - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyExistAsync(It.IsAny())) + .Returns(Task.FromResult(false)); Exception ex = Assert.ThrowsAsync(() => this._technologyService.UpdateTechnology(updateTechnologyServiceModel)); @@ -213,8 +253,12 @@ namespace DevHive.Services.Tests { }; - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(true)); - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())).Returns(Task.FromResult(true)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyExistAsync(It.IsAny())) + .Returns(Task.FromResult(true)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny())) + .Returns(Task.FromResult(true)); Exception ex = Assert.ThrowsAsync(() => this._technologyService.UpdateTechnology(updateTechnologyServiceModel)); @@ -232,9 +276,15 @@ namespace DevHive.Services.Tests Guid id = Guid.NewGuid(); 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); @@ -247,7 +297,9 @@ namespace DevHive.Services.Tests string exceptionMessage = "Technology does not exist!"; Guid id = Guid.NewGuid(); - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny())).Returns(Task.FromResult(false)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyExistAsync(It.IsAny())) + .Returns(Task.FromResult(false)); Exception ex = Assert.ThrowsAsync(() => this._technologyService.DeleteTechnology(id)); -- cgit v1.2.3