Example #1
0
        public async Task GetFocusOffsetsAsync_SendValidRequest()
        {
            //Arrange
            string       commandName       = "focusoffsets";
            IRestRequest sentRequest       = null;
            var          commandSenderMock = new Mock <ICommandSender>();

            commandSenderMock
            .Setup(x => x.ExecuteRequestAsync <IntListResponse>(It.IsAny <string>(), It.IsAny <RestRequest>()))
            .Callback((string baseUrl, IRestRequest request) => sentRequest = request)
            .Returns(Task.FromResult(new IntListResponse(new List <int> {
                1
            })));
            var filterWheel = new FilterWheel(_deviceConfiguration, commandSenderMock.Object);

            //Act
            await filterWheel.GetFocusOffsetsAsync();

            //Assert
            Assert.Equal(Method.GET, sentRequest.Method);
            AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName);
        }
        private async Task CallDeviceMethodsAsync(FilterWheel filterWheel)
        {
            Logger.LogInformation("START CallDeviceMethodsAsync");

            Logger.LogInformation("Connect Filter wheel");
            var setConnectedAsyncTask = filterWheel.SetConnectedAsync(true);

            ContinueTask(setConnectedAsyncTask);

            var isConnectedAsyncTask = filterWheel.IsConnectedAsync();

            ContinueTask(isConnectedAsyncTask);

            Logger.LogInformation("Call GetNameAsync");
            var getNameAsyncTask = filterWheel.GetNameAsync();

            ContinueTask(getNameAsyncTask);

            Logger.LogInformation("Call GetDescriptionAsync");
            var getDescriptionAsyncTask = filterWheel.GetDescriptionAsync();

            ContinueTask(getDescriptionAsyncTask);

            Logger.LogInformation("Call GetDriverInfoAsync");
            var getDriverInfoAsyncTask = filterWheel.GetDriverInfoAsync();

            ContinueTask(getDriverInfoAsyncTask);

            Logger.LogInformation("Call GetDriverVersionAsync");
            var getDriverVersionAsyncTask = filterWheel.GetDriverVersionAsync();

            ContinueTask(getDriverVersionAsyncTask);

            Logger.LogInformation("Call GetNamesAsync");
            var getNamesAsyncTask = filterWheel.GetNamesAsync();

            ContinueTask(getNamesAsyncTask);

            Logger.LogInformation("Call GetFocusOffsetsAsync");
            var getFocusOffsetsAsyncTask = filterWheel.GetFocusOffsetsAsync();

            ContinueTask(getFocusOffsetsAsyncTask);

            Logger.LogInformation("Call SetPositionAsync(2)");
            var setPositionAsync2Task = filterWheel.SetPositionAsync(2);

            ContinueTask(setPositionAsync2Task);

            Logger.LogInformation("Call GetPositionAsync");
            var getPositionAsyncTask = filterWheel.GetPositionAsync();

            ContinueTask(getPositionAsyncTask);

            Logger.LogInformation("Call SetPositionAsync(1000)");
            var setPositionAsync1000Task = filterWheel.SetPositionAsync(1000);

            ContinueTask(setPositionAsync1000Task);

            await Task.WhenAll(setConnectedAsyncTask, isConnectedAsyncTask, getNameAsyncTask,
                               getDescriptionAsyncTask, getDriverInfoAsyncTask, getDriverVersionAsyncTask,
                               getNamesAsyncTask, getFocusOffsetsAsyncTask, setPositionAsync2Task, getPositionAsyncTask, setPositionAsync1000Task);

            Logger.LogInformation("END CallDeviceMethodsAsync");
        }