public async Task <Student> GetOrCreateAsync(string id, School school) { if (id is null) { throw new ArgumentNullException(nameof(id)); } if (school is null) { throw new ArgumentNullException(nameof(school)); } var student = await _dbContext.Students.Include(_ => _.Orders) .FirstOrDefaultAsync(_ => _.Id == id && _.School.Id == school.Id) .ConfigureAwait(false); if (student is null) { student = new Student { School = school, Id = id }; await _dbContext.AddAsync(student); await _dbContext.SaveChangesAsync(); } return(student); }
public async Task Handle_Success_NoCondition() { var barman = new Barman() { Id = Guid.NewGuid().ToString() }; await _dbContext.AddAsync(barman); await _dbContext.SaveChangesAsync(); var claimPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new [] { new Claim(ClaimTypes.NameIdentifier, barman.Id) })); Assert.IsType <Barman>(await _handler.HandleAsync(claimPrincipal)); _loggerMock.VerifyNoOtherCalls(); }