public void GenerateMessagesByNamespace_ShouldCallAddNewDirectoryToProjectAndGenerateMessagesMethods() { //arrange string testType = "testType"; string testNamespace = "testNamespace"; string standardNamespace = "testStandardNamespace"; Mock <IMsgFile> messageFileMock = new Mock <IMsgFile>(); messageFileMock.SetupGet(msgFile => msgFile.Type).Returns(new RosType(testNamespace, testType)); Mock <ProjectItem> groupDirectoryProjectItemMock = new Mock <ProjectItem>(); IGrouping <string, IMsgFile> msgGroup = new IMsgFile[] { messageFileMock.Object }.GroupBy(msg => msg.Type.Namespace).First(); _testClassPartialMock.CallBase = true; _solutionManagerMock.Setup(solutionManager => solutionManager.AddNewDirectoryToProject(msgGroup.Key)) .Returns(groupDirectoryProjectItemMock.Object); _testClassPartialMock.Setup(testClass => testClass.GenerateMessages(groupDirectoryProjectItemMock.Object, msgGroup, standardNamespace)).Callback(() => { }); //act ProjectItem result = _testClassPartialMock.Object.GenerateMessagesByNamespace(msgGroup, standardNamespace); //assert result.Should().NotBeNull(); result.Should().BeSameAs(groupDirectoryProjectItemMock.Object); _testClassPartialMock.Verify(testClass => testClass.GenerateMessages(groupDirectoryProjectItemMock.Object, msgGroup, standardNamespace)); }
public void GenerateStandardNamespaceMessages_ShouldCallGenerateMessagesByNamespaceAndGenerateCustomTimePrimitiveTypeMethod() { //arrange string testType = "testType"; string standardNamespace = "testStandardNamespace"; Mock <IMsgFile> msgFileMock = new Mock <IMsgFile>(); IEnumerable <IGrouping <string, IMsgFile> > groupList = new IMsgFile[] { msgFileMock.Object }.GroupBy(msgFile => msgFile.Type.Namespace); Mock <ProjectItem> standardNamespaceDirectoryProjectItemMock = new Mock <ProjectItem>(); _testClassPartialMock.CallBase = true; msgFileMock.Setup(msgFile => msgFile.Type).Returns(new RosType(standardNamespace, testType)); _testClassPartialMock .Setup(testClass => testClass.GenerateMessagesByNamespace(It.IsAny <IGrouping <string, IMsgFile> >(), It.IsAny <string>())) .Returns(standardNamespaceDirectoryProjectItemMock.Object); _testClassPartialMock.Setup(testClass => testClass.GenerateCustomTimePrimitiveType(standardNamespaceDirectoryProjectItemMock.Object, standardNamespace)); //act _testClassPartialMock.Object.GenerateStandardNamespaceMessages(groupList, standardNamespace); //assert _testClassPartialMock.Verify(testClass => testClass.GenerateMessagesByNamespace(It.Is <IGrouping <string, IMsgFile> >(group => group.Key == standardNamespace), standardNamespace), Times.Once); _testClassPartialMock.Verify(testClass => testClass.GenerateCustomTimePrimitiveType(standardNamespaceDirectoryProjectItemMock.Object, standardNamespace), Times.Once); }
public void GenerateStandardNamespaceMessages_NoStandardNamespaceGroup_ShouldThrowNoStandardNamespaceException() { //arrange string testType = "testType"; string standardNamespace = "testStandardNamespace"; string nonStandardNamepsace = "testNonStandardNamespace"; Mock <IMsgFile> msgFileMock = new Mock <IMsgFile>(); IEnumerable <IGrouping <string, IMsgFile> > groupList = new IMsgFile[] { msgFileMock.Object }.GroupBy(msgFile => msgFile.Type.Namespace); _testClassPartialMock.CallBase = true; msgFileMock.Setup(msgFile => msgFile.Type).Returns(new RosType(nonStandardNamepsace, testType)); //act Action act = () => _testClassPartialMock.Object.GenerateStandardNamespaceMessages(groupList, standardNamespace); //assert act.Should().ThrowExactly <NoStandardNamespaceException>(); }
public void GenerateMessages_ShouldCallTransformTemplateToFileMethod() { //arrange string messageType = "testType"; string standardNamespace = "testStandardNamespace"; string messageNamespace = "testNamespace"; Mock <ProjectItem> directoryProjectItemMock = new Mock <ProjectItem>(); Mock <IMsgFile> messageFileMock = new Mock <IMsgFile>(); IEnumerable <IMsgFile> messageFileCollection = new IMsgFile[] { messageFileMock.Object }; Mock <ITextTemplatingSession> templatingSessionMock = new Mock <ITextTemplatingSession>(); RosType testDependencyType = new RosType("testDepdendencyNamespace", "testDependencyType"); ISet <RosType> dependencySet = new HashSet <RosType>(); dependencySet.Add(testDependencyType); ISet <MessageField> arrayFieldSet = new HashSet <MessageField>(); ISet <MessageField> constantFieldSet = new HashSet <MessageField>(); ISet <MessageField> fieldSet = new HashSet <MessageField>(); messageFileMock.SetupGet(messageFile => messageFile.ArrayFieldSet).Returns(arrayFieldSet); messageFileMock.SetupGet(messageFile => messageFile.ConstantFieldSet).Returns(constantFieldSet); messageFileMock.SetupGet(messageFile => messageFile.FieldSet).Returns(fieldSet); _testClassPartialMock.CallBase = true; messageFileMock.SetupGet(messageFile => messageFile.Type).Returns(new RosType(messageNamespace, messageType)); messageFileMock.SetupGet(messageFile => messageFile.DependencySet).Returns(dependencySet); _textTemplatingSessionHostMock.Setup(textTemplatingSessionHost => textTemplatingSessionHost.CreateSession()) .Returns(templatingSessionMock.Object); _textTemplatingSessionHostMock.Setup(textTemplatingSessionHost => textTemplatingSessionHost.CreateSession()) .Returns(templatingSessionMock.Object); _testClassPartialMock.Setup(testClass => testClass.TransformTemplateToFile(templatingSessionMock.Object, directoryProjectItemMock.Object, ROS_MESSAGE_CODE_GENERATION_TEMPLATE_PATH, ROS_MESSAGE_CODE_GENERATION_TEMPLATE_CONTENT, It.IsAny <string>())).Callback(() => { }); //act _testClassPartialMock.Object.GenerateMessages(directoryProjectItemMock.Object, messageFileCollection, standardNamespace); //assert _textTemplatingSessionHostMock.Verify(sessionHost => sessionHost.CreateSession(), Times.Once); _testClassPartialMock.Verify(testClass => testClass.TransformTemplateToFile(templatingSessionMock.Object, directoryProjectItemMock.Object, ROS_MESSAGE_CODE_GENERATION_TEMPLATE_PATH, ROS_MESSAGE_CODE_GENERATION_TEMPLATE_CONTENT, It.IsAny <string>()), Times.Once); }
protected override void ProcessFields() { string[] splittedFileContent = this.FileContent.Split(new string[] { INPUT_OUTPUT_SEPARATOR }, StringSplitOptions.None); string requestString = splittedFileContent.FirstOrDefault(); string responseString = splittedFileContent.LastOrDefault(); if (requestString != null) { string tempClassName = $"{this.Type.Type}{TYPE_SEPARATOR}{RESPONSE_NAME}"; Request = new MsgFile(_yamlParser, requestString, tempClassName, this.Type.Namespace); } if (responseString != null) { string tempClassName = $"{this.Type.Type}{TYPE_SEPARATOR}{REQUEST_NAME}"; Response = new MsgFile(_yamlParser, responseString, tempClassName, this.Type.Namespace); } }
public void SetMsgFileFieldsFromYAMLString(string yamlString, IMsgFile msgFile) { if (null == yamlString) { throw new ArgumentNullException(nameof(yamlString)); } if (null == msgFile) { throw new ArgumentNullException(nameof(msgFile)); } foreach (Match currentMatch in RegexMatch(yamlString)) { if (currentMatch.Success) { string namespaceName = currentMatch.Groups[NamespaceRegexGroupName].Value; string type = currentMatch.Groups[TypeRegexGroupName].Value; bool isArray = currentMatch.Groups[IsArrayRegexGroupName].Success; int elementCount = 0; int.TryParse(currentMatch.Groups[ElementCountRegexGroupName].Value, out elementCount); string name = currentMatch.Groups[VariableNameRegexGroupName].Value; string memberValue = currentMatch.Groups[ConstantValueRegexGroupName].Value; MessageField newField = new MessageField(name, _primitiveTypeDictionary.ContainsKey(type) ? _primitiveTypeDictionary[type] : type, namespaceName, isArray, elementCount, memberValue); if (isArray) { msgFile.ArrayFieldSet.Add(newField); } else if (!string.IsNullOrWhiteSpace(memberValue)) { msgFile.ConstantFieldSet.Add(newField); } else { msgFile.FieldSet.Add(newField); } } } }