diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-14 11:39:23 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-14 11:39:23 +0200 |
| commit | 5372fa5e7cd1a3d97a61052cd87f2105c65b143a (patch) | |
| tree | eb949c3f7cdeb00fdb95e0127895ad4fe359c6a5 /src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs | |
| parent | a2dde73b37ad311213a6787fb5aeb5cb4103968c (diff) | |
| download | DevHive-5372fa5e7cd1a3d97a61052cd87f2105c65b143a.tar DevHive-5372fa5e7cd1a3d97a61052cd87f2105c65b143a.tar.gz DevHive-5372fa5e7cd1a3d97a61052cd87f2105c65b143a.zip | |
Updated code style of mock setups in Service layer tests
Diffstat (limited to 'src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs')
| -rw-r--r-- | src/Services/DevHive.Services.Tests/TechnologyServices.Tests.cs | 104 |
1 files changed, 78 insertions, 26 deletions
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<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); + 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.CreateTechnology(createTechnologyServiceModel); @@ -68,9 +76,15 @@ namespace DevHive.Services.Tests 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.CreateTechnology(createTechnologyServiceModel); @@ -88,7 +102,9 @@ namespace DevHive.Services.Tests Name = technologyName }; - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())).Returns(Task.FromResult(true)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyNameExistAsync(It.IsAny<string>())) + .Returns(Task.FromResult(true)); Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this._technologyService.CreateTechnology(createTechnologyServiceModel)); @@ -111,8 +127,12 @@ namespace DevHive.Services.Tests Name = name }; - this._technologyRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(technology)); - this._mapperMock.Setup(p => p.Map<ReadTechnologyServiceModel>(It.IsAny<Technology>())).Returns(readTechnologyServiceModel); + this._technologyRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny<Guid>())) + .Returns(Task.FromResult(technology)); + this._mapperMock + .Setup(p => p.Map<ReadTechnologyServiceModel>(It.IsAny<Technology>())) + .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<Guid>())).Returns(Task.FromResult<Technology>(null)); + this._technologyRepositoryMock + .Setup(p => p.GetByIdAsync(It.IsAny<Guid>())) + .Returns(Task.FromResult<Technology>(null)); Exception ex = Assert.ThrowsAsync<ArgumentException>(() => 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<Technology>()); - this._mapperMock.Setup(p => p.Map<HashSet<ReadTechnologyServiceModel>>(It.IsAny<HashSet<Technology>>())).Returns(technologies); + this._technologyRepositoryMock + .Setup(p => p.GetTechnologies()) + .Returns(new HashSet<Technology>()); + this._mapperMock + .Setup(p => p.Map<HashSet<ReadTechnologyServiceModel>>(It.IsAny<HashSet<Technology>>())) + .Returns(technologies); HashSet<ReadTechnologyServiceModel> 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<Technology>()); - this._mapperMock.Setup(p => p.Map<HashSet<ReadTechnologyServiceModel>>(It.IsAny<HashSet<Technology>>())).Returns(new HashSet<ReadTechnologyServiceModel>()); + this._technologyRepositoryMock + .Setup(p => p.GetTechnologies()) + .Returns(new HashSet<Technology>()); + this._mapperMock + .Setup(p => p.Map<HashSet<ReadTechnologyServiceModel>>(It.IsAny<HashSet<Technology>>())) + .Returns(new HashSet<ReadTechnologyServiceModel>()); HashSet<ReadTechnologyServiceModel> result = this._technologyService.GetTechnologies(); @@ -180,10 +210,18 @@ namespace DevHive.Services.Tests 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<Guid>(), It.IsAny<Technology>())).Returns(Task.FromResult(shouldPass)); - this._mapperMock.Setup(p => p.Map<Technology>(It.IsAny<UpdateTechnologyServiceModel>())).Returns(technology); + 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<Guid>(), 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); @@ -198,7 +236,9 @@ namespace DevHive.Services.Tests { }; - this._technologyRepositoryMock.Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())).Returns(Task.FromResult(false)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())) + .Returns(Task.FromResult(false)); Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this._technologyService.UpdateTechnology(updateTechnologyServiceModel)); @@ -213,8 +253,12 @@ namespace DevHive.Services.Tests { }; - 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(true)); + 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(true)); Exception ex = Assert.ThrowsAsync<ArgumentException>(() => 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<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); @@ -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<Guid>())).Returns(Task.FromResult(false)); + this._technologyRepositoryMock + .Setup(p => p.DoesTechnologyExistAsync(It.IsAny<Guid>())) + .Returns(Task.FromResult(false)); Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this._technologyService.DeleteTechnology(id)); |
