public async Task AddAndDeleteNewPlanet_Ok()
        {
            //Arrange
            var id     = Guid.NewGuid();
            var system = new Planet
            {
                Id   = id,
                Name = "Test"
            };

            //Act
            await m_repository.CreateAsync(system);

            //Assert
            var(_, planets) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new PlanetFilter
            {
                SearchTerm = id.ToString()
            });

            Assert.Equal(id, planets.First().Id);
            Assert.Equal("Test", planets.First().Name);
            await m_repository.DeleteAsync(system);

            var(_, emptyResponse) = await m_repository.SearchAsync(new Pagination(), new Ordering(), new PlanetFilter
            {
                SearchTerm = id.ToString()
            });

            Assert.Empty(emptyResponse);
        }
Exemple #2
0
        public async Task CreatePlanetAsync(Planet planet)
        {
            try
            {
                var validationError = planet.Validate();
                if (validationError.Any())
                {
                    throw new ValidationException($"A validation exception was raised while trying to create a planet : {JsonConvert.SerializeObject(validationError, Formatting.Indented)}");
                }
                if (!await planet.ImageUrl.IsValidImageAsync())
                {
                    throw new ValidationException("The provided Image url is not a Valid Image");
                }
                await CheckSolarSystemExistsAsync(planet.SolarSystemId);

                await m_repository.CreateAsync(planet);
            }
            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 planet with the properties : {JsonConvert.SerializeObject(planet, Formatting.Indented)}");
                throw;
            }
        }