public void Move() { var matchRegExResponse = _findObjectsRegExService.MatchRegex(_model.FileContent); if (!matchRegExResponse.HasMatched) { return; } var regex = new Regex(@"(.*,\d,)(-?\d*(?:\.\d*)?)_(-?\d*(?:\.\d*)?)_(-?\d*(?:\.\d*)?)(,.*)", RegexOptions.Multiline); var objects = matchRegExResponse.Content.Split("%"); for (var i = 0; i < objects.Length; i++) { if (objects[i].Contains("co_wire", System.StringComparison.OrdinalIgnoreCase)) { objects[i] = _moveCoWireObjectService.For(objects[i]); } else { var match = regex.Match(objects[i]); var leadingValue = match.Groups[1].Value; var x = _parseAndAddFloatValue.For(match.Groups[2].Value, _model.MoveXAxisValue); var y = _parseAndAddFloatValue.For(match.Groups[3].Value, _model.MoveYAxisValue); var z = _parseAndAddFloatValue.For(match.Groups[4].Value, _model.MoveZAxisValue); var trailingValue = match.Groups[5].Value; objects[i] = objects[i].Replace(match.Value, $"{leadingValue}{x}_{y}_{z}{trailingValue}"); } } var result = string.Join("%", objects); _model.FileContent = _findObjectsRegExService.Replace(_model.FileContent, matchRegExResponse.Prefix + result + matchRegExResponse.Suffix, matchRegExResponse.MatchingRegEx); }
public void Move() { var matchRegExResponse = _regExService.MatchRegex(_mainModel.FileContent); if (!matchRegExResponse.HasMatched) { return; } var regex = new Regex(@"^(.*,\d,)(-?\d*(?:\.\d*)?)_(-?\d(?:\.\d*)?)_(-?\d*(?:\.\d*)?)(,.*)", RegexOptions.Multiline); var someObjects = matchRegExResponse.Content.Split("%"); for (var i = 0; i < someObjects.Length; i++) { var match = regex.Match(someObjects[i]); var leadingValue = match.Groups[1].Value; var x = _parseAndAddFloatValue.For(match.Groups[2].Value, _mainModel.MoveXAxisValue); var y = _parseAndAddFloatValue.For(match.Groups[3].Value, _mainModel.MoveYAxisValue); var z = _parseAndAddFloatValue.For(match.Groups[4].Value, _mainModel.MoveZAxisValue); var trailingValue = match.Groups[5].Value; someObjects[i] = someObjects[i].Replace(match.Value, $"{leadingValue}{x}_{y}_{z}{trailingValue}"); //someObjects[i] = $"{leadingValue}{x}_{y}_{z}{trailingValue}"; } var result = string.Join("%", someObjects); _mainModel.FileContent = _regExService.Replace(_mainModel.FileContent, matchRegExResponse.Prefix + result + matchRegExResponse.Suffix, matchRegExResponse.MatchingRegEx); }
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); }
public void Move() { var matchRegExResponse = _findTracksRegExService.MatchRegex(_mainModel.FileContent); if (!matchRegExResponse.HasMatched) { return; } var tracks = matchRegExResponse.Content.Split("%"); var regex = new Regex(@"(?:ct_dynamic(?:_flexy)?,\d),((-?\d*(?:\.\d*)?)_(-?\d(?:\.\d*)?)_(-?\d*(?:\.\d*)?))"); for (var i = 0; i < tracks.Length; i++) { var match = regex.Match(tracks[i]); if (!match.Success) { continue; } var x = _parseAndAddFloatValue.For(match.Groups[2].Value, _mainModel.MoveXAxisValue); var y = _parseAndAddFloatValue.For(match.Groups[3].Value, _mainModel.MoveYAxisValue); var z = _parseAndAddFloatValue.For(match.Groups[4].Value, _mainModel.MoveZAxisValue); tracks[i] = tracks[i].Replace(match.Groups[1].Value, $"{x}_{y}_{z}"); } var result = string.Join("%", tracks); _mainModel.FileContent = _findTracksRegExService.Replace(_mainModel.FileContent, matchRegExResponse.Prefix + result + matchRegExResponse.Suffix, matchRegExResponse.MatchingRegEx); }
public void For_PatternDoesMatch_ReturnsInputStringWithNewCoordinates( [Frozen] IMainModel model, [Frozen] IParseAndAddFloatValue parseAndAddFloatValue, MoveCoWireObjectService sut) { //Arrange model.MoveXAxisValue.Returns(1); model.MoveYAxisValue.Returns(2); model.MoveZAxisValue.Returns(3); var input = "14,co_wire,1,12.68545_2.453807_61.43925,3.329947_138.1346_1.069022E-07,-1,0.5,0,0,0,-1,12.68545_2.453807_61.43925&13.11526_2.416335_60.95963&0.5&2,-1,kcc0:h0:s0:v26:lr50:hr20,0,,%14,"; var expectedResult = "14,co_wire,1,X_Y_Z,3.329947_138.1346_1.069022E-07,-1,0.5,0,0,0,-1,X_Y_Z&A_B_C&0.5&2,-1,kcc0:h0:s0:v26:lr50:hr20,0,,%14,"; parseAndAddFloatValue.For("12.68545", 1).Returns("X"); parseAndAddFloatValue.For("2.453807", 2).Returns("Y"); parseAndAddFloatValue.For("61.43925", 3).Returns("Z"); parseAndAddFloatValue.For("13.11526", 1).Returns("A"); parseAndAddFloatValue.For("2.416335", 2).Returns("B"); parseAndAddFloatValue.For("60.95963", 3).Returns("C"); //Act var result = sut.For(input); //Assert result.Should().Be(expectedResult); }
public string For(string input) { var match = _regexDesTodesOfDoom.Match(input); if (!match.Success) { return(input); } var firstX = _parseAndAddFloatValue.For(match.Groups[3].Value, _model.MoveXAxisValue); var firstY = _parseAndAddFloatValue.For(match.Groups[4].Value, _model.MoveYAxisValue); var firstZ = _parseAndAddFloatValue.For(match.Groups[5].Value, _model.MoveZAxisValue); var firstCoordinates = $"{firstX}_{firstY}_{firstZ}"; input = input.Replace(match.Groups[2].Value, firstCoordinates); var secondX = _parseAndAddFloatValue.For(match.Groups[8].Value, _model.MoveXAxisValue); var secondY = _parseAndAddFloatValue.For(match.Groups[9].Value, _model.MoveYAxisValue); var secondZ = _parseAndAddFloatValue.For(match.Groups[10].Value, _model.MoveZAxisValue); var secondCoordinates = $"{secondX}_{secondY}_{secondZ}"; input = input.Replace(match.Groups[7].Value, secondCoordinates); return(input); }
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); }
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); }