Implement DatabaseTests and SlotTests

This commit is contained in:
jvyden 2021-10-19 22:19:37 -04:00
parent 15e3870620
commit bbeb7d980e
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
3 changed files with 71 additions and 2 deletions

View file

@ -1,3 +1,4 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@ -22,11 +23,15 @@ namespace ProjectLighthouse {
);
public async Task<User> CreateUser(string username) {
User user;
if((user = await Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null)
return user;
Location l = new(); // store to get id after submitting
this.Locations.Add(l); // add to table
await this.SaveChangesAsync(); // saving to the database returns the id and sets it on this entity
User user = new() {
user = new() {
Username = username,
LocationId = l.Id,
Biography = username + " hasn't introduced themselves yet.",
@ -36,7 +41,6 @@ namespace ProjectLighthouse {
await this.SaveChangesAsync();
return user;
}
#nullable enable