/// <summary> /// Strategy to move carousel /// </summary> /// <param name="transactionData"></param> /// <param name="slot"></param> /// <returns></returns> public async Task <IDeviceResponse> MoveCarousel(TransactionData transactionData, Slot slot) { //Carousel specific parameter passing & property re-initialization before calling move method. if (_carousel is CarWhiteIpcDualAccess) { //TODO: Currently mocking the property : isOutsideComputer. The same to be received in event data bool isOutsideComputer = true; _deviceResponse = await _carousel.Move(slot : slot, transactionData : transactionData, isOutsideComputer : isOutsideComputer); } else if (_carousel is CarWhiteTb14702300) { if (transactionData.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel")).Attribute.IsDisplayAttached) { (_carousel as CarWhiteTb14702300).IgnoreSendMessage = true; } _deviceResponse = await _carousel.Move(slot : slot, transactionData : transactionData); } else if (_carousel is CarWhiteTB1470 || _carousel is CarWhiteTB1470H) { _deviceResponse = await _carousel.Move(slot : slot, transactionData : transactionData); } return(_deviceResponse); }
public async Task MoveCarouse__TransactionQueue_DeviceResponse_CarWhiteTB1470H_Positive() { //Assume IDeviceResponse expected = new DeviceResponse() { HasError = false }; CarouselFactory carouselFactory = new CarouselFactory(); Utility utility = new Utility(); CarouselManager objCarouselManager = new CarouselManager(_configuration, _logger.Object, carouselFactory, _socket.Object, _deviceResponse.Object); TransactionData data = CreateTransactionQueueData(); Device device = data.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel")); device.Attribute.DeviceClass = ControllerType.WhiteTB1470H.ToString().ToUpper(); await objCarouselManager.CreateCarousel(data); Slot slot = await utility.BuildStorageSpaceItem(device.StorageSpaces); //Act IDeviceResponse actual = await objCarouselManager.MoveCarousel(data, slot); //Assert Assert.Equal(expected.HasError, actual.HasError); }
public async Task Move_SlotInfoAndComputerInfo_CarouselShouldMove(bool isOutsideComputer) { IUtility utility = new Utility(); _carousel = new CarWhiteIpcDualAccess(controlType: ControllerType.WhiteIPCDualAccess, ipAddr: _carouselData.Attribute.IPAddress, carAddr: _carouselData.Attribute.DeviceNumber, port: _carouselData.Attribute.Port, timeOut: 10, returnsStatus: true, deviceResponse: _deviceResponse, socket: _socket); _carousel.Connect(); //Assume IDeviceResponse expected = new DeviceResponse() { HasError = false, Message = "Data is written on device successfully.", CurrentCarrier = 0 }; //Act IDeviceResponse actual = await _carousel.Move(slot : await utility.BuildStorageSpaceItem(_carouselData.StorageSpaces), isOutsideComputer : isOutsideComputer); _carousel.Disconnect(); //Assert Assert.Equal(expected: expected.HasError, actual: actual.HasError); Assert.Equal(expected: expected.Message, actual: actual.Message); Assert.Equal(expected: expected.CurrentCarrier, actual: actual.CurrentCarrier); }
/// <summary> /// Default Constructor /// </summary> /// <param name="config"></param> /// <param name="logger"></param> /// <param name="carouselFactory"></param> /// <param name="socket"></param> /// <param name="deviceResponse"></param> public CarouselManager(IConfiguration config, ILogger <CarouselManager> logger, ICarouselFactory carouselFactory, IIPSocket socket, IDeviceResponse deviceResponse) { _carouselFactory = carouselFactory; _logger = logger; _socket = socket; _deviceResponse = deviceResponse; _configuration = config; }
/// <summary> /// Constructor to initialize logger, deviceResponse and carouselManager /// </summary> /// <param name="logger"></param> /// <param name="deviceResponse"></param> /// <param name="carouselManager"></param> /// <param name="utility"></param> public CarouselProcess(ILogger <CarouselProcess> logger, IDeviceResponse deviceResponse, ICarouselManager carouselManager, IUtility utility) { _logger = logger; _deviceResponse = deviceResponse; _carouselManager = carouselManager; _utility = utility; }
/// <summary> /// /// </summary> /// <returns></returns> public override IDeviceResponse GetCurrentLocation() { ResetLog(); IDeviceResponse status = GetStatus(); status.CurrentCarrier = TargetShelf; return(status); }
/// <summary> /// Carousel move implementation /// </summary> /// <param name="transactionData"></param> public async Task <IDeviceResponse> MoveCarousel(TransactionData transactionData) { _deviceResponse.HasError = false; _deviceResponse.Message = string.Empty; _deviceResponse.CurrentCarrier = 0; try { // Slot Data Slot slot = await _utility.BuildStorageSpaceItem(transactionData.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel"))?.StorageSpaces); _logger.LogInformation(Constants.CarousalProcess.SlotObjectCreated); // Carousel creation _deviceResponse = await _carouselManager.CreateCarousel(transactionData); if (!_deviceResponse.HasError) { _logger.LogInformation(Constants.CarousalProcess.CarouselCreated); } else { _logger.LogInformation(_deviceResponse.Message); return(_deviceResponse); } // Moving carousel _deviceResponse = await _carouselManager.MoveCarousel(transactionData : transactionData, slot : slot); if (!_deviceResponse.HasError) { _logger.LogInformation(Constants.CarousalProcess.CarouselMoved); } else { _logger.LogInformation(_deviceResponse.Message); return(_deviceResponse); } } catch (System.Net.Sockets.SocketException ex) { _logger.LogError(ex, ex.Message); //Initializing the response object _deviceResponse.HasError = true; _deviceResponse.ErrorCode = ex.ErrorCode; _deviceResponse.Message = ex.Message; } return(_deviceResponse); }
/// <summary> /// Carousel factory method instantiate carousel as per ControllerType /// </summary> /// <param name="carouselData"></param> /// <param name="deviceResponse"></param> /// <param name="socket"></param> /// <param name="timeOut"></param> /// <returns></returns> public async Task <ICarousel> GetCarouselType(Device carouselData, IDeviceResponse deviceResponse, IIPSocket socket, string timeOut) { //Required inputs ControllerType controllerType = ControllerType.Undefined; string deviceClass = carouselData?.Attribute?.DeviceClass?.ToUpper(); string ipAddress = carouselData?.Attribute?.IPAddress; string deviceNumber = carouselData?.Attribute?.DeviceNumber; bool? returnStatus = carouselData?.Attribute?.ReturnStatus; int? ipPort = carouselData?.Attribute?.Port; int carouselTimeOut = default(int); Int32.TryParse(timeOut, out carouselTimeOut); //Setting the controller type if (deviceClass == ControllerType.WhiteTB1470_2300.ToString().ToUpper()) { controllerType = ControllerType.WhiteTB1470_2300; } else if (deviceClass == ControllerType.WhiteTB1470.ToString().ToUpper()) { controllerType = ControllerType.WhiteTB1470; } else if (deviceClass == ControllerType.WhiteTB1470H.ToString().ToUpper()) { controllerType = ControllerType.WhiteTB1470H; } else if (deviceClass == ControllerType.WhiteIPCDualAccess.ToString().ToUpper()) { controllerType = ControllerType.WhiteIPCDualAccess; } //Creating the instance switch (controllerType) { case ControllerType.WhiteTB1470_2300: return(new CarWhiteTb14702300(controllerType, deviceNumber, ipAddress, ipPort.Value, carouselTimeOut, returnStatus.Value, deviceResponse, socket)); case ControllerType.WhiteTB1470: return(new CarWhiteTB1470(controllerType, deviceNumber, ipAddress, ipPort.Value, carouselTimeOut, returnStatus.Value, deviceResponse, socket)); case ControllerType.WhiteTB1470H: return(new CarWhiteTB1470H(controllerType, deviceNumber, ipAddress, ipPort.Value, carouselTimeOut, returnStatus.Value, deviceResponse, socket)); case ControllerType.WhiteIPCDualAccess: return(new CarWhiteIpcDualAccess(controllerType, deviceNumber, ipAddress, ipPort.Value, carouselTimeOut, returnStatus.Value, deviceResponse, socket)); default: return(null); } }
public async Task MoveCarousel_ErrorFound_At_CreateCarousel_DeviceResponse() { IDeviceResponse deviceResponseAtCreateCarousel = new DeviceResponse() { HasError = true, Message = "Error Found at CreateCarousel." }; IDeviceResponse deviceResponseMoveCarousel = new DeviceResponse(); var transactionData = CreateTransactionQueueData(); _carouselManager.Setup(x => x.CreateCarousel(transactionData)).Returns(Task.FromResult(deviceResponseAtCreateCarousel)); _carouselManager.Setup(x => x.MoveCarousel(transactionData, new Slot())).Returns(Task.FromResult(deviceResponseMoveCarousel)); CarouselProcess carouselProcess = new CarouselProcess(_logger.Object, _deviceResponse.Object, _carouselManager.Object, _utility.Object); IDeviceResponse deviceResponse = await carouselProcess.MoveCarousel(transactionData); Assert.Equal(deviceResponseAtCreateCarousel.HasError, deviceResponse.HasError); Assert.Equal(deviceResponseAtCreateCarousel.Message, deviceResponse.Message); }
public async Task CreateCarousel_TransactionQueue_shouldCreateCarWhiteTB1470Carousel_Positive() { //Arrange TransactionData objTransactionData = CreateTransactionQueueData(); Device _carouselData = objTransactionData.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel")); _carousel = new CarWhiteTB1470H(controlType: ControllerType.WhiteTB1470, ipAddr: _carouselData.Attribute.IPAddress, carAddr: _carouselData.Attribute.DeviceNumber, port: _carouselData.Attribute.Port, TimeOut: 10, returnsStatus: true, deviceResponse: _deviceResponse.Object, socket: _socket.Object); _carouselFactory.Setup(x => x.GetCarouselType(_carouselData, It.IsAny <IDeviceResponse>(), It.IsAny <IIPSocket>(), It.IsAny <string>())).Returns(Task.FromResult(_carousel)); CarouselManager objCarouselManager = new CarouselManager(_configuration, _logger.Object, _carouselFactory.Object, _socket.Object, _deviceResponse.Object); //Act IDeviceResponse deviceResponse = await objCarouselManager.CreateCarousel(objTransactionData); //Assert Assert.False(deviceResponse.HasError); }
public async Task CreateCarousel_TransactionQueue_shouldCreateWhiteIPCDualAccessCarousel_Negative() { //Arrange TransactionData objTransactionData = CreateTransactionQueueData(); Device _carouselData = objTransactionData.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel")); _carousel = null; IDeviceResponse divDeviceResponse = new DeviceResponse(); _carouselFactory.Setup(x => x.GetCarouselType(_carouselData, It.IsAny <IDeviceResponse>(), It.IsAny <IIPSocket>(), It.IsAny <string>())).Returns(Task.FromResult(_carousel)); CarouselManager objCarouselManager = new CarouselManager(_configuration, _logger.Object, _carouselFactory.Object, _socket.Object, divDeviceResponse); //Act IDeviceResponse deviceResponse = await objCarouselManager.CreateCarousel(objTransactionData); //Assert Assert.True(deviceResponse.HasError); }
public async Task MoveCarousel_ErrorFound_At_MoveCarousel_DeviceResponse() { IDeviceResponse deviceResponseAtMoveCarousel = new DeviceResponse() { HasError = true, Message = "Erro Found at MoveCarousel." }; IDeviceResponse deviceResponseMoveCarousel = new DeviceResponse(); var transactionData = CreateTransactionQueueData(); Device device = transactionData.Devices.FirstOrDefault(dev => dev.Type.Equals("Carousel")); Slot slot = new Slot(); _utility.Setup(x => x.BuildStorageSpaceItem(device.StorageSpaces)).Returns(Task.FromResult(slot)); _carouselManager.Setup(x => x.CreateCarousel(transactionData)).Returns(Task.FromResult(deviceResponseMoveCarousel)); _carouselManager.Setup(x => x.MoveCarousel(transactionData, slot)).Returns(Task.FromResult(deviceResponseAtMoveCarousel)); CarouselProcess carouselProcess = new CarouselProcess(_logger.Object, _deviceResponse.Object, _carouselManager.Object, _utility.Object); IDeviceResponse deviceResponse = await carouselProcess.MoveCarousel(transactionData); Assert.Equal(deviceResponseAtMoveCarousel.HasError, deviceResponse.HasError); Assert.Equal(deviceResponseAtMoveCarousel.Message, deviceResponse.Message); }
/// <summary> /// Carousel Constructor /// </summary> /// <param name="controlType"></param> /// <param name="carAddr"></param> /// <param name="ipAddr"></param> /// <param name="port"></param> /// <param name="TimeOut"></param> /// <param name="returnsStatus"></param> /// <param name="deviceResponse"></param> /// <param name="socket"></param> protected Carousel(ControllerType controlType, string carAddr, string ipAddr, int port, int TimeOut, bool returnsStatus, IDeviceResponse deviceResponse, IIPSocket socket) { // SET DEFAULT VALUES CarAddress = carAddr; Type = controlType; IpAddress = ipAddr; IpPort = port; Timeout = TimeOut; ReturnsStatus = returnsStatus; Telegram = new StringBuilder(); LastErrorText = ""; ResetLog(); _deviceResponse = deviceResponse; IPSocket = socket; IgnoreDisplayCommands = false; IgnoreMoveCommand = false; SetCharacterAttributes(); }
public async Task Move_ShelfInfo_CarouselShouldMove() { _carousel = new CarWhiteIpcDualAccess(controlType: ControllerType.WhiteIPCDualAccess, ipAddr: _carouselData.Attribute.IPAddress, carAddr: _carouselData.Attribute.DeviceNumber, port: _carouselData.Attribute.Port, timeOut: 10, returnsStatus: true, deviceResponse: _deviceResponse, socket: _socket); _carousel.Connect(); //Assume IDeviceResponse expected = new DeviceResponse() { HasError = false, Message = "Data is written on device successfully.", CurrentCarrier = 0 }; //Act IDeviceResponse actual = await _carousel.Move(shelfNum : _carouselData.StorageSpaces.FirstOrDefault(space => space.ItemType.Equals("2")).Number); _carousel.Disconnect(); //Assert Assert.Equal(expected: expected.HasError, actual: actual.HasError); Assert.Equal(expected: expected.Message, actual: actual.Message); Assert.Equal(expected: expected.CurrentCarrier, actual: actual.CurrentCarrier); }
public CarWhiteTB1470H(ControllerType controlType, string carAddr, string ipAddr, int port, int TimeOut, bool returnsStatus, IDeviceResponse deviceResponse, Logistics.Services.DeviceCommunication.API.DeviceInterface.Interfaces.IIPSocket socket) : base(controlType, carAddr, ipAddr, port, TimeOut, returnsStatus, deviceResponse, socket) { // SET DEFAULT VALUES this.SetCharacterAttributes(); this.TargetShelf = 0; }
/// <summary> /// CarWhiteTb14702300 constructor to set default value /// </summary> /// <param name="controlType"></param> /// <param name="carAddr"></param> /// <param name="ipAddr"></param> /// <param name="port"></param> /// <param name="TimeOut"></param> /// <param name="returnsStatus"></param> /// <param name="deviceResponse"></param> /// <param name="socket"></param> public CarWhiteTb14702300(ControllerType controlType, string carAddr, string ipAddr, int port, int TimeOut, bool returnsStatus, IDeviceResponse deviceResponse, IIPSocket socket) : base(controlType, carAddr, ipAddr, port, TimeOut, returnsStatus, deviceResponse, socket) { SetCharacterAttributes(); TargetShelf = 0; }