public async Task AddAndDeleteNewSolarSystem_Ok() { //Arrange var id = Guid.NewGuid(); var system = new SolarSystem { Id = id, Name = "Test" }; //Act await m_repository.CreateAsync(system); //Assert var(_, systems) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new SolarSystemFilter { SearchTerm = id.ToString() }); Assert.Equal(id, systems.First().Id); Assert.Equal("Test", systems.First().Name); await m_repository.DeleteAsync(system); var(_, emptyResponse) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new SolarSystemFilter { SearchTerm = id.ToString() }); Assert.Empty(emptyResponse); }
public async Task CreateSolarSystemAsync(SolarSystem solarSystem) { try { var validationError = solarSystem.Validate(); if (validationError.Any()) { throw new ValidationException($"A validation exception was raised while trying to create a solar system : {JsonConvert.SerializeObject(validationError, Formatting.Indented)}"); } await m_repository.CreateAsync(solarSystem); } 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 solar system with the properties : {JsonConvert.SerializeObject(solarSystem, Formatting.Indented)}"); throw; } }