Beispiel #1
0
        public void ReadDroneByIdWithNoDroneFoundThrowsException()
        {
            var           droneRepo    = new Mock <IDroneRepository>();
            IDroneService droneService = new DroneService(droneRepo.Object);

            var drone = new Drone()
            {
                Id           = 1,
                Manufacturer = new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Phantom",
                    Drones = new List <Drone>()
                    {
                        new Drone()
                    }
                },
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            droneRepo.Setup(x => x.ReadById(drone.Id)).Returns(() => drone = null);

            var e = Assert.Throws <ArgumentException>(() => droneService.ReadById(drone.Id));

            Assert.Equal("Could not find any drones with the entered id", e.Message);
        }
Beispiel #2
0
        public void CreateDroneNoManufacturerException()
        {
            var           droneRepo = new Mock <IDroneRepository>();
            IDroneService service   = new DroneService(droneRepo.Object);
            Drone         drone     = new Drone()
            {
                Id = 1,

                /*Manufacturer = new Manufacturer()
                 * {
                 *  Id = 1,
                 *  Name = "Phantom",
                 *  Drones = new List<Drone>()
                 *  {
                 *      new Drone()
                 *  }
                 * },*/
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            Exception e = Assert.Throws <ArgumentException>(() => service.Create(drone));

            Assert.Equal("Manufacturer cannot be null or empty", e.Message);
        }
Beispiel #3
0
        public void CreateDroneEnsureRepositoryIsCalled()
        {
            var           droneRepo = new Mock <IDroneRepository>();
            IDroneService service   = new DroneService(droneRepo.Object);

            var isCalled = false;

            var drone = new Drone()
            {
                Id           = 1,
                Manufacturer = new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Phantom",
                    Drones = new List <Drone>()
                    {
                        new Drone()
                    }
                },
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            droneRepo.Setup(x => x.Create(drone)).Callback(() => isCalled = true).Returns(drone);

            service.Create(drone);

            Assert.True(isCalled);
        }
Beispiel #4
0
        public void ReadDroneByIdWithIdLowerThan1ThrowsException()
        {
            var           droneRepo    = new Mock <IDroneRepository>();
            IDroneService droneService = new DroneService(droneRepo.Object);

            var drone = new Drone()
            {
                Id           = 0,
                Manufacturer = new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Phantom",
                    Drones = new List <Drone>()
                    {
                        new Drone()
                    }
                },
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            var e = Assert.Throws <ArgumentException>(() => droneService.ReadById(drone.Id));

            Assert.Equal("The Id entered has to be at least 1", e.Message);
        }
        public void finalizaPedido()
        {
            PedidoDrone pedidoUm = new PedidoDrone()
            {
                Id = 1, StatusEnvio = (int)StatusEnvio.EM_TRANSITO
            };
            PedidoDrone pedidoDois = new PedidoDrone()
            {
                Id = 2, StatusEnvio = (int)StatusEnvio.EM_TRANSITO
            };

            List <PedidoDrone> listPedidoDrones = new List <PedidoDrone> {
                pedidoUm, pedidoDois
            };

            var _pedidoDroneRepository = Substitute.For <IPedidoDroneRepository>();

            _pedidoDroneRepository.RetornaPedidosParaFecharAsync().Returns(listPedidoDrones);

            ICoordinateService _coordinateService = null;
            IDroneRepository   _droneRepository   = null;
            IPedidoRepository  _pedidoRepository  = null;

            var droneService = new DroneService(_coordinateService, _pedidoDroneRepository, _droneRepository, _pedidoRepository);

            droneService.FinalizaPedidosAsync().Wait();

            var existepedidoComStatusDiferenteDeFinalizado = listPedidoDrones.Any(_ => _.StatusEnvio != (int)StatusEnvio.FINALIZADO);

            Assert.True(!existepedidoComStatusDiferenteDeFinalizado);
        }
Beispiel #6
0
        public void UpdateDroneWithoutImageURLExeption()
        {
            var           droneRepo    = new Mock <IDroneRepository>();
            IDroneService droneService = new DroneService(droneRepo.Object);

            var drone = new Drone()
            {
                Id           = 1,
                Manufacturer = new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Phantom",
                    Drones = new List <Drone>()
                    {
                        new Drone()
                    }
                },
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                //ImageURL = "www.imgUrl.com"
            };

            var e = Assert.Throws <ArgumentException>(() => droneService.Update(drone));

            Assert.Equal("ImageURL cannot be null or empty", e.Message);
        }
        public void RetornarStatusDrone()
        {
            var sddUm = new StatusDroneDto {
                ClienteId = 1, PedidoId = 1
            };
            var sddDois = new StatusDroneDto {
                ClienteId = 2, PedidoId = 2
            };

            var listSdd = new List <StatusDroneDto> {
                sddUm, sddDois
            };

            var _droneRepository = new Mock <IDroneRepository>();

            _droneRepository.Setup(_ => _.GetDroneStatus()).Returns(listSdd);

            ICoordinateService     _coordinateService     = null;
            IPedidoDroneRepository _pedidoDroneRepository = null;
            IPedidoRepository      _pedidoRepository      = null;

            var droneService = new DroneService(_coordinateService, _pedidoDroneRepository, _droneRepository.Object, _pedidoRepository);

            var result = droneService.GetDroneStatus();

            Assert.True(result.Count() == 2, "A quantidade de registros retornados não esperada");
        }
Beispiel #8
0
        public void DeliverOrders(string inFilePath, string outFilePath)
        {
            var filesInfo = Directory.GetFiles(inFilePath, "in*.txt").Select(fn => new FileInfo(fn))
                            .Take(_deliverySettings.MaxDroneCount).ToList();

            IDroneService droneService = new DroneService(_deliverySettings);

            filesInfo.AsParallel().ForAll(fi => DeliverOrdersForFile(droneService, fi));
        }
        public void Should_Not_Pass_Code_Validation_For_Empty_Code(String code)
        {
            IDroneRepository droneRepository = new Mock <IDroneRepository>().Object;
            DroneService     droneService    = new DroneService(droneRepository);

            Boolean isValid = droneService.IsCodeValid(code);

            Assert.False(isValid);
        }
        public void ValidarDistancia(int somaDistancia, double distanciaRetorno, double pedidoDroneDistancia, float performanceDrone, bool resultadoEsperado, string mensagemErro)
        {
            var drone = new Drone {
                Id = 1, Capacidade = 500, Velocidade = 40, Autonomia = 50, Carga = 80, Perfomance = performanceDrone
            };

            DroneStatusDto dtoDroneStatus = new DroneStatusDto {
                Drone = drone, SomaDistancia = somaDistancia, SomaPeso = 300
            };

            Assert.True(resultadoEsperado == DroneService.ValidaDistancia(dtoDroneStatus, distanciaRetorno, pedidoDroneDistancia), mensagemErro);
        }
Beispiel #11
0
        public void ReadAllDronesIncludeManufacturersEnsureRepositoryIsCalled()
        {
            var           droneRepo = new Mock <IDroneRepository>();
            IDroneService service   = new DroneService(droneRepo.Object);

            var isCalled = false;

            droneRepo.Setup(x => x.GetAllDronesIncludeManufacturers()).Callback(() => isCalled = true).Returns(new FilteredList <Drone>());

            service.GetAllDronesIncludeManufacturers();
            Assert.True(isCalled);
        }
Beispiel #12
0
        public void ShouldNotDeliverMoreThanTenBlocks()
        {
            uint droneId      = 1;
            var  droneService = new DroneService(DeliverySettings.Create(blocksToDeliver: 10));
            var  commandList  = new List <string> {
                "AAAAAAAAAAA", "AAAIAAA", "IAAAIAAA"
            };
            var expectedList = new List <string> {
                DroneService.OUTFILE_HEADER, "(0, 0) Ahead North", "(-3, 3) Ahead West", "(0, 0) Ahead East"
            };

            DeliverOrdersAndAssert(droneService, droneId, commandList, expectedList);
        }
Beispiel #13
0
        public void ShouldNotDeliverMoreThanThreeOrders()
        {
            uint droneId      = 1;
            var  droneService = new DroneService(DeliverySettings.Create());
            var  commandList  = new List <string> {
                "AAAAIAA", "DDDAIAD", "AAIADAD", "IGNORED"
            };
            var expectedList = new List <string> {
                DroneService.OUTFILE_HEADER, "(-2, 4) Ahead West", "(-1, 3) Ahead South", "(0, 0) Ahead West"
            };

            DeliverOrdersAndAssert(droneService, droneId, commandList, expectedList);
        }
Beispiel #14
0
        public void ShouldReturnDronePositionFromCommandList_AsUnderstood()
        {
            uint droneId      = 1;
            var  droneService = new DroneService(DeliverySettings.Create());
            var  commandList  = new List <string> {
                "AAAAIAA", "DDDAIAD", "AAIADAD"
            };
            var expectedList = new List <string> {
                DroneService.OUTFILE_HEADER, "(-2, 4) Ahead West", "(-1, 3) Ahead South", "(0, 0) Ahead West"
            };

            DeliverOrdersAndAssert(droneService, droneId, commandList, expectedList);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DroneCommands"/> class.
 /// </summary>
 /// <param name="drone">The drone service.</param>
 /// <param name="feedback">The feedback service.</param>
 /// <param name="content">The content service.</param>
 /// <param name="context">The command context.</param>
 public DroneCommands
 (
     DroneService drone,
     FeedbackService feedback,
     ContentService content,
     ICommandContext context
 )
 {
     _drone    = drone;
     _feedback = feedback;
     _content  = content;
     _context  = context;
 }
        public void ConsultarStatusDrone()
        {
            ICoordinateService     coordinateService     = new CoordinateService();
            IPedidoDroneRepository pedidoDroneRepository = null;
            IDroneRepository       droneRepository       = new MockDroneRepository();

            IPedidoRepository pedidoRepository = null;

            IDroneService droneService = new DroneService(coordinateService, pedidoDroneRepository, droneRepository, pedidoRepository);

            droneService.GetDroneStatusAsync();

            Assert.Equal <int>(2, droneService.GetDroneStatusAsync().Count);
        }
Beispiel #17
0
        public void ConsultarStatusDrone()
        {
            var coordinateService = new CoordinateService();
            IPedidoDroneRepository pedidoDroneRepository = null;
            var context         = Substitute.For <DataContext>();
            var droneRepository = new MockDroneRepository(context);
            PedidoRepository pedidoRepository = null;

            var droneService = new DroneService(coordinateService, pedidoDroneRepository, droneRepository, pedidoRepository);

            var droneStatus = droneService.GetDroneStatus();

            Assert.Equal <int>(2, droneStatus.Count);
        }
        public void ValidarPeso(int capacidadeDrone, int droneSomaPeso, int pedidoPeso, bool resultadoEsperado, string mensagemErro)
        {
            var drone = new Drone {
                Id = 1, Capacidade = capacidadeDrone, Velocidade = 40, Autonomia = 50, Carga = 80, Perfomance = 33.3F
            };

            DroneStatusDto dtoDroneStatus = new DroneStatusDto {
                Drone = drone, SomaDistancia = 50, SomaPeso = droneSomaPeso
            };

            Pedido pedido = new Pedido {
                ClienteId = 1, Peso = pedidoPeso
            };

            Assert.True(resultadoEsperado == DroneService.ValidaPeso(dtoDroneStatus, pedido), mensagemErro);
        }
        public async Task TestDroneAtendePedidoQuandoDroneExiste()
        {
            var droneService = new DroneService(_coordinateService,
                                                _pedidoDroneRepository,
                                                _droneRepository,
                                                _pedidoRepository);
            var pedidoService = new PedidoService(droneService, _coordinateService);

            _coordinateService.GetKmDistance(Arg.Any <Point>(), Arg.Any <Point>())
            .Returns(10);
            _pedidoDroneRepository.RetornaPedidosEmAbertoAsync().Returns(SetupTests.GetPedidoDrones(StatusEnvio.AGUARDANDO));
            _droneRepository.RetornaDroneStatus(Arg.Any <int>())
            .Returns(SetupTests.GetDroneStatusDto());
            var drone = await pedidoService.DroneAtendePedido(SetupTests.GetPedido());

            Assert.True(drone != null);
        }
        public void Should_Return_Correct_Filtered_Drones_By_Filter(String droneCode, Int32?droneType, Int32 count)
        {
            Mock <IDroneRepository> droneRepository = new Mock <IDroneRepository>();

            droneRepository.Setup(_ => _.GetAll(It.IsAny <Expression <Func <Drone, Boolean> > >(),
                                                It.IsAny <Func <IQueryable <Drone>, IQueryable <Drone> > >())).Returns(GetTestDrones());

            DroneService droneService = new DroneService(droneRepository.Object);

            DroneListFilter filter = new DroneListFilter
            {
                DroneCode = droneCode,
                DroneType = droneType
            };


            ICollection <Drone> filteredDrones = droneService.GetDronesByPersonId(String.Empty, filter);

            Assert.Equal(count, filteredDrones.Count);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DroneCommands"/> class.
 /// </summary>
 /// <param name="drone">The drone service.</param>
 /// <param name="feedback">The feedback service.</param>
 /// <param name="content">The content service.</param>
 public DroneCommands(DroneService drone, UserFeedbackService feedback, ContentService content)
 {
     _drone    = drone;
     _feedback = feedback;
     _content  = content;
 }
 public DroneController(DroneService <DroneViewModel, Drone> droneService)
 {
     _droneService = droneService;
     var d = User;
 }
 public MainViewModel()
 {
     _droneService    = DroneService.Instance;
     WeatherViewModel = new WeatherViewModel();
 }