// DELETE: api/Topic/5 public HttpResponseMessage Delete(string id) { var provider = new TrainerProvider(DbInfo); var deleted = provider.DeleteTrainer(id); return(Request.CreateResponse(HttpStatusCode.OK, deleted)); }
public HttpResponseMessage Get(string id) { var certification = new TrainerProvider(DbInfo).GetTrainer(int.Parse(id)); var exists = certification != null; var status = exists ? HttpStatusCode.OK : HttpStatusCode.NotFound; return(Request.CreateResponse(status, certification)); }
public async Task When_queried_for_multiple_nonexisting_guids_provider_returns_empty_collection() { var guid = Guid.NewGuid(); var trainerProvider = new TrainerProvider(BuildUserManagerMock(new[] { Guid.NewGuid() })); var trainers = await trainerProvider.GetTrainerDetails(new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }); Assert.Empty(trainers); }
public async Task When_queried_for_single_nonexisting_guid_provider_returns_none() { var guid = Guid.NewGuid(); var trainerProvider = new TrainerProvider(BuildUserManagerMock(new[] { guid })); var trainer = await trainerProvider.GetTrainerDetails(Guid.NewGuid()); Assert.False(trainer.HasValue); }
public async Task When_queried_for_single_existing_guid_provider_returns_trainer() { var guid = Guid.NewGuid(); var trainerProvider = new TrainerProvider(BuildUserManagerMock(new[] { guid })); var trainer = await trainerProvider.GetTrainerDetails(guid); Assert.True(trainer.HasValue); Assert.Equal(guid, trainer.Value.Guid); Assert.Equal(guid.ToString(), trainer.Value.Name); }
public async Task When_queried_for_duplicate_existing_guids_provider_returns_only_single_trainer() { var guid = Guid.NewGuid(); var trainerProvider = new TrainerProvider(BuildUserManagerMock(new[] { guid })); var trainers = await trainerProvider.GetTrainerDetails(new[] { guid, guid, guid }); var trainer = Assert.Single(trainers); Assert.Equal(guid, trainer.Guid); Assert.Equal(guid.ToString(), trainer.Name); }
public HttpResponseMessage GetTrainers(string id) { try { var trainers = new TrainerProvider(DbInfo).GetTrainers(id); return(Request.CreateResponse(HttpStatusCode.OK, trainers)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, ex.StackTrace)); } }
public HttpResponseMessage Post(Trainer trainer) { try { var provider = new TrainerProvider(DbInfo); var isSaved = provider.Save(trainer); return(Request.CreateResponse(HttpStatusCode.OK, isSaved)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.OK, ex.Message)); } }
public async Task When_queried_for_multiple_unique_existing_guids_provider_returns_trainer_for_each_of_them() { var guids = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var trainerProvider = new TrainerProvider(BuildUserManagerMock(guids)); var trainers = await trainerProvider.GetTrainerDetails(guids); Assert.Collection(trainers, first => { Assert.Equal(guids[0], first.Guid); Assert.Equal(guids[0].ToString(), first.Name); }, second => { Assert.Equal(guids[1], second.Guid); Assert.Equal(guids[1].ToString(), second.Name); }, third => { Assert.Equal(guids[2], third.Guid); Assert.Equal(guids[2].ToString(), third.Name); }); }