public void Move_RegExMatchDoesNotContainPercentChar_ReplacesOneLine(
            [Frozen] IMainModel model,
            [Frozen] IFindWaggonsRegExService findWaggonsRegExService,
            [Frozen] IParseAndAddFloatValue parseAndAddFloatValue,
            MoveWaggonsService sut,
            string dummyContent,
            RegexServiceResponseModel regexServiceResponseModel,
            string dummyRegex)
        {
            //Arrange
            var source         = "ct_dynamic,1,16.73281_1.918186_60.32922,0_125.4218_0,43,36,42,0,0,0,0,0,0,0,0,0,0,0,-1,0,,1_0_-2_45_2.9_0_6_22_1_1_12,-1,0,4_0,kcc0:h0:s0:v49:lr50:hr20,,1,";
            var expectedResult = "ct_dynamic,1,X_Y_Z,0_125.4218_0,43,36,42,0,0,0,0,0,0,0,0,0,0,0,-1,0,,1_0_-2_45_2.9_0_6_22_1_1_12,-1,0,4_0,kcc0:h0:s0:v49:lr50:hr20,,1,";

            model.FileContent.Returns(dummyContent);
            regexServiceResponseModel.HasMatched    = true;
            regexServiceResponseModel.Content       = source;
            regexServiceResponseModel.MatchingRegEx = dummyRegex;
            findWaggonsRegExService.MatchRegex(dummyContent).Returns(regexServiceResponseModel);

            parseAndAddFloatValue.For("16.73281", Arg.Any <float>()).Returns("X");
            parseAndAddFloatValue.For("1.918186", Arg.Any <float>()).Returns("Y");
            parseAndAddFloatValue.For("60.32922", Arg.Any <float>()).Returns("Z");

            //Act
            sut.Move();

            //Assert
            model.ReceivedCalls().Should().HaveCount(6);
            findWaggonsRegExService.ReceivedCalls().Should().HaveCount(2);
            findWaggonsRegExService.Received(1).MatchRegex(dummyContent);
            findWaggonsRegExService.Received(1).Replace(dummyContent, expectedResult, regexServiceResponseModel.MatchingRegEx);
        }
Ejemplo n.º 2
0
        public IRegexServiceResponseModel MatchRegex(string content)
        {
            var result = new RegexServiceResponseModel();

            var match = Regex.Match(content, MagicRegex());

            if (match.Success)
            {
                result.Prefix        = match.Groups[1].Value;
                result.Content       = match.Groups[2].Value;
                result.Suffix        = match.Groups[3].Value;
                result.HasMatched    = true;
                result.MatchingRegEx = MagicRegex();
            }
            else
            {
                match = Regex.Match(content, AlternateMagicRegex());
                if (match.Success)
                {
                    result.Prefix        = match.Groups[0].Value;
                    result.HasMatched    = true;
                    result.MatchingRegEx = AlternateMagicRegex();
                }
            }

            return(result);
        }
        public void Move_RegExMatchesMultipleObjects_ReplacesCoordinates(
            [Frozen] IMainModel model,
            [Frozen] IFindObjectsRegExService findObjectsRegExService,
            [Frozen] IMoveCoWireObjectService moveCoWireObjectService,
            [Frozen] IParseAndAddFloatValue parseAndAddFloatValue,
            MoveObjectsService sut,
            string dummyContent,
            RegexServiceResponseModel regexServiceResponseModel,
            string dummyRegex)
        {
            //Arrange
            var source         = Resources.Services_Move_MultipleObjects_Source;
            var expectedResult = Resources.Services_Move_MultipleObjects_ExpectedResult;

            model.FileContent.Returns(dummyContent);
            regexServiceResponseModel.HasMatched    = true;
            regexServiceResponseModel.Content       = source;
            regexServiceResponseModel.MatchingRegEx = dummyRegex;
            findObjectsRegExService.MatchRegex(dummyContent).Returns(regexServiceResponseModel);
            moveCoWireObjectService.For(Arg.Any <string>()).Returns("co_wire");


            var coordinateCounter = 0;

            parseAndAddFloatValue.For(Arg.Any <string>(), Arg.Any <float>()).Returns((ci) =>
            {
                switch (coordinateCounter)
                {
                case 0:
                    coordinateCounter++;
                    return("X");

                case 1:
                    coordinateCounter++;
                    return("Y");

                default:
                    coordinateCounter = 0;
                    return("Z");
                }
                ;
            });

            //Act
            sut.Move();

            //Assert
            findObjectsRegExService.ReceivedCalls().Should().HaveCount(2);
            findObjectsRegExService.Received(1).MatchRegex(dummyContent);
            findObjectsRegExService.Received(1).Replace(dummyContent, expectedResult, regexServiceResponseModel.MatchingRegEx);
        }
        public void Move_RegExMatchDoesNotContainPercentChar_ReplacesOneLine(
            [Frozen] IMainModel model,
            [Frozen] IFindObjectsRegExService findObjectsRegExService,
            [Frozen] IParseAndAddFloatValue parseAndAddFloatValue,
            MoveObjectsService sut,
            string dummyContent,
            RegexServiceResponseModel regexServiceResponseModel,
            string dummyRegex,
            float dummyX,
            float dummyY,
            float dummyZ)
        {
            //Arrange
            var source         = "table_square_0,1,16.48622_-0.2120953_61.54293,-1.347026E-05_270_-1.018759E-06,-1,1,0,0,0,-1,,-1,kcc0:h0:s0:v49:lr50:hr20,0,,";
            var expectedResult = "table_square_0,1,X_Y_Z,-1.347026E-05_270_-1.018759E-06,-1,1,0,0,0,-1,,-1,kcc0:h0:s0:v49:lr50:hr20,0,,";

            model.FileContent.Returns(dummyContent);
            model.MoveXAxisValue.Returns(dummyX);
            model.MoveYAxisValue.Returns(dummyY);
            model.MoveZAxisValue.Returns(dummyZ);

            regexServiceResponseModel.HasMatched    = true;
            regexServiceResponseModel.Content       = source;
            regexServiceResponseModel.MatchingRegEx = dummyRegex;
            findObjectsRegExService.MatchRegex(dummyContent).Returns(regexServiceResponseModel);

            parseAndAddFloatValue.For("16.48622", dummyX).Returns("X");
            parseAndAddFloatValue.For("-0.2120953", dummyY).Returns("Y");
            parseAndAddFloatValue.For("61.54293", dummyZ).Returns("Z");

            //Act
            sut.Move();

            //Assert
            model.ReceivedCalls().Should().HaveCount(6);
            findObjectsRegExService.ReceivedCalls().Should().HaveCount(2);
            findObjectsRegExService.Received(1).MatchRegex(dummyContent);
            findObjectsRegExService.Received(1).Replace(dummyContent, expectedResult, regexServiceResponseModel.MatchingRegEx);
        }