mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
installed Moq
This commit is contained in:
parent
4e4cc5567b
commit
57880ab9ae
3 changed files with 37 additions and 4 deletions
|
|
@ -50,6 +50,7 @@ namespace TicketManager.Controllers
|
|||
/// GET: api/Projects/2
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="id">Identifier of the ressource</param>
|
||||
/// <response code="200">Returns a specific project</response>
|
||||
/// <response code="404">If the required project is null</response>
|
||||
[HttpGet("{id}")]
|
||||
|
|
|
|||
|
|
@ -1,21 +1,52 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using TicketManager.Controllers;
|
||||
using TicketManager.Data;
|
||||
using TicketManager.Models;
|
||||
|
||||
|
||||
namespace TicketManager.Tests
|
||||
{
|
||||
public class ProjectsControllerTests
|
||||
{
|
||||
|
||||
|
||||
public ProjectsControllerTests()
|
||||
[Fact]
|
||||
public async Task Get_ReturnsAListofProjects()
|
||||
{
|
||||
// _context = context;
|
||||
// Arrange
|
||||
var mockRepo = new Mock<IProjectRepository>();
|
||||
mockRepo.Setup(r => r.List())
|
||||
.ReturnsAsync(GetTestProjects());
|
||||
var controller = new ProjectsController(mockRepo.Object);
|
||||
|
||||
// Act
|
||||
var result = await controller.GetProjects();
|
||||
|
||||
// Assert
|
||||
var viewResult = Assert.IsAssignableFrom<IEnumerable<Project>>(result);
|
||||
}
|
||||
|
||||
private List<Project> GetTestProjects()
|
||||
{
|
||||
var projects = new List<Project>();
|
||||
projects.Add(new Project()
|
||||
{
|
||||
PlannedEnding = new DateTime(2016, 7, 2),
|
||||
Id = 1,
|
||||
Title = "Test One",
|
||||
});
|
||||
projects.Add(new Project()
|
||||
{
|
||||
PlannedEnding = new DateTime(2016, 7, 1),
|
||||
Id = 2,
|
||||
Title = "Test Two"
|
||||
});
|
||||
return projects;
|
||||
}
|
||||
|
||||
|
||||
// [Fact]
|
||||
// public void Get_ReturnsProjectList()
|
||||
// {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
|
||||
<PackageReference Include="Moq" Version="4.13.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.0.0" />
|
||||
<PackageReference Include="Xunit" Version="2.4.1" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue