Пример #1
0
        private IGraphType CreateGraphType(OperationType operationType, IEnumerable <GraphOperationDescriptor> operations)
        {
            var graphType = new GraphType(operationType);

            if (operations == null)
            {
                return(graphType);
            }
            foreach (var operation in operations)
            {
                var resolver = new OperationResolver(operation, _binderProvider);
                var type     = _graphTypeProvider.GetGraphType(operation.MethodInfo.ReturnType, null, null);

                var field = new GraphField(operation.Name, type, typeof(void), resolver);
                foreach (var parameter in operation.Parameters.Values)
                {
                    if (!parameter.IsGraphArgument)
                    {
                        continue;
                    }
                    var parameterGraphType = _graphTypeProvider.GetGraphType(parameter.ParameterInfo.ParameterType, parameter.IsRequired, null);
                    field.AddArgument(new NamedGraphType(parameter.ArgumentName, parameterGraphType));
                }

                graphType.AddField(typeof(void), field);
            }
            return(graphType);
        }
Пример #2
0
        public void ResolveOperation_For_UnknownOperation_Throws_InvalidOperationException()
        {
            // Mock the dependencies
            var loggerMock          = new Mock <ILogger <OperationResolver> >();
            var serviceProviderMock = new Mock <IServiceProvider>();

            // Call and assert
            var operationResolver = new OperationResolver(serviceProviderMock.Object, loggerMock.Object);

            Assert.ThrowsException <InvalidOperationException>(() => operationResolver.ResolveOperation("blah operation"));
        }
Пример #3
0
        public void ResolveOperation_For_NullOperation_Throws_ArgumentNullException()
        {
            // Mock the dependencies
            var loggerMock          = new Mock <ILogger <OperationResolver> >();
            var serviceProviderMock = new Mock <IServiceProvider>();

            // Call and assert
            var operationResolver = new OperationResolver(serviceProviderMock.Object, loggerMock.Object);

            Assert.ThrowsException <ArgumentNullException>(() => operationResolver.ResolveOperation(null));
        }
        public double Calculate(string op, double num1, double num2)
        {
            string op1 = OperationResolver.Resolve(op);

            if (!string.IsNullOrEmpty(op1))
            {
                var command = Extensions.GetMathOperator(_resolver, op1);
                command.Operand1 = num1;
                command.Operand2 = num2;
                return(_calculator.Invoke(command));
            }
            return(num1);
        }
Пример #5
0
        public void ResolveOperation_For_ValidOperation_Returns_IOperation(string operationName, Type operationType)
        {
            // Mock the dependencies
            var loggerMock          = new Mock <ILogger <OperationResolver> >();
            var serviceProviderMock = new Mock <IServiceProvider>();

            serviceProviderMock.Setup(m => m.GetService(operationType)).Returns(Activator.CreateInstance(operationType));

            // Call
            var operationResolver = new OperationResolver(serviceProviderMock.Object, loggerMock.Object);
            var operation         = operationResolver.ResolveOperation(operationName);

            // Assert
            Assert.IsInstanceOfType(operation, operationType);      // exact instance
            Assert.IsInstanceOfType(operation, typeof(IOperation)); // interface
        }
Пример #6
0
        static void Main(string[] args)
        {
            RegisterExitHandler();

            InitializeDevices();

            Logger.LogInformation("Air Conditioner Controller Client");

            IConfigurationRoot configuration = GetConfiguration();

            OperationResolver.Initialize(typeof(Program).Assembly, new DefaultOperation(), Logger);

            Logger.LogInformation("Operations ready");

            Hub = new HubFacade(configuration, Logger);
            Hub.StartListen();

            // Wait for messages - service mode
            while (true)
            {
                Console.ReadKey();
            }
            // ReSharper disable once FunctionNeverReturns
        }