-
-
Notifications
You must be signed in to change notification settings - Fork 22
Refactor dotnet code gen #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c5840f4
Initial Commit of using erb to generate dotnet
clrudolphi b90e60e
fixup syntax errors
clrudolphi 4b9f301
fixup mistake with enums
clrudolphi 24685ba
added using statement for System.ComponentModel so that Description a…
clrudolphi ea833bf
added using statement for System.ComponentModel so that Description a…
clrudolphi 792de3e
Merge branch 'RefactorDotnetCodeGen' of https://github.com/clrudolphi…
clrudolphi 213fba6
added using statement for System.Reflection to the enum generator
clrudolphi 8b652ea
regenerated the enums with the previous fix
clrudolphi 1521062
Fixed enums by creating Extensions class for each enum
clrudolphi 7044cb3
Fixup nullable value types,
clrudolphi 3cdf56a
Setup Make, make build fail
mpkorstanje e4aa561
Moved Generated Files to the /generated folder. Added support classes…
clrudolphi 8e274b3
Modified github workflow test-dotnet.yml to invoke dotnet test during…
clrudolphi b99f54b
Revisions based upon PR comments. All resolved except for decisions o…
clrudolphi 4cf2841
Downgraded dependency on System.Text.JSON to v6.0.0 per comments in t…
clrudolphi 2e6bd7c
Revised JsonOptions initializer from a lock sequence to Lazy<T>
clrudolphi 97f4da6
Remove unused default.mk
mpkorstanje e4925a2
Remove unused update-versions script
mpkorstanje 6061002
Remove unused default.mk
mpkorstanje 579edce
Clean-ups from review comments.
clrudolphi 8b5849f
Merge branch 'RefactorDotnetCodeGen' of https://github.com/clrudolphi…
clrudolphi d605e39
Changes per review comments
clrudolphi cbfd326
Remove dependabot config
mpkorstanje 49b45ad
Merge branch 'main' into RefactorDotnetCodeGen
mpkorstanje File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
| // README at: https://github.com/devcontainers/templates/tree/main/src/ruby | ||
| { | ||
| "name": "Ruby", | ||
| // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
| "image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye", | ||
| "features": { | ||
| "ghcr.io/jungaretti/features/make:1": {}, | ||
| "ghcr.io/devcontainers/features/dotnet:2": { | ||
| "version": "8.0" | ||
| } | ||
| } | ||
| // Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
| // "forwardPorts": [], | ||
| // Use 'postCreateCommand' to run commands after the container is created. | ||
| // "postCreateCommand": "ruby --version", | ||
| // Configure tool-specific properties. | ||
| // "customizations": {}, | ||
| // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
| // "remoteUser": "root" | ||
| } |
36 changes: 36 additions & 0 deletions
36
dotnet/Cucumber.Messages.Specs/BasicMessageSerializationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using Xunit; | ||
| using System.IO; | ||
| using Io.Cucumber.Messages.Types; | ||
| using System.Text.Json; | ||
| using System.Collections.Generic; | ||
| using System.Reflection; | ||
| using System.Text.Json.Serialization; | ||
| using System; | ||
| using System.ComponentModel; | ||
| using Cucumber.Messages; | ||
|
|
||
| namespace Cucumber.Messages.Specs | ||
| { | ||
| public class BasicMessageSerializationTests | ||
| { | ||
|
|
||
| [Fact] | ||
| public void SerializesAnEnvelopeToNDJSONCorrectly() | ||
| { | ||
| var stepDefinitionNDJSON = @"{""stepDefinition"":{""id"":""0"",""pattern"":{""source"":""I have {int} cukes in my belly"",""type"":""CUCUMBER_EXPRESSION""},""sourceReference"":{""location"":{""line"":3},""uri"":""samples/minimal/minimal.feature.ts""}}} | ||
| "; | ||
| var sourceReference = new SourceReference("samples/minimal/minimal.feature.ts", | ||
| null, null, new Location(3, null)); | ||
| var stepDefPattern = new StepDefinitionPattern("I have {int} cukes in my belly", StepDefinitionPatternType.CUCUMBER_EXPRESSION); | ||
| var stepDefinition = new StepDefinition("0", stepDefPattern, sourceReference); | ||
| var env = new Envelope(null, null, null, null, null, null, null, null, stepDefinition, null, null, null, null, null, null, null, null); | ||
|
|
||
| var serializedStepDefinition = NdjsonSerializer.Serialize(env); | ||
| var reconstructedStepDefinition = NdjsonSerializer.Deserialize(serializedStepDefinition); | ||
|
|
||
| var expectedStepDefinition = NdjsonSerializer.Deserialize(stepDefinitionNDJSON); | ||
| Assert.Equal(expectedStepDefinition, reconstructedStepDefinition); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Cucumber.Messages.Specs | ||
| { | ||
| public class ConvertersTests | ||
| { | ||
|
|
||
| [Fact] | ||
| public void ConvertsToAndFromTimestamp() | ||
| { | ||
| var current = DateTime.Parse("2024-06-29T17:29:47.1537257Z", null, System.Globalization.DateTimeStyles.RoundtripKind); | ||
| var timestamp = Converters.ToTimestamp(current); | ||
|
|
||
| var dt = Converters.ToDateTime(timestamp); | ||
|
|
||
| Assert.Equal(current, dt); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ConvertsToAndFromDuration() | ||
| { | ||
| var current = TimeSpan.FromSeconds(3.000161); | ||
| var duration = Converters.ToDuration(current); | ||
|
|
||
| var ts = Converters.ToTimeSpan(duration); | ||
|
|
||
| Assert.Equal(current, ts); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using Io.Cucumber.Messages.Types; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Cucumber.Messages.Specs | ||
| { | ||
| public class MessagesTest | ||
| { | ||
|
|
||
| [Fact] | ||
| public void ThrowsWhenRequiredFieldsAreMissing() | ||
| { | ||
| Assert.Throws<ArgumentNullException>(() => new Background(null, null, null, null, null, null)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IsValidWhenNoRequiredFieldsAreMissing() | ||
| { | ||
| // This should succeed as no constructor arguments to an Envelope are required. | ||
| var env = new Envelope(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); | ||
mpkorstanje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
dotnet/Cucumber.Messages.Specs/NdjsonStreamSerializationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| using Cucumber.Messages; | ||
| using Io.Cucumber.Messages.Types; | ||
|
|
||
| namespace Cucumber.Messages.Specs | ||
| { | ||
| public class NdjsonStreamSerializationTests | ||
| { | ||
|
|
||
| [Fact] | ||
| public void WritesSourceEnvelope() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(); | ||
| var writer = new MessageToNdjsonWriter(memoryStream); | ||
| writer.Write(Envelope.Create(new Source("hello.feature", "Feature: Hello", SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN))); | ||
|
|
||
| var json = Encoding.UTF8.GetString(memoryStream.ToArray()); | ||
| Assert.Equal(@"{""source"":{""uri"":""hello.feature"",""data"":""Feature: Hello"",""mediaType"":""text/x.cucumber.gherkin+plain""}}"+Environment.NewLine, json); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DoesNotSerializeNullFields() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(); | ||
| var writer = new MessageToNdjsonWriter(memoryStream); | ||
| writer.Write(new Envelope(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)); | ||
|
|
||
| var json = Encoding.UTF8.GetString(memoryStream.ToArray()); | ||
| Assert.Equal("{}"+Environment.NewLine, json); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IgnoresEmptyLines() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("{}\n{}\n\n{}\n")); | ||
| var enumerator = new NdjsonMessageReader(memoryStream).GetEnumerator(); | ||
|
|
||
| var expectedEnvelope = new Envelope(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); | ||
| for (int i = 0; i < 3; i++) | ||
| { | ||
| Assert.True(enumerator.MoveNext()); | ||
| Assert.Equal(expectedEnvelope, enumerator.Current); | ||
| } | ||
|
|
||
| Assert.False(enumerator.MoveNext()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Handles_Enums() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("{\"attachment\":{\"contentEncoding\":\"BASE64\", \"body\":\"the-body\", \"mediaType\":\"text/plain\"}}\n")); | ||
| var enumerator = new NdjsonMessageReader(memoryStream).GetEnumerator(); | ||
| Assert.True(enumerator.MoveNext()); | ||
| Envelope envelope = enumerator.Current; | ||
|
|
||
| Assert.Equal(AttachmentContentEncoding.BASE64, envelope.Attachment.ContentEncoding); | ||
| Assert.Equal("the-body", envelope.Attachment.Body); | ||
| Assert.Equal("text/plain", envelope.Attachment.MediaType); | ||
| Assert.False(enumerator.MoveNext()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Handles_Single_Argument_Constructor() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("{\"testRunStarted\": {\"timestamp\":{\"nanos\":0,\"seconds\":0}}}\n")); | ||
| var enumerator = new NdjsonMessageReader(memoryStream).GetEnumerator(); | ||
| Assert.True(enumerator.MoveNext()); | ||
| Envelope envelope = enumerator.Current; | ||
| Envelope expected = Envelope.Create(new TestRunStarted(new Timestamp(0, 0))); | ||
|
|
||
| Assert.Equal(expected, envelope); | ||
| Assert.False(enumerator.MoveNext()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Includes_Offending_Line_In_Error_Message() | ||
| { | ||
| MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("BLA BLA")); | ||
| var enumerator = new NdjsonMessageReader(memoryStream).GetEnumerator(); | ||
| var exception = Assert.Throws<InvalidOperationException>( () => enumerator.MoveNext()); | ||
| Assert.Equal("Could not parse JSON: BLA BLA", exception.Message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Text.RegularExpressions; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Cucumber.Messages.Specs | ||
| { | ||
| public class ProtocolVersionTest | ||
| { | ||
| [Fact] | ||
| public void ProtocolVersionIsCorrect() | ||
| { | ||
| Assert.Matches(@"\d+\.\d+\.\d+(-[0-9A-Za-z-](\.[0-9A-Za-z-])*)?", Cucumber.Messages.ProtocolVersion.Version); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using Io.Cucumber.Messages.Types; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Data; | ||
| using System.Text; | ||
|
|
||
| namespace Cucumber.Messages | ||
| { | ||
| public class Converters | ||
| { | ||
| private static DateTime EpochStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); | ||
| private static long NanoSecondsPerTick = 100L; | ||
|
|
||
| public static Timestamp ToTimestamp(DateTime dateTime) | ||
| { | ||
| var timeSpan = (dateTime.Subtract(EpochStart)); | ||
| long seconds = timeSpan.Ticks / TimeSpan.TicksPerSecond; | ||
| long nanos = (timeSpan.Ticks % TimeSpan.TicksPerSecond) * NanoSecondsPerTick; | ||
| return new Timestamp( | ||
| seconds, | ||
| nanos); | ||
| } | ||
|
|
||
| public static Duration ToDuration(TimeSpan timeSpan) | ||
| { | ||
| return new Duration( | ||
| (long) timeSpan.TotalSeconds, | ||
| (timeSpan.Ticks % TimeSpan.TicksPerSecond) * NanoSecondsPerTick); | ||
| } | ||
|
|
||
| public static DateTime ToDateTime(Timestamp timestamp) | ||
| { | ||
| var seconds = timestamp.Seconds; | ||
| var time = EpochStart.AddSeconds(seconds).ToUniversalTime(); | ||
| time = time.AddTicks(timestamp.Nanos / NanoSecondsPerTick); | ||
|
|
||
| return time; | ||
| } | ||
|
|
||
| public static TimeSpan ToTimeSpan(Duration duration) | ||
| { | ||
| var ts = new TimeSpan(0, 0, 0, (int)duration.Seconds); | ||
| ts = ts.Add(TimeSpan.FromTicks(duration.Nanos / NanoSecondsPerTick)); | ||
|
|
||
| return ts; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.