Skip to content

Commit

Permalink
Merge branch 'feature/unittest/userrepo' of https://github.com/Digita…
Browse files Browse the repository at this point in the history
…lExcellence/dex-backend into feature/unittest/userrepo
  • Loading branch information
JVerbruggen committed May 11, 2020
2 parents 79274c4 + 135263c commit 624404c
Show file tree
Hide file tree
Showing 28 changed files with 420 additions and 143 deletions.
2 changes: 0 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ A few sentences describing the overall goals of the pull request's commits.

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Expand Down
20 changes: 0 additions & 20 deletions .gitlab-ci.yml

This file was deleted.

18 changes: 9 additions & 9 deletions 2_Services.Tests/Base/ServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Initialize()
/// <summary>
/// Test if the repository method is called and check if anything has changed to the entity
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task FindAsyncTest_GoodFlow(TDomain entity)
{
Expand All @@ -68,7 +68,7 @@ public virtual async Task FindAsyncTest_GoodFlow(TDomain entity)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
public virtual void AddTest_GoodFlow(TDomain entity)
{
RepositoryMock.Setup(
Expand All @@ -84,7 +84,7 @@ public virtual void AddTest_GoodFlow(TDomain entity)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="entities"></param>
/// <param name="entities">The entities which are used as data to test</param>
public virtual void AddRangeTest_GoodFlow(IEnumerable<TDomain> entities)
{
RepositoryMock.Setup(
Expand All @@ -101,7 +101,7 @@ public virtual void AddRangeTest_GoodFlow(IEnumerable<TDomain> entities)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
public virtual void Update(TDomain entity)
{
RepositoryMock.Setup(
Expand All @@ -117,7 +117,7 @@ public virtual void Update(TDomain entity)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
public virtual void Remove(TDomain entity)
{
RepositoryMock.Setup(
Expand All @@ -133,7 +133,7 @@ public virtual void Remove(TDomain entity)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="id"></param>
/// <param name="id">The id which is used to remove the entity</param>
/// <returns></returns>
public virtual async Task RemoveAsync(int id)
{
Expand All @@ -150,11 +150,11 @@ public virtual async Task RemoveAsync(int id)
/// <summary>
/// Test if the repository method is called
/// </summary>
/// <param name="entities"></param>
/// <param name="amountToTest"></param>
/// <param name="entities">The entities which are used as data to test</param>
/// <returns></returns>
public virtual async Task GetAll(List<TDomain> entities, int amountToTest)
public virtual async Task GetAll(List<TDomain> entities)
{
int amountToTest = entities.Count;
RepositoryMock.Setup(
repository => repository.GetAll())
.Returns(
Expand Down
8 changes: 4 additions & 4 deletions 2_Services.Tests/ProjectServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ProjectServiceTest : ServiceTest<Project, ProjectService, IProjectR
/// <summary>
/// Test whether the repository method is called and no changes have been applied to the object
/// </summary>
/// <param name="projects"></param>
/// <param name="projects">The projects which are used as data to test</param>
/// <returns></returns>
[Test]
public async Task GetAllWithUsersAsync_GoodFlow([ProjectDataSource(10)]List<Project> projects)
Expand All @@ -42,7 +42,7 @@ public async Task GetAllWithUsersAsync_GoodFlow([ProjectDataSource(10)]List<Proj
/// <summary>
/// Test whether the repository method is called and no changes are applied to the object
/// </summary>
/// <param name="project"></param>
/// <param name="project">The projects which are used as data to test</param>
/// <returns></returns>
[Test]
public async Task FindWithUserAndCollaboratorsAsync([ProjectDataSource]Project project)
Expand Down Expand Up @@ -78,9 +78,9 @@ public override void AddTest_GoodFlow([ProjectDataSource]Project entity)

///<inheritdoc cref="ServiceTest{TDomain, TService, TRepository}"/>
[Test]
public Task GetAll([ProjectDataSource(100)]List<Project> entities)
public override Task GetAll([ProjectDataSource(100)]List<Project> entities)
{
return base.GetAll(entities, 100);
return base.GetAll(entities);
}

///<inheritdoc cref="ServiceTest{TDomain, TService, TRepository}"/>
Expand Down
25 changes: 12 additions & 13 deletions 3_Repositories.Tests/Base/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual void Initialize()
// Check which id the entity has and use this id to retrieve it from the database again
// Check if all the properties of the retrieved entity match to the properties of the original entity
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task FindAsyncTest_GoodFlow(TDomain entity)
{
Expand All @@ -68,7 +68,7 @@ public virtual async Task FindAsyncTest_GoodFlow(TDomain entity)
/// Try to retrieve an entity from the database with a key that doesn't exist
/// Check if the error is handled correctly by returning null
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task FindAsyncTest_BadFlow_NotExists(TDomain entity)
{
Expand All @@ -82,7 +82,7 @@ public virtual async Task FindAsyncTest_BadFlow_NotExists(TDomain entity)
/// Add the given entity to the database
/// Check if the return type is not null
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task AddAsyncTest_GoodFlow(TDomain entity)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ public virtual void AddTest_BadFlow_Null()
/// Retrieve the items from the database again by their id
/// and check if they are not null
/// </summary>
/// <param name="entities"></param>
/// <param name="entities">The entitis which are used as data to test</param>
/// <returns></returns>
public virtual async Task AddRangeTest_GoodFlow(List<TDomain> entities)
{
Expand Down Expand Up @@ -154,8 +154,8 @@ public virtual void AddRangeTest_BadFlow_Null()
/// Retrieve the entity in the database and check if the entity is not equal to the first entity
/// Also check if the database entity is equal to the second entity
/// </summary>
/// <param name="entity"></param>
/// <param name="updateEntity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <param name="updateEntity">The entity which is used to update the data to test</param>
/// <returns></returns>
public virtual async Task UpdateTest_GoodFlow(TDomain entity, TDomain updateEntity)
{
Expand All @@ -176,8 +176,8 @@ public virtual async Task UpdateTest_GoodFlow(TDomain entity, TDomain updateEnti
/// Try to update an entity in the database which does not exist
/// and check how the error is handled
/// </summary>
/// <param name="entity"></param>
/// <param name="updateEntity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <param name="updateEntity">The entity which is used to update the data to test</param>
/// <returns></returns>
public virtual async Task UpdateTest_BadFlow_NotExists(TDomain entity, TDomain updateEntity)
{
Expand All @@ -197,7 +197,7 @@ public virtual async Task UpdateTest_BadFlow_NotExists(TDomain entity, TDomain u
/// Try to update the entity in the database with null
/// and check how the error is handled
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task UpdateTest_BadFlow_Null(TDomain entity)
{
Expand All @@ -214,7 +214,7 @@ public virtual async Task UpdateTest_BadFlow_Null(TDomain entity)
/// <summary>
/// Add the given entity to the database and try to remove it again with the id it got from EF Core.
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task RemoveAsyncTest_GoodFlow(TDomain entity)
{
Expand All @@ -232,7 +232,7 @@ public virtual async Task RemoveAsyncTest_GoodFlow(TDomain entity)
/// Try to remove an non existing entity from the database
/// and check how the error is handled
/// </summary>
/// <param name="entity"></param>
/// <param name="entity">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task RemoveAsyncTest_BadFlow_NotExists(TDomain entity)
{
Expand All @@ -249,8 +249,7 @@ public virtual async Task RemoveAsyncTest_BadFlow_NotExists(TDomain entity)
/// Add the given list to the database and retrieve them again
/// Check if the retrieved list is the same amount as the given list
/// </summary>
/// <param name="entities"></param>
/// <param name="amountToTest"></param>
/// <param name="entities">The entity which is used as data to test</param>
/// <returns></returns>
public virtual async Task GetAllAsyncTest_GoodFlow(List<TDomain> entities)
{
Expand Down
9 changes: 9 additions & 0 deletions 3_Repositories.Tests/DataGenerators/Base/FakeDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@

namespace Repositories.Tests.DataGenerators.Base
{
/// <summary>
/// Base class to inherit the fakeDataGenerators from
/// </summary>
/// <typeparam name="T">Domain class from the Models</typeparam>
public class FakeDataGenerator<T> : IFakeDataGenerator<T> where T : class
{
protected Faker<T> Faker;

/// <summary>
/// Initializes fakeDataGenerator
/// </summary>
public FakeDataGenerator()
{
Faker = new Faker<T>();
}

///<inheritdoc cref="IFakeDataGenerator{TDomain}"/>
public T Generate()
{
return Faker.Generate();
}

///<inheritdoc cref="IFakeDataGenerator{TDomain}"/>
public IEnumerable<T> GenerateRange(int amount)
{
return Faker.Generate(amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Repositories.Tests.DataGenerators.Base
{
/// <summary>
/// Interface to define the required methods in fakeDataGenerator
/// </summary>
/// <typeparam name="T">Domain class from the Models</typeparam>
public interface IFakeDataGenerator<T>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

namespace Repositories.Tests.DataGenerators
{
/// <summary>
/// FakeDataGenerator for the collaborators
/// </summary>
public class CollaboratorDataGenerator : FakeDataGenerator<Collaborator>
{
/// <summary>
/// Initializes the collaboratorDataGenerator
/// and define dataGenerator options
/// </summary>
public CollaboratorDataGenerator()
{
Faker = new Faker<Collaborator>()
Expand Down
7 changes: 7 additions & 0 deletions 3_Repositories.Tests/DataGenerators/ProjectDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

namespace Repositories.Tests.DataGenerators
{
/// <summary>
/// FakeDataGenerator for the projects
/// </summary>
public class ProjectDataGenerator : FakeDataGenerator<Project>
{
/// <summary>
/// Initializes the projectDataGenerator
/// and define dataGenerator options
/// </summary>
public ProjectDataGenerator()
{
Faker = new Faker<Project>()
Expand Down
7 changes: 7 additions & 0 deletions 3_Repositories.Tests/DataGenerators/UserDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

namespace Repositories.Tests.DataGenerators
{
/// <summary>
/// FakeDataGenerator for the users
/// </summary>
public class UserDataGenerator : FakeDataGenerator<User>
{
/// <summary>
/// Initializes the userDataGenerator
/// and define dataGenerator options
/// </summary>
public UserDataGenerator()
{
Faker = new Faker<User>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,37 @@

namespace Repositories.Tests.DataSources
{
/// <summary>
/// Attribute to generate collaborators
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class CollaboratorDataSourceAttribute : Attribute, IParameterDataSource
{
private readonly IFakeDataGenerator<Collaborator> fakeDataGenerator;
private readonly int amountToGenerate = 0;

/// <summary>
/// Initializes collaboratorDataSourceAttribute
/// </summary>
public CollaboratorDataSourceAttribute()
{
fakeDataGenerator = new CollaboratorDataGenerator();
}

/// <summary>
/// Initializes collaboratorDataSourceAttribute
/// and setting the amount of collaborators to be generated
/// </summary>
public CollaboratorDataSourceAttribute(int amount) : this()
{
amountToGenerate = amount;
}

/// <summary>
/// Generate the data and return it
/// </summary>
/// <param name="parameter">Extra parameters given in the attribute, not in use but required due to inheritance</param>
/// <returns>The generated data</returns>
public IEnumerable GetData(IParameterInfo parameter)
{
if (amountToGenerate <= 1)
Expand Down
15 changes: 15 additions & 0 deletions 3_Repositories.Tests/DataSources/ProjectDataSourceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,37 @@

namespace Repositories.Tests.DataSources
{
/// <summary>
/// Attribute to generate projects
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class ProjectDataSourceAttribute : Attribute, IParameterDataSource
{
private readonly IFakeDataGenerator<Project> fakeDataGenerator;
private readonly int amountToGenerate = 0;

/// <summary>
/// Initializes collaboratorDataSourceAttribute
/// </summary>
public ProjectDataSourceAttribute()
{
fakeDataGenerator = new ProjectDataGenerator();
}

/// <summary>
/// Initializes projectDataSourceAttribute
/// and setting the amount of projects to be generated
/// </summary>
public ProjectDataSourceAttribute(int amount) : this()
{
amountToGenerate = amount;
}

/// <summary>
/// Generate the data and return it
/// </summary>
/// <param name="parameter">Extra parameters given in the attribute, not in use but required due to inheritance</param>
/// <returns>The generated data</returns>
public IEnumerable GetData(IParameterInfo parameter)
{
if(amountToGenerate <= 1)
Expand Down
Loading

0 comments on commit 624404c

Please sign in to comment.