Skip to content

Commit

Permalink
Refactored QueryBaseExtensionsTests uUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteDecoder committed Jul 4, 2020
1 parent adc0c6e commit 2c2fd2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/Queryology.Tests/QueryBaseExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
using System.Collections.Generic;
using System.Linq;
using ByteDecoder.Queryology.Extensions;
using ByteDecoder.Queryology.Tests.Queries;
using ByteDecoder.Queryology.Tests.TestBuilders;
using Xunit;

namespace ByteDecoder.Queryology.Tests
{
public class QueryBaseExtensionsTests
public class QueryBaseExtensionsTests: IDisposable
{
private TestBuilderFactory _testBuilderFactory;

public QueryBaseExtensionsTests()
{
_testBuilderFactory = new TestBuilderFactory();
}

[Fact]
public void IgnoreExcludedQueries_ThrowsAnArgumentNullException_WhenSourceIsNull()
{
Expand All @@ -25,12 +32,7 @@ public void IgnoreExcludedQueries_FiltersOnlyAllowedQueries_WhenIsSetToTrue()
{
// Arrange
using var dbContext = new NullDbContext();
var queries = new List<IQuery<NullDbContext>>()
{
new QueryTypeNullDbContextOne(dbContext),
new QueryTypeNullDbContextTwo(dbContext),
new QueryTypeNullDbContextThree(dbContext)
};
var queries = _testBuilderFactory.CreateNullDbContextObjectQueries(dbContext);

// Act
var result = queries.IgnoreExcludedQueries().Count();
Expand All @@ -44,18 +46,15 @@ public void IgnoreExcludedQueries_NoFiltersQueries_WhenIsSetToFalse()
{
// Arrange
using var dbContext = new NullDbContext();
var queries = new List<IQuery<NullDbContext>>()
{
new QueryTypeNullDbContextOne(dbContext),
new QueryTypeNullDbContextTwo(dbContext),
new QueryTypeNullDbContextThree(dbContext)
};
var queries = _testBuilderFactory.CreateNullDbContextObjectQueries(dbContext);

// Act
var result = queries.IgnoreExcludedQueries(false).Count();

// Assert
Assert.Equal(3, result);
}

public void Dispose() => _testBuilderFactory = null;
}
}
12 changes: 11 additions & 1 deletion src/Queryology.Tests/TestBuilders/TestBuilderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using ByteDecoder.Queryology.Tests.Queries;
using Microsoft.EntityFrameworkCore;

namespace ByteDecoder.Queryology.Tests.TestBuilders
{
Expand All @@ -8,5 +10,13 @@ internal class TestBuilderFactory
{
return new QueryologyEngineTestBuilder<T>();
}

public IEnumerable<IQuery<NullDbContext>> CreateNullDbContextObjectQueries(NullDbContext dbContext) =>
new List<IQuery<NullDbContext>>()
{
new QueryTypeNullDbContextOne(dbContext),
new QueryTypeNullDbContextTwo(dbContext),
new QueryTypeNullDbContextThree(dbContext)
};
}
}

0 comments on commit 2c2fd2a

Please sign in to comment.