Skip to content

Commit

Permalink
moved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormgate1998 committed Sep 22, 2023
1 parent 1468a44 commit 4462073
Show file tree
Hide file tree
Showing 103 changed files with 221 additions and 177 deletions.
8 changes: 4 additions & 4 deletions src/api-tests/ControllerTests/AdminControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public class AdminControllerTest

public static AdminController GetAdminController()
{
var context = TestHelpers.CreateContext();
var donationRepository = new DonationRepository(context, TestHelpers.AspenMapper);
var eventRepository = new EventRepository(context, TestHelpers.AspenMapper);
return new AdminController(donationRepository, eventRepository, TestHelpers.AspenMapper);
AspenContext context = TestHelpers.CreateContext();
IDonationRepository donationRepository = new DonationRepository(context, TestHelpers.AspenMapper);
IAdminService adminService = new AdminService(donationRepository, TestHelpers.AspenMapper);
return new AdminController(adminService);
}

[SetUp]
Expand Down
2 changes: 1 addition & 1 deletion src/api-tests/ControllerTests/DonationControllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Api.Extensions;
using v2.Extensions;
using Microsoft.Extensions.Logging;
using Tests.Steps;

Expand Down
6 changes: 3 additions & 3 deletions src/api-tests/ControllerTests/LinkContorllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Api.Controllers;
using Api.Extensions;
using v2.Controllers;
using v2.Extensions;
using Microsoft.Extensions.Logging;
using shared.DtoModels;
using Tests;
using Tests.ControllerTests;
using Tests.Steps;

namespace Api.Tests.Controllers
namespace v2.Tests.Controllers
{
[TestFixture]
public class LinkControllerTests
Expand Down
6 changes: 3 additions & 3 deletions src/api-tests/ControllerTests/LinkRecordContorllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Api.Controllers;
using Api.Extensions;
using v2.Controllers;
using v2.Extensions;
using Microsoft.Extensions.Logging;
using shared.DtoModels;
using Tests;
using Tests.ControllerTests;
using Tests.Steps;

namespace Api.Tests.Controllers
namespace v2.Tests.Controllers
{
[TestFixture]
public class LinkRecordControllerTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Api.DataAccess;
using Api.DbModels;
using v2.DataAccess;
using v2.DbModels;
using Microsoft.Extensions.Logging;
using shared.DtoModels;
using TechTalk.SpecFlow.CommonModels;
Expand Down
2 changes: 1 addition & 1 deletion src/api-tests/ControllerTests/TeamControllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Api.DataAccess;
using v2.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Net.Http.Json;
Expand Down
8 changes: 4 additions & 4 deletions src/api-tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global using Api.Controllers;
global using Api.DataAccess;
global using Api.Models.Entities;
global using Api.Services;
global using v2.Controllers;
global using v2.DataAccess;
global using v2.Models.Entities;
global using v2.Services;
global using FluentAssertions;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
Expand Down
2 changes: 1 addition & 1 deletion src/api-tests/Hooks/Hooks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Api.Mappers;
using v2.Mappers;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
using Docker.DotNet;
using Docker.DotNet.Models;
Expand Down
2 changes: 1 addition & 1 deletion src/api-tests/TestHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Api.Mappers;
using v2.Mappers;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Tests.Hooks;
Expand Down
33 changes: 11 additions & 22 deletions src/combined/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
namespace Api.Controllers;
namespace v2.Controllers;

[ApiController]
[Authorize(Roles = AspenAdminRole)]
[Route("/api/[controller]")]
public class AdminController : ControllerBase
{
public const string AspenAdminRole = "admin-aspen";
private readonly IDonationRepository donationRepository;
private readonly IEventRepository eventRepository;
private readonly IMapper mapper;

public AdminController(IDonationRepository donationRepository, IEventRepository eventRepository, IMapper mapper)

private IAdminService service;
public AdminController(IAdminService service)
{
this.donationRepository = donationRepository;
this.eventRepository = eventRepository;
this.mapper = mapper;
this.service = service;
}

[HttpGet]
public IEnumerable<UserClaim> Get() =>
User.Claims.Select(c => new UserClaim(c.Type.ToString(), c.Value.ToString()));

//[HttpGet("donation/{eventID}")]
//public async Task<IEnumerable<DtoDonation>> GetEventDonations(long eventID)
//{
// //var donations = await donationRepository.GetByEventIdAsync(eventID);
// return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
//}
public IEnumerable<UserClaim> Get()
{
return User.Claims.Select(c => new UserClaim(c.Type.ToString(), c.Value.ToString()));
}

[HttpGet("donation/{eventID}/{teamID}")]
public async Task<IEnumerable<DtoDonation>> GetTeamDonations( long teamID)
{
var donations = await donationRepository.GetByTeamIdAsync(teamID);
return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
return await service.GetTeamDonationsAsync(teamID);
}

[HttpGet("donations/event/{eventID}")]
public async Task<IEnumerable<DtoDonation>> GetEventDonations(long eventID)
{
var donations = await donationRepository.GetByEventIdAsync(eventID);
return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
return await service.GetEventDonationsAsync(eventID);
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/combined/Controllers/AssetController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Controllers;
namespace v2.Controllers;

public record Response<T> { public T Data { get; init; } }

Expand All @@ -17,7 +17,12 @@ public AssetController(IAssetFileService assetsFileService, ILogger<AssetControl
this.logger = logger;
}

[SwaggerOperation(Summary = "Endpoint for users to upload file assets.", Description = "Recieves one file in FormData that has the key 'asset'. Returned data value can be accessed at that can be accessed at /assets/{data}")]
[SwaggerOperation(
Summary = "Endpoint for users to upload file assets.",
Description = "Recieves one file in FormData that has the key 'asset'. " +
"Returned data value can be accessed at that can be accessed at /assets/{data}")
]

[HttpPost]
public async Task<ActionResult<Response<string>>> PostAsync([FromForm] IFormFile asset)
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/Controllers/DonationController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Controllers;
namespace v2.Controllers;

[Route("api/donations")]
[ApiController]
Expand Down
2 changes: 1 addition & 1 deletion src/combined/Controllers/EventController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace Api.Controllers;
namespace v2.Controllers;

[Route("api/events")]
[ApiController]
Expand Down
2 changes: 1 addition & 1 deletion src/combined/Controllers/LinkController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Net;
namespace Api.Controllers;
namespace v2.Controllers;

[Route("api/links")]
[ApiController]
Expand Down
2 changes: 1 addition & 1 deletion src/combined/Controllers/LinkRecordContorller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Net;
namespace Api.Controllers;
namespace v2.Controllers;

[Route("api/linkrecords")]
[ApiController]
Expand Down
24 changes: 16 additions & 8 deletions src/combined/Controllers/PersonController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace Api.Controllers;
namespace v2.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down Expand Up @@ -28,55 +28,62 @@ public PersonController(IPersonRepository personRepository, IMapper mapper, ILog
public async Task<ActionResult<DtoPerson>> GetByID(long id)
{
log.LogInformation("Getting person {id}", id);

if (!await personRepository.ExistsAsync(id))
return NotFound("Person id does not exist");

var person = await personRepository.GetByIDAsync(id);

return mapper.Map<DtoPerson>(person);
}


[HttpGet("authid/{authId}"), Authorize]
public async Task<ActionResult<DtoPerson>> GetByAuthId(string authId)
{
log.LogInformation("Getting person AuthId {authId}", authId);

var person = await personRepository.GetByAuthIdAsync(authId);

if (person == null)
return NotFound("AuthID does not exist");

return mapper.Map<DtoPerson>(person);
}

[HttpPost]
public async Task<ActionResult<DtoPerson>> Add([FromBody] DtoPerson dtoPerson)
{
log.LogInformation("Adding person {dtoPerson}", dtoPerson);

if (!ModelState.IsValid)
return BadRequest(getModelStateErrorMessage());

if (dtoPerson.ID != 0)
return BadRequest("Cannot add with a valid id");

if (dtoPerson.AuthID != null)
return BadRequest("Don't create users with authid using this endpoint. This endpoint is really only for creating people to be used in a PersonRegistration.");

if (string.IsNullOrEmpty(dtoPerson.AuthID))
{
var person = await personRepository.AddAsync(dtoPerson.Name, dtoPerson.Bio, dtoPerson.Nickname);
return mapper.Map<DtoPerson>(person);
return BadRequest("Don't create users with authid using this endpoint. " +
"This endpoint is really only for creating people to be used in a PersonRegistration.");
}
else
{
var person = await personRepository.AddAsync(dtoPerson.Name, dtoPerson.Bio, dtoPerson.AuthID, dtoPerson.Nickname);
var person = await personRepository.AddAsync(dtoPerson.Name, dtoPerson.Bio, dtoPerson.Nickname);
return mapper.Map<DtoPerson>(person);
}

}


[HttpPut(), Authorize]
public async Task<ActionResult<DtoPerson>> Edit([FromBody] DtoPerson dtoPerson)
{
log.LogInformation("Editing person {dtoPerson}", dtoPerson);

if (!ModelState.IsValid)
return BadRequest(getModelStateErrorMessage());

if (!await personRepository.ExistsAsync(dtoPerson.ID))
return NotFound("Person id does not exist");

Expand All @@ -89,6 +96,7 @@ public async Task<ActionResult<DtoPerson>> Edit([FromBody] DtoPerson dtoPerson)
public async Task<IActionResult> Delete(long id)
{
log.LogInformation("Deleting person {id}", id);

if (!await personRepository.ExistsAsync(id))
return NotFound("Person id does not exist");

Expand Down
4 changes: 2 additions & 2 deletions src/combined/Controllers/PersonTeamAssociationController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using Api.DataAccess;
using v2.DataAccess;

namespace Api.Controllers;
namespace v2.Controllers;

//[Authorize]
[Route("api/[controller]")]
Expand Down
6 changes: 3 additions & 3 deletions src/combined/Controllers/StripeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using static System.Net.WebRequestMethods;
using System.Net;
using shared;
using Person = Api.Models.Entities.Person;
using Api.DataAccess;
using Person = v2.Models.Entities.Person;
using v2.DataAccess;
using AutoMapper;
using Serilog;

namespace Api.Controllers;
namespace v2.Controllers;
[Route("api/stripe")]
[ApiController]
public class StripeController : ControllerBase
Expand Down
4 changes: 2 additions & 2 deletions src/combined/Controllers/TeamController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

namespace Api.Controllers;
namespace v2.Controllers;

using Api.DataAccess;
using v2.DataAccess;
using NuGet.Protocol;
using Serilog;

Expand Down
2 changes: 1 addition & 1 deletion src/combined/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text;
namespace Api.Controllers;
namespace v2.Controllers;
using Serilog;

[ApiController]
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/AspenContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using combined.Models.DbModels;

namespace Api.DataAccess;
namespace v2.DataAccess;

public class AspenContext : DbContext
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/DonationRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

public interface IDonationRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/EventRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

public interface IEventRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/LinkRecordRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

public interface ILinkRecordRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/LinkRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

public interface ILinkRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/PaymentFailureRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using combined.Models.DbModels;
using combined.Models.Entities;

namespace Api.DataAccess;
namespace v2.DataAccess;

public interface IPaymentFailureRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/PersonRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

public interface IPersonRepository
{
Expand Down
2 changes: 1 addition & 1 deletion src/combined/DataAccess/PersonTeamAssoicationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Serilog;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Api.DataAccess;
namespace v2.DataAccess;

public interface IPersonTeamAssoicationRepository
{
Expand Down
4 changes: 2 additions & 2 deletions src/combined/DataAccess/TeamRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Api.DataAccess;
namespace v2.DataAccess;

using Api.Models.Entities;
using v2.Models.Entities;
using Microsoft.Extensions.Logging;

public interface ITeamRepository
Expand Down
2 changes: 1 addition & 1 deletion src/combined/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Exceptions;
namespace v2.Exceptions;

public class NotFoundException<T> : Exception where T : class
{
Expand Down
Loading

0 comments on commit 4462073

Please sign in to comment.