Skip to content

Commit

Permalink
GitHub Actions with workflows tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a7a6ecc3e59179971fd5e47bdc516a583c71861)
  • Loading branch information
Rodrigo Cesar committed May 20, 2024
1 parent 2da1105 commit f486755
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/csharp.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: C# CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

defaults:
run:
working-directory: ./lib/csharp-models-to-json_test

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal

26 changes: 26 additions & 0 deletions .github/workflows/node.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ lib/csharp-models-to-json/bin
lib/csharp-models-to-json/obj
lib/csharp-models-to-json_test/obj/
lib/csharp-models-to-json_test/bin/
/test-files/api.d.ts

**/.vs/*
.vscode/*
.idea/*
.idea/*
*.user
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"bin": {
"csharp-models-to-typescript": "./index.js"
},
"scripts": {
"test": "node index.js --config=./test-files/test-config.json && node ./test-files/test-file-exists.js --config=./test-files/test-config.json"
},
"dependencies": {
"camelcase": "^6.0.0"
}
Expand Down
143 changes: 143 additions & 0 deletions test-files/AlarmOccurrence.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using FG.Sitrad.Common.Enum;

namespace FG.Sitrad.Model
{
[DataContract]
[DebuggerDisplay("{AlarmCode}")]
public class AlarmOccurrence : ICloneable
{
#region Propriedades adicionais

/// <summary>
/// Utilizado para verificar se é preciso salvar o objeto ao final do processamento de alarmes.
/// </summary>
[IgnoreDataMember]
public bool IsSavePending { get; set; }

[IgnoreDataMember]
public AlarmInhibitionType PreviousInhibitionType = AlarmInhibitionType.Undefined;

[IgnoreDataMember]
public AlarmInhibitionType inhibitionType = AlarmInhibitionType.Undefined;

#endregion



#region Campos do banco de dados

[DataMember]
public int Id { get; set; }

[DataMember]
public int InstrumentId { get; set; }

[DataMember]
public string AlarmCode { get; set; }

[DataMember]
public string Description { get; set; }

[DataMember(EmitDefaultValue = false)]
public string Value { get; set; }

[DataMember]
public DateTime OccurrenceDate { get; set; }

[DataMember(EmitDefaultValue = false)]
public DateTime? OccurrenceFinalDate { get; set; }

[DataMember(EmitDefaultValue = false)]
public DateTime? AcknowledgeTime { get; set; }

[DataMember(EmitDefaultValue = false)]
public int? AcknowledgeUserId { get; set; }

[DataMember(EmitDefaultValue = false)]
public string AcknowledgeUserName { get; set; }

[DataMember]
public AlarmInhibitionType InhibitionType
{
get => inhibitionType;
set
{
PreviousInhibitionType = inhibitionType;
inhibitionType = value;
}
}

[DataMember(EmitDefaultValue = false)]
public bool Inhibited { get; set; }

[IgnoreDataMember]
public DateTime? DelayEndDate { get; set; }

[DataMember(EmitDefaultValue = false)]
public int? EventLogId { get; set; }

[DataMember(EmitDefaultValue = false)]
public EventLog EventLog { get; set; }

[DataMember(EmitDefaultValue = false)]
public int? AcknowledgeEventLogId { get; set; }

[DataMember(EmitDefaultValue = false)]
public bool OccurringOrUnacknowledged { get; private set; }

[DataMember(EmitDefaultValue = false)]
public EventLog AcknowledgeEventLog { get; set; }

[DataMember(EmitDefaultValue = false)]
public Instrument Instrument { get; set; }

[IgnoreDataMember]
public User AcknowledgeUser { get; set; }

[DataMember]
public IList<AlarmNotificationType> IgnoredTo { get; set; }

#endregion



#region IClonable

public object Clone()
{
var occurrence = new AlarmOccurrence();
CloneTo(ref occurrence);
return occurrence;
}

public void CloneTo(ref AlarmOccurrence alarmOccurrence)
{
alarmOccurrence.Id = Id;
alarmOccurrence.AlarmCode = AlarmCode;
alarmOccurrence.Description = Description;
alarmOccurrence.Value = Value;
alarmOccurrence.OccurrenceDate = OccurrenceDate;
alarmOccurrence.OccurrenceFinalDate = OccurrenceFinalDate;
alarmOccurrence.AcknowledgeTime = AcknowledgeTime;
alarmOccurrence.InhibitionType = InhibitionType;
alarmOccurrence.Inhibited = Inhibited;
alarmOccurrence.EventLog = EventLog;
alarmOccurrence.EventLogId = EventLogId;
alarmOccurrence.AcknowledgeEventLog = AcknowledgeEventLog;
alarmOccurrence.AcknowledgeEventLogId = AcknowledgeEventLogId;
alarmOccurrence.InstrumentId = InstrumentId;
alarmOccurrence.Instrument = Instrument;
alarmOccurrence.AcknowledgeUser = AcknowledgeUser;
alarmOccurrence.AcknowledgeUserId = AcknowledgeUserId;
alarmOccurrence.AcknowledgeUserName = AcknowledgeUserName;
alarmOccurrence.IgnoredTo = IgnoredTo;
alarmOccurrence.IsSavePending = IsSavePending;
}

#endregion
}
}
25 changes: 25 additions & 0 deletions test-files/test-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"include": [
"test-files/*.cs"
],
"exclude": [ ],
"output": "./test-files/api.d.ts",
"camelCase": false,
"camelCaseEnums": false,
"camelCaseOptions": {
"pascalCase": false,
"preserveConsecutiveUppercase": false,
"locale": "en-US"
},
"includeComments": true,
"numericEnums": true,
"omitSemicolon": true,
"omitFilePathComment": true,
"stringLiteralTypesInsteadOfEnums": false,
"customTypeTranslations": {
"ProductName": "string",
"ProductNumber": "string",
"byte": "number",
"uint": "number"
}
}
31 changes: 31 additions & 0 deletions test-files/test-file-exists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');

const configArg = process.argv.find(x => x.startsWith('--config='));

if (!configArg) {
throw Error('No configuration file for `csharp-models-to-typescript` provided.');
}

const configPath = configArg.substr('--config='.length);
let config;

try {
unparsedConfig = fs.readFileSync(configPath, 'utf8');
} catch (error) {
throw Error(`Configuration file "${configPath}" not found.\n${error.message}`);
}

try {
config = JSON.parse(unparsedConfig);
} catch (error) {
throw Error(`Configuration file "${configPath}" contains invalid JSON.\n${error.message}`);
}

const output = config.output || 'types.d.ts';

if (!fs.existsSync(output))
throw Error(`Can't find output file: ${output}`)

const file = fs.readFileSync(output, 'utf8')
if (file.length === 0)
throw Error(`File '${output}' is empty`)

0 comments on commit f486755

Please sign in to comment.