Exemplo n.º 1
0
        public async Task Run()
        {
            try
            {
                _logger.LogInformation("Adding Area 1...");
                var name = "Area 1";

                var farmArea = new FarmArea(name);
                farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);
                farmArea.AddCoordinate(-18.154670446321067M, -50.53162693977356M);
                farmArea.AddCoordinate(-18.154201487543776M, -50.531712770462036M);
                farmArea.AddCoordinate(-17.842383165920296M, -46.25969409942627M);

                _logger.LogInformation("Validating...");
                var farmAreaExists = await _farmAreaRepository.GetByName(name);

                if (farmAreaExists != null)
                {
                    throw new DomainException("Area already exists");
                }

                farmArea.Validate();

                _farmAreaRepository.Add(farmArea);

                await _farmAreaRepository.UnitOfWork.Commit();

                _logger.LogInformation("Area 1 persisted!");
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error. {ex.Message}");
            }
        }
Exemplo n.º 2
0
        public void FarmArea_AddNewFarmAreaFail_ReturnsDomainException()
        {
            var farmArea = new FarmArea("Área 1");

            farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);
            farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);
            farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);
            farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);

            var exception = Assert.ThrowsAny <DomainException>(() => farmArea.Validate());
        }
Exemplo n.º 3
0
        public void FarmArea_AddNewFarmAreaSucceded_ReturnsTrue()
        {
            var farmArea = new FarmArea("Área 1");

            farmArea.AddCoordinate(-18.154384993302173M, -50.53218483924866M);
            farmArea.AddCoordinate(-18.154670446321067M, -50.53162693977356M);
            farmArea.AddCoordinate(-18.154201487543776M, -50.531712770462036M);
            farmArea.AddCoordinate(-17.842383165920296M, -46.25969409942627M);

            try
            {
                farmArea.Validate();
            }
            catch (DomainException ex)
            {
                Assert.True(ex == null, $"Domain exception. {ex.Message}");
            }
        }