aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-03-15 09:27:12 +0200
committertranstrike <transtrike@gmail.com>2021-03-15 09:27:12 +0200
commit0161be09312fde634865f110504884119a617d5c (patch)
tree0fa68366edcb024c054f370ecf90f5b66282aae5 /src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
parente3b5757b5a5db2f7874b0924cdd4a22b1a9e1ee2 (diff)
parentac82c773a5ec43c6a59d3d0b7665b67ac9e6bdde (diff)
downloadDevHive-0161be09312fde634865f110504884119a617d5c.tar
DevHive-0161be09312fde634865f110504884119a617d5c.tar.gz
DevHive-0161be09312fde634865f110504884119a617d5c.zip
Fixed to new() where possible and readable
Diffstat (limited to 'src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs')
-rw-r--r--src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
index d25fd3b..d268777 100644
--- a/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
@@ -12,27 +12,25 @@ namespace DevHive.Data.Tests
public class TechnologyRepositoryTests
{
private const string TECHNOLOGY_NAME = "Technology test name";
-
- protected DevHiveContext Context { get; set; }
-
- protected TechnologyRepository TechnologyRepository { get; set; }
+ private DevHiveContext _context;
+ private TechnologyRepository _technologyRepository;
#region Setups
[SetUp]
public void Setup()
{
- var optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
+ DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- TechnologyRepository = new TechnologyRepository(Context);
+ this._technologyRepository = new TechnologyRepository(this._context);
}
[TearDown]
public void TearDown()
{
- this.Context.Database.EnsureDeleted();
+ this._context.Database.EnsureDeleted();
}
#endregion
@@ -40,11 +38,11 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetByNameAsync_ReturnsTheCorrectTechnology_IfItExists()
{
- await AddEntity();
+ await this.AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
+ Technology technology = this._context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().FirstOrDefault();
- Technology resultTechnology = await this.TechnologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
+ Technology resultTechnology = await this._technologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
Assert.AreEqual(technology.Id, resultTechnology.Id);
}
@@ -52,7 +50,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetByNameAsync_ReturnsNull_IfTechnologyDoesNotExists()
{
- Technology resultTechnology = await this.TechnologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
+ Technology resultTechnology = await this._technologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
Assert.IsNull(resultTechnology);
}
@@ -62,11 +60,11 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesTechnologyExist_ReturnsTrue_IfIdExists()
{
- await AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).ToList().FirstOrDefault();
+ await this.AddEntity();
+ Technology technology = this._context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().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");
}
@@ -76,7 +74,7 @@ namespace DevHive.Data.Tests
{
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");
}
@@ -86,9 +84,9 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesTechnologyNameExist_ReturnsTrue_IfTechnologyExists()
{
- await AddEntity();
+ await this.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");
}
@@ -96,7 +94,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists()
{
- 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");
}
@@ -105,13 +103,13 @@ namespace DevHive.Data.Tests
#region HelperMethods
private async Task AddEntity(string name = TECHNOLOGY_NAME)
{
- Technology technology = new Technology
+ Technology technology = new()
{
Name = name
};
- this.Context.Technologies.Add(technology);
- await this.Context.SaveChangesAsync();
+ this._context.Technologies.Add(technology);
+ await this._context.SaveChangesAsync();
}
#endregion
}