Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

51 changes: 51 additions & 0 deletions MyNumberNET_ApiServer/Controllers/MyNumberController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Mvc;
using MyNumberNET;

namespace MyNumberNET_ApiServer.Controllers
{
/// <summary>
/// Controller for exposing MyNumberNET functionality via REST API.
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class MyNumberController : ControllerBase
{
/// <summary>
/// Verifies if the provided 12-digit array is a valid "My Number".
/// </summary>
/// <param name="number">An array of 12 integers representing the My Number digits.</param>
/// <returns>True if valid, false otherwise. Returns BadRequest if input is malformed.</returns>
[HttpPost("verify")]
public ActionResult<bool> Verify([FromBody] int[] number)
{
try
{
bool isValid = MyNumber.VerifyNumber(number);
return Ok(isValid);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}

/// <summary>
/// Calculates the check digit for the provided 11-digit array.
/// </summary>
/// <param name="number">An array of 11 integers representing the first 11 digits of My Number.</param>
/// <returns>The calculated check digit. Returns BadRequest if input is malformed.</returns>
[HttpPost("checkdigit")]
public ActionResult<int> CheckDigit([FromBody] int[] number)
{
try
{
int checkDigit = MyNumber.CalculateCheckDigits(number);
return Ok(checkDigit);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}
12 changes: 12 additions & 0 deletions MyNumberNET_ApiServer/MyNumberNET_ApiServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MyNumberNET\MyNumberNET.csproj" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions MyNumberNET_ApiServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace MyNumberNET_ApiServer
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

var app = builder.Build();

app.UseRouting();
app.UseEndpoints(endpoints =>

Check warning on line 17 in MyNumberNET_ApiServer/Program.cs

View workflow job for this annotation

GitHub Actions / build

Suggest using top level route registrations instead of UseEndpoints (https://aka.ms/aspnet/analyzers)

Check warning on line 17 in MyNumberNET_ApiServer/Program.cs

View workflow job for this annotation

GitHub Actions / build

Suggest using top level route registrations instead of UseEndpoints (https://aka.ms/aspnet/analyzers)
{
endpoints.MapControllers();
});

app.Run();
}
}
}
72 changes: 72 additions & 0 deletions MyNumberNET_Test/MyNumberControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using Xunit;
using MyNumberNET_ApiServer.Controllers;
using Microsoft.AspNetCore.Mvc;

namespace MyNumberNET_Test
{
public class MyNumberControllerTests
{
[Fact]
public void Verify_ValidNumber_ReturnsTrue()
{
var controller = new MyNumberController();
var first11 = new[] { 1,2,3,4,5,6,7,8,9,0,1 };
var checkDigit = MyNumberNET.MyNumber.CalculateCheckDigits((int[])first11.Clone());
var validNumber = new int[12];
Array.Copy(first11, validNumber, 11);
validNumber[11] = checkDigit;
var result = controller.Verify(validNumber);
Assert.NotNull(result.Result);
var okResult = result.Result as OkObjectResult;
Assert.NotNull(okResult);
Assert.True((bool)okResult.Value);
}

[Fact]
public void Verify_InvalidNumber_ReturnsFalse()
{
var controller = new MyNumberController();
var invalidNumber = new[] { 1,2,3,4,5,6,7,8,9,0,1,3 }; // Last digit is wrong
var result = controller.Verify(invalidNumber);
Assert.NotNull(result.Result);
var okResult = result.Result as OkObjectResult;
Assert.NotNull(okResult);
Assert.False((bool)okResult.Value);
}

[Fact]
public void Verify_MalformedNumber_ReturnsBadRequest()
{
var controller = new MyNumberController();
var malformedNumber = new[] { 1,2,3 }; // Too short
var result = controller.Verify(malformedNumber);
Assert.NotNull(result.Result);
var badRequestResult = result.Result as BadRequestObjectResult;
Assert.NotNull(badRequestResult);
}

[Fact]
public void CheckDigit_ValidInput_ReturnsDigit()
{
var controller = new MyNumberController();
var digits = new[] { 1,2,3,4,5,6,7,8,9,0,1 };
var result = controller.CheckDigit(digits);
Assert.NotNull(result.Result);
var okResult = result.Result as OkObjectResult;
Assert.NotNull(okResult);
Assert.True(int.TryParse(okResult.Value.ToString(), out _));
}

[Fact]
public void CheckDigit_MalformedInput_ReturnsBadRequest()
{
var controller = new MyNumberController();
var malformedDigits = new[] { 1,2,3 }; // Too short
var result = controller.CheckDigit(malformedDigits);
Assert.NotNull(result.Result);
var badRequestResult = result.Result as BadRequestObjectResult;
Assert.NotNull(badRequestResult);
}
}
}
3 changes: 3 additions & 0 deletions MyNumberNET_Test/MyNumberNET_Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<!-- Other test dependencies -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyNumberNET\MyNumberNET.csproj" />
<ProjectReference Include="..\MyNumberNET_ApiServer\MyNumberNET_ApiServer.csproj" />
</ItemGroup>
<PropertyGroup>
<Deterministic>true</Deterministic>
Expand Down
52 changes: 34 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# My Number Library for .NET

This repository provides tools for validating and generating Japanese My Number (Social Security and Tax Number System) in .NET.
This repository provides tools for validating and generating Japanese My Number (Social Security and Tax Number System) in .NET 8.0.

## Project Structure

- **MyNumberNET/**: Core .NET 8.0 library for My Number validation and generation.
- **MyNumberNET_ApiServer/**: ASP.NET Core Web API for My Number validation and generation.
- **MyNumberNET_CLI/**: Command-line interface for interacting with the library. Uses NLog for logging.
- **MyNumberNET_Test/**: Unit tests for the library and API server.
- **Jenkinsfile**: CI/CD pipeline configuration.
- **global.json**: Specifies the .NET SDK version.
- **MyNumberNET.sln**: Solution file for managing all projects.

## Projects

### MyNumberNET
A .NET library for validating and generating My Number sequences.
A .NET 8.0 library for validating and generating My Number sequences.

**Features:**
- Validate a 12-digit My Number: `MyNumber.VerifyNumber(int[] number)`
Expand All @@ -19,13 +29,26 @@ int[] number = {6,1,4,1,0,6,5,2,6,0,0,0};
bool isValid = MyNumber.VerifyNumber(number);
```

### MyNumberNET_ApiServer
ASP.NET Core Web API for validating and generating My Numbers.

**Usage:**
```
dotnet run --project MyNumberNET_ApiServer
```
The API exposes endpoints for validation and generation. See `Controllers/MyNumberController.cs` for details.

### MyNumberNET_CLI
A command-line interface for validating and generating My Numbers.
A command-line interface for validating and generating My Numbers. Uses NLog for logging.

**Usage:**
```
dotnet run --project MyNumberNET_CLI [command] [arguments]
```
Or run the built executable directly:
```
MyNumberNET_CLI\bin\Debug\net8.0\MyNumberNET_CLI.exe [command] [arguments]
```
**Commands:**
- `generate [count]` : Generate valid My Numbers
- `check [My Number]` : Validate a given number
Expand All @@ -34,27 +57,20 @@ dotnet run --project MyNumberNET_CLI [command] [arguments]
- `ranges [min] [max]` : Generate numbers in a sequential range

### MyNumberNET_Test
Unit tests for the library.
Unit tests for the library and API server.

**To run tests:**
**Run tests:**
```
dotnet test MyNumberNET_Test
```

## Build Instructions
## Solution Management

1. Clone the repository.
2. Build the solution:
```
dotnet build MyNumberNET.sln
```
3. Run CLI or tests as shown above.
Use the solution file to build and manage all projects:
```
dotnet build MyNumberNET.sln
```

## .NET Version
All projects now target **.NET 8 (net8.0)**. You need the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) to build and run.

## Logging
The CLI uses **NLog** for logging. Configuration is in `MyNumberNET_CLI/nlog.config`.

## License
See LICENSE for details.
This repository uses .NET 8.0. The required SDK version is specified in `global.json`.
Loading