first unit test :)
This commit is contained in:
parent
5cd52c7814
commit
640782ed9e
@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicQuery.Test", "PoweredSoft.DynamicQuery.Test\PoweredSoft.DynamicQuery.Test.csproj", "{3EAD8217-8E10-4261-9055-50444905922C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{E4E954E0-66FA-4D72-979A-FB2EF8356A90}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4E954E0-66FA-4D72-979A-FB2EF8356A90}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4E954E0-66FA-4D72-979A-FB2EF8356A90}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3EAD8217-8E10-4261-9055-50444905922C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3EAD8217-8E10-4261-9055-50444905922C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3EAD8217-8E10-4261-9055-50444905922C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3EAD8217-8E10-4261-9055-50444905922C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
42
PoweredSoft.DynamicQuery.Test/CriteriaTests.cs
Normal file
42
PoweredSoft.DynamicQuery.Test/CriteriaTests.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PoweredSoft.DynamicQuery.Test.Mock;
|
||||
using Xunit;
|
||||
|
||||
namespace PoweredSoft.DynamicQuery.Test
|
||||
{
|
||||
public class CriteriaTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestEmptyCriteria()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<MockContext>().UseInMemoryDatabase(databaseName: "TestEmptyCriteria").Options;
|
||||
using (var ctx = new MockContext(options))
|
||||
{
|
||||
ctx.AddRange(new Item[]
|
||||
{
|
||||
new Item { Id = 1, Name = "Computer", Price = 1000M },
|
||||
new Item { Id = 2, Name = "Mice", Price = 25.99M },
|
||||
new Item { Id = 3, Name = "Keyboard", Price = 100M },
|
||||
new Item { Id = 4, Name = "Screen", Price = 499.98M },
|
||||
new Item { Id = 5, Name = "Printer", Price = 230.95M },
|
||||
});
|
||||
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
using (var ctx = new MockContext(options))
|
||||
{
|
||||
var resultShouldMatch = ctx.Items.ToList();
|
||||
var queryable = ctx.Items.AsQueryable();
|
||||
|
||||
// query handler that is empty should be the same as running to list.
|
||||
var criteria = new QueryCriteria();
|
||||
var queryHandler = new QueryHandler();
|
||||
var result = queryHandler.Execute(queryable, criteria);
|
||||
Assert.All(resultShouldMatch, t => result.Data.Contains(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
PoweredSoft.DynamicQuery.Test/Mock/Entities.cs
Normal file
50
PoweredSoft.DynamicQuery.Test/Mock/Entities.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PoweredSoft.DynamicQuery.Test.Mock
|
||||
{
|
||||
public class Order
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long OrderNum { get; set; }
|
||||
public long Date { get; set; }
|
||||
public long CustomerId { get; set; }
|
||||
|
||||
public virtual Customer Customer { get; set; }
|
||||
public ICollection<OrderItem> OrderItems { get; set; } = new HashSet<OrderItem>();
|
||||
}
|
||||
|
||||
public class Customer
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string AddressLine1 { get; set; }
|
||||
public string AddressLine2 { get; set; }
|
||||
public string City { get; set; }
|
||||
public string ProvinceOrState { get; set; }
|
||||
public string PostalCodeOrZip { get; set; }
|
||||
|
||||
|
||||
public ICollection<Order> Orders { get; set; } = new HashSet<Order>();
|
||||
}
|
||||
|
||||
public class Item
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public virtual ICollection<OrderItem> OrderItems { get; set; } = new HashSet<OrderItem>();
|
||||
}
|
||||
|
||||
public class OrderItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long Quantity { get; set; }
|
||||
public decimal PriceAtTheTime { get; set; }
|
||||
public long ItemId { get; set; }
|
||||
|
||||
public virtual Item Item { get; set; }
|
||||
public virtual Order Order { get; set; }
|
||||
}
|
||||
}
|
31
PoweredSoft.DynamicQuery.Test/Mock/MockContext.cs
Normal file
31
PoweredSoft.DynamicQuery.Test/Mock/MockContext.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PoweredSoft.DynamicQuery.Test.Mock
|
||||
{
|
||||
public class MockContext : DbContext
|
||||
{
|
||||
public virtual DbSet<Customer> Customers { get; set; }
|
||||
public virtual DbSet<Item> Items { get; set; }
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
public virtual DbSet<OrderItem> OrderItems { get; set; }
|
||||
|
||||
public MockContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MockContext(DbContextOptions<MockContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PoweredSoft.DynamicQuery\PoweredSoft.DynamicQuery.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -19,7 +19,7 @@ Criteria must implement the following interfaces
|
||||
|
||||
Object | Interface | Implementation | Example | Description
|
||||
-----------------|--------------------------------------------------------------------------|-------------------------------------------------------------------------------|--------------------------------------------------------|--------------------------------------------
|
||||
Query Criteria | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryCriteria.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/QueryCriteria.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Wraps the query parameters
|
||||
Query Criteria | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryCriteria.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/QueryCriteria.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/CriteriaTests.cs) | Wraps the query parameters
|
||||
Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a filter to be executed
|
||||
Simple Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ISimpleFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a simple filter to be executed
|
||||
Composite Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ICompositeFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a composite filter to be executed
|
||||
|
Loading…
Reference in New Issue
Block a user