public async Task AddAndDeleteNewShuttle_Ok() { //Arrange var id = Guid.NewGuid(); var shuttle = new Shuttle { Id = id, Name = "Test" }; //Act await m_repository.CreateAsync(shuttle); //Assert var(_, shuttles) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new ShuttleFilter { SearchTerm = id.ToString() }); Assert.Equal(id, shuttles.First().Id); Assert.Equal("Test", shuttles.First().Name); await m_repository.DeleteAsync(shuttle); var(_, emptyResponse) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new ShuttleFilter { SearchTerm = id.ToString() }); Assert.Empty(emptyResponse); }
public async Task CreateShuttleAsync(Shuttle shuttle) { try { var validationError = shuttle.Validate(); if (validationError.Any()) { throw new ValidationException($"A validation exception was raised while trying to create a Shuttle : {JsonConvert.SerializeObject(validationError, Formatting.Indented)}"); } await CheckExplorersTeamExistAsync(shuttle.ExplorersTeamId); await CheckExplorersTeamHaveNoShuttleAsync(shuttle.ExplorersTeamId); await m_repository.CreateAsync(shuttle); } catch (ValidationException e) { m_logger.LogWarning(e, "A validation failed"); throw; } catch (Exception e) when(e.GetType() != typeof(ValidationException)) { m_logger.LogCritical(e, $"Unexpected Exception while trying to create a Shuttle with the properties : {JsonConvert.SerializeObject(shuttle, Formatting.Indented)}"); throw; } }