mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-12 11:46:40 +00:00
-
This commit is contained in:
parent
e3f8d5df6c
commit
611289c02f
5 changed files with 44 additions and 5 deletions
|
|
@ -38,7 +38,6 @@ namespace TicketManager.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public async Task<IEnumerable<Project>> GetProjects()
|
public async Task<IEnumerable<Project>> GetProjects()
|
||||||
{
|
{
|
||||||
|
|
||||||
return await _projects.List();
|
return await _projects.List();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +195,7 @@ namespace TicketManager.Controllers
|
||||||
/// <response code="404">Not Found</response>
|
/// <response code="404">Not Found</response>
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[HttpPut("{id}/members")]
|
[HttpPatch("{id}/members")]
|
||||||
public async Task<ActionResult<Project>> SetProjectMembers(int id, List<AppUser> projectMembers)
|
public async Task<ActionResult<Project>> SetProjectMembers(int id, List<AppUser> projectMembers)
|
||||||
{
|
{
|
||||||
Project project = await _projects.Get(id);
|
Project project = await _projects.Get(id);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ namespace TicketManager.Data
|
||||||
.Include(p => p.Assignments).ThenInclude(a => a.User)
|
.Include(p => p.Assignments).ThenInclude(a => a.User)
|
||||||
.Include(p => p.Tickets)
|
.Include(p => p.Tickets)
|
||||||
.Include(p => p.Manager)
|
.Include(p => p.Manager)
|
||||||
.Include(p => p.Files);
|
.Include(p => p.Files)
|
||||||
|
// .AsNoTracking()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<Project> Get(int id)
|
public override async Task<Project> Get(int id)
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,10 @@ namespace TicketManager.Models
|
||||||
public void RemoveMembers(List<AppUser> membersToRemove)
|
public void RemoveMembers(List<AppUser> membersToRemove)
|
||||||
{
|
{
|
||||||
this.Assignments.RemoveAll(a => membersToRemove.Contains(a.User));
|
this.Assignments.RemoveAll(a => membersToRemove.Contains(a.User));
|
||||||
|
|
||||||
|
// membersToRemove.ForEach(
|
||||||
|
// m => m.Assignments.RemoveAll(a => (a.Project == this))
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMembers(List<AppUser> projectMembers)
|
public void SetMembers(List<AppUser> projectMembers)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,11 @@ namespace TicketManager
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddDbContext<AppDbContext>(options =>
|
services.AddDbContext<AppDbContext>(options =>
|
||||||
options.UseSqlite(Configuration.GetConnectionString("Sqlite")));
|
{
|
||||||
|
options.UseSqlite(Configuration.GetConnectionString("Sqlite"));
|
||||||
|
options.EnableSensitiveDataLogging(true); //Remove in production.
|
||||||
|
}
|
||||||
|
);
|
||||||
services.AddScoped<IProjectRepository, ProjectRepository>();
|
services.AddScoped<IProjectRepository, ProjectRepository>();
|
||||||
services.AddScoped<IAppUserRepository, AppUserRepository>();
|
services.AddScoped<IAppUserRepository, AppUserRepository>();
|
||||||
services.AddScoped<ITicketRepository, TicketRepository>();
|
services.AddScoped<ITicketRepository, TicketRepository>();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using Moq;
|
||||||
using TicketManager.Controllers;
|
using TicketManager.Controllers;
|
||||||
using TicketManager.Data;
|
using TicketManager.Data;
|
||||||
using TicketManager.Models;
|
using TicketManager.Models;
|
||||||
|
using TicketManager.DTO;
|
||||||
|
|
||||||
namespace TicketManager.Tests
|
namespace TicketManager.Tests
|
||||||
{
|
{
|
||||||
|
|
@ -28,6 +28,22 @@ namespace TicketManager.Tests
|
||||||
var viewResult = Assert.IsAssignableFrom<IEnumerable<Project>>(result);
|
var viewResult = Assert.IsAssignableFrom<IEnumerable<Project>>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Get1_ReturnsProject1()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockRepo = new Mock<IProjectRepository>();
|
||||||
|
mockRepo.Setup(r => r.Get(1));
|
||||||
|
// .ReturnsAsync(GetProjectDTO());
|
||||||
|
var controller = new ProjectsController(mockRepo.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await controller.GetProject(1);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var viewResult = Assert.IsAssignableFrom<Project>(result);
|
||||||
|
}
|
||||||
|
|
||||||
private List<Project> GetTestProjects()
|
private List<Project> GetTestProjects()
|
||||||
{
|
{
|
||||||
var projects = new List<Project>();
|
var projects = new List<Project>();
|
||||||
|
|
@ -46,6 +62,20 @@ namespace TicketManager.Tests
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProjectDTO GetProjectDTO()
|
||||||
|
{
|
||||||
|
var project = new Project()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
PlannedEnding = new DateTime(2016, 7, 2),
|
||||||
|
Title = "Test One",
|
||||||
|
Description = "Lorem Ipsum",
|
||||||
|
Status = Status.InProgress
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ProjectDTO(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// [Fact]
|
// [Fact]
|
||||||
// public void Get_ReturnsProjectList()
|
// public void Get_ReturnsProjectList()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue