public void when_the_input_amount_sides_is_higer_than_one_and_is_not_separated_by_comma__then_it_should_throw_exception()
        {
            InputDto inputDto = new InputDto("triangle", "perimeter", "2.5:3");

            ControllerShape controllerShape = new ControllerShape(inputDto);

            controllerShape.getCalculatedValue();
        }
        public void when_the_input_operation_name_is_not_correct_then_it_should_throw_exception()
        {
            InputDto inputDto = new InputDto("square", "ratio", "2.5");

            ControllerShape controllerShape = new ControllerShape(inputDto);

            controllerShape.getCalculatedValue();
        }
        public void when_the_input_amount_sides_is_not_correct_then_it_should_throw_exception()
        {
            InputDto inputDto = new InputDto("square", "area", "2.5,4");

            ControllerShape controllerShape = new ControllerShape(inputDto);

            controllerShape.getCalculatedValue();
        }
        public void when_the_input_is_correct_then_it_should_return_double_value()
        {
            InputDto inputDto = new InputDto("square", "area", "2.5");

            ControllerShape controllerShape = new ControllerShape(inputDto);

            double valueResponse = controllerShape.getCalculatedValue();

            Assert.IsNotNull(valueResponse);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the value of the shape:");
            string shapeName = Console.ReadLine();

            Console.WriteLine("Enter the values of the sides, " +
                              "separated by comma if it's necessary(square:1, rectangle:2, triangle:3):");
            string sideValues = Console.ReadLine();

            Console.WriteLine("Enter the operation:");
            string operation = Console.ReadLine();

            InputDto    inputDto    = new InputDto(shapeName, operation, sideValues);
            ManageInput manageInput = new ControllerShape(inputDto);

            OutputDto response = manageInput.execute();

            ManageOutput manageOutput = new PresenterResponse();

            manageOutput.execute(response);
        }
        public void when_the_input_is_not_correct_then_it_should_return_an_error_response()
        {
            OutputDto expectedOutput = new OutputDto(
                "squar",
                ApplicationConstants.Operation.AREA,
                0,
                ApplicationConstants.Status.ERROR,
                "The name of the shape is not valid");

            InputDto inputDto = new InputDto("squar", "area", "2");

            ManageInput manageInput = new ControllerShape(inputDto);

            OutputDto response = manageInput.execute();

            Assert.IsNotNull(response);
            Assert.AreEqual(expectedOutput.Shape, response.Shape);
            Assert.AreEqual(expectedOutput.Operation, response.Operation);
            Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus);
            Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse);
            Assert.AreEqual(expectedOutput.Message, response.Message);
        }
        public void when_the_input_is_correct_then_it_should_return_a_successfull_response()
        {
            OutputDto expectedOutput = new OutputDto(
                ApplicationConstants.ShapeName.SQUARE,
                ApplicationConstants.Operation.AREA,
                4,
                ApplicationConstants.Status.SUCCESS,
                "Operation ran successfully");

            InputDto inputDto = new InputDto("square", "area", "2");

            ManageInput manageInput = new ControllerShape(inputDto);

            OutputDto response = manageInput.execute();

            Assert.IsNotNull(response);
            Assert.AreEqual(expectedOutput.Shape, response.Shape);
            Assert.AreEqual(expectedOutput.Operation, response.Operation);
            Assert.AreEqual(expectedOutput.ResponseStatus, response.ResponseStatus);
            Assert.AreEqual(expectedOutput.ValueResponse, response.ValueResponse);
            Assert.AreEqual(expectedOutput.Message, response.Message);
        }
예제 #8
0
 private void _addControllerShapeToList(ControllerShape controllerShape, List<ControllerShape> list)
 {
     if (controllerShape != null)
         list.Add(controllerShape);
 }
예제 #9
0
        private void _addControllerShapeToControllerMap(ControllerShape controllerShape, Dictionary<IOutputDevice, ControllerShape> map)
        {
            if (controllerShape.Controller == null) {
                Logging.Error("null controller");
                return;
            }

            if (map.ContainsKey(controllerShape.Controller))
                Logging.Warn("Adding filter to map, but it already exists");

            map[controllerShape.Controller] = controllerShape;
        }
예제 #10
0
        private void _updateControllerShapeFromOutputSet(ControllerShape controllerShape, HashSet<int> outputs)
        {
            List<int> sortedOutputs = new List<int>(outputs);
            sortedOutputs.Sort();

            foreach (int outputIndex in sortedOutputs) {
                OutputShape oldShape = controllerShape.ChildFilterShapes.Cast<OutputShape>()
                    .Where(x => x.Controller == controllerShape.Controller && x.OutputIndex == outputIndex).FirstOrDefault();

                if (oldShape != null) {
                    _addOutputShapeToList(oldShape, _outputShapes);
                } else {
                    _CreateOutputShape(controllerShape, outputIndex);
                }
            }

            foreach (OutputShape outputShape in controllerShape.ChildFilterShapes.Cast<OutputShape>().Where(x => !outputs.Contains(x.OutputIndex)).ToArray()) {
                controllerShape.ChildFilterShapes.Remove(outputShape);
                _RemoveShapeFromDiagram(outputShape, false);
            }

            // sort the nested shapes of the outputs in the controller shape; the list above has them in order, but the list of shapes might not
            controllerShape.ChildFilterShapes.Sort(delegate (FilterSetupShapeBase a, FilterSetupShapeBase b)
                                                   	{
                                                   		OutputShape osa = a as OutputShape;
                                                   		OutputShape osb = b as OutputShape;
                                                        if (a == null || b == null)
                                                            return 0;
                                                   		return osa.OutputIndex.CompareTo(osb.OutputIndex);
                                                   	});
        }
예제 #11
0
        private OutputShape _CreateOutputShape(ControllerShape controllerShape, int outputIndex)
        {
            OutputShape outputShape = _MakeOutputShape(controllerShape.Controller, outputIndex);
            _addOutputShapeToList(outputShape, _outputShapes);

            controllerShape.ChildFilterShapes.Add(outputShape);

            return outputShape;
        }