public void CommentOutCode_GivenSourceCodeWithNoReasonForCommentingAndNoExceptionMessageWithHash_CommentsCode() { //Arrange string originalSourceCode = CreateSourceCode(); string commentedSourceCode = CreateCommentedSourceCodeWithHash(); //Act string result = SourceCodeHelpers.CommentOutCode(originalSourceCode, commentSymbol: "#"); //Assert result .Should() .Be(commentedSourceCode); }
public void CommentOutCode_GivenSourceCodeWithReasonForCommentingAndNoExceptionMessage_CommentsCode() { //Arrange string reason = "Just for test the unit tests"; string originalSourceCode = CreateSourceCode(); string commentedSourceCode = CreateCommentedSourceCode(); //Act string result = SourceCodeHelpers.CommentOutCode(originalSourceCode, reason); //Assert result .Should() .Be($"'System Commented\r\n\r\n'{reason}\r\n\r\n\r\n{commentedSourceCode}"); }
public void CommentOutCode_GivenSourceCodeAlreadyCommented_DoesntCommentCode() { //Arrange const string systemCommented = "'System Commented\r\n\r\n"; string originalSourceCode = CreateCommentedSourceCode(); string commentedSourceCode = CreateCommentedSourceCode(); //Act string result = SourceCodeHelpers.CommentOutCode(originalSourceCode); //Assert result .Should() .Be($"{systemCommented}{commentedSourceCode}"); }
public void CommentOutCode_GivenSourceCodeWithNoReasonForCommentingAndNoExceptionMessage_CommentsCode() { //Arrange const string systemCommented = "'System Commented\r\n\r\n"; string originalSourceCode = CreateSourceCode(); string commentedSourceCode = CreateCommentedSourceCode(); //Act string result = SourceCodeHelpers.CommentOutCode(originalSourceCode); //Assert result .Should() .Be($"{systemCommented}{commentedSourceCode}"); }
public async Task ResetScenarioForFieldDefinitionChanges(IEnumerable <DatasetSpecificationRelationshipViewModel> relationships, string specificationId, IEnumerable <string> currentFieldDefinitionNames) { Guard.ArgumentNotNull(relationships, nameof(relationships)); Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId)); Guard.ArgumentNotNull(currentFieldDefinitionNames, nameof(currentFieldDefinitionNames)); IEnumerable <TestScenario> scenarios = await _scenariosRepositoryPolicy.ExecuteAsync(() => _scenariosRepository.GetTestScenariosBySpecificationId(specificationId)); if (scenarios.IsNullOrEmpty()) { _logger.Information($"No scenarios found for specification id '{specificationId}'"); return; } List <string> fieldIdentifiers = new List <string>(); foreach (DatasetSpecificationRelationshipViewModel datasetSpecificationRelationshipViewModel in relationships) { fieldIdentifiers.AddRange(currentFieldDefinitionNames.Select(m => $"dataset {datasetSpecificationRelationshipViewModel.Name} field {VisualBasicTypeGenerator.GenerateIdentifier(m)}")); } IEnumerable <TestScenario> scenariosToUpdate = scenarios.Where(m => SourceCodeHelpers.CodeContainsFullyQualifiedDatasetFieldIdentifier(m.Current.Gherkin.RemoveAllQuotes(), fieldIdentifiers)); if (scenariosToUpdate.IsNullOrEmpty()) { _logger.Information($"No test scenarios required resetting for specification id '{specificationId}'"); return; } const string reasonForCommenting = "The dataset definition referenced by this scenario/spec has been updated and subsequently the code has been commented out"; foreach (TestScenario scenario in scenariosToUpdate) { string gherkin = scenario.Current.Gherkin; string updatedGherkin = SourceCodeHelpers.CommentOutCode(gherkin, reasonForCommenting, commentSymbol: "#"); await SaveVersion(scenario, updatedGherkin); } }
public void CommentOutCode_GivenSourceCodeWithReasonForCommentingAndExceptionMessage_CommentsCode() { //Arrange const string reason = "Just for test the unit tests"; const string exceptionMessage = "Exception thrown, just for test the unit tests"; const string exceptionType = "DatasetReferenceChangeException"; string originalSourceCode = CreateSourceCode(); string commentedSourceCode = CreateCommentedSourceCode(); string expected = $"'System Commented\r\n\r\n'{reason}\r\n\r\n\r\nThrow New {exceptionType}(\"{exceptionMessage}\")\r\n\r\n\r\n{commentedSourceCode}"; //Act string result = SourceCodeHelpers.CommentOutCode(originalSourceCode, reason, exceptionMessage, exceptionType); //Assert result .Should() .Be(expected); }