mirror of
https://github.com/Biarity/Sieve.git
synced 2025-07-27 12:43:13 +02:00
Basic working & complete tests
This commit is contained in:
55
SieveTests/Controllers/TestController.cs
Normal file
55
SieveTests/Controllers/TestController.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
|
||||
namespace SieveTests.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class TestController : Controller
|
||||
{
|
||||
private ISieveProcessor<Post> _sieveProcessor;
|
||||
private ApplicationDbContext _dbContext;
|
||||
|
||||
public TestController(ISieveProcessor<Post> sieveProcessor,
|
||||
ApplicationDbContext dbContext)
|
||||
{
|
||||
_sieveProcessor = sieveProcessor;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult GetAllWithSieve(SieveModel sieveModel)
|
||||
{
|
||||
var result = _dbContext.Posts.AsNoTracking();
|
||||
|
||||
result = _sieveProcessor.ApplyAll(sieveModel, result);
|
||||
|
||||
return Json(result.ToList());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult Create(int number = 10)
|
||||
{
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
_dbContext.Posts.Add(new Post());
|
||||
}
|
||||
|
||||
_dbContext.SaveChanges();
|
||||
|
||||
return Json(_dbContext.Posts.ToList());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult GetAll()
|
||||
{
|
||||
return Json(_dbContext.Posts.ToList());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SieveTests.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
public class ValuesController : Controller
|
||||
{
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public IEnumerable<string> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
[HttpGet("{id}")]
|
||||
public string Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST api/values
|
||||
[HttpPost]
|
||||
public void Post([FromBody]string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/values/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody]string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user