Skip to content

Commit

Permalink
Merge pull request #2 from jmayer913/v1.1.0/VersionBranch
Browse files Browse the repository at this point in the history
V1.1.0/version branch
  • Loading branch information
jmayer913 authored Aug 24, 2024
2 parents a5dd1f3 + 93612be commit 0ef24ae
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 50 deletions.
35 changes: 0 additions & 35 deletions JMayer.Example.WindowsService/BSM/BMSEqualityComparer.cs

This file was deleted.

34 changes: 34 additions & 0 deletions JMayer.Example.WindowsService/BSM/BSM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ public class BSM : ITypeB
/// </summary>
public VersionSupplementaryData? VersionSupplementaryData { get; set; }

/// <summary>
/// The default constructor.
/// </summary>
public BSM() { }

/// <summary>
/// The copy constructor.
/// </summary>
/// <param name="copy">The object to copy from.</param>
public BSM(BSM copy)
{
ChangeOfStatus = copy.ChangeOfStatus;

if (copy.BaggageTagDetails != null)
{
BaggageTagDetails = new BaggageTagDetails(copy.BaggageTagDetails);
}

if (copy.OutboundFlight != null)
{
OutboundFlight = new OutboundFlight(copy.OutboundFlight);
}

if (copy.PassengerName != null)
{
PassengerName = new PassengerName(copy.PassengerName);
}

if (copy.VersionSupplementaryData != null)
{
VersionSupplementaryData = new VersionSupplementaryData(copy.VersionSupplementaryData);
}
}

/// <summary>
/// The method returns the change of status from the BSM.
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions JMayer.Example.WindowsService/BSM/BSMEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Diagnostics.CodeAnalysis;

namespace JMayer.Example.WindowsService.BSM;

/// <summary>
/// The class manages comparing two BSM objects.
/// </summary>
public class BSMEqualityComparer : IEqualityComparer<BSM>
{
/// <inheritdoc/>
public bool Equals(BSM? x, BSM? y)
{
if (x == null || y == null)
{
return false;
}

return new BaggageTagDetailEqualityComparer().Equals(x.BaggageTagDetails, y.BaggageTagDetails)
&& x.ChangeOfStatus == y.ChangeOfStatus
&& new OutboundFlightEqualityComparer().Equals(x.OutboundFlight, y.OutboundFlight)
&& new PassengerNameEqualityComparer().Equals(x.PassengerName, y.PassengerName)
&& new VersionSupplementaryDataEqualityComparer().Equals(x.VersionSupplementaryData, y.VersionSupplementaryData);
}

/// <inheritdoc/>
public int GetHashCode([DisallowNull] BSM obj)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions JMayer.Example.WindowsService/BSM/BaggageTagDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public int Count
/// </summary>
public const string DotNElement = ".N";

/// <summary>
/// The default constructor.
/// </summary>
public BaggageTagDetails() { }

/// <summary>
/// The copy constructor.
/// </summary>
/// <param name="copy">The object to copy from.</param>
public BaggageTagDetails(BaggageTagDetails copy) => BaggageTagNumbers.AddRange(copy.BaggageTagNumbers);

/// <inheritdoc/>
public void Parse(string typeBString)
{
Expand Down
18 changes: 18 additions & 0 deletions JMayer.Example.WindowsService/BSM/OutboundFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ public class OutboundFlight : ITypeB
[RegularExpression("^([0-9]{4})|([0-9]{4}[A-Z]{1})$", ErrorMessage = "The flight number must be 4 digits and optionally a capital letter.")]
public string FlightNumber { get; set; } = string.Empty;

/// <summary>
/// The default constructor.
/// </summary>
public OutboundFlight() { }

/// <summary>
/// The copy constructor.
/// </summary>
/// <param name="copy">The object to copy from.</param>
public OutboundFlight(OutboundFlight copy)
{
Airline = copy.Airline;
ClassOfTravel = copy.ClassOfTravel;
Destination = copy.Destination;
FlightDate = copy.FlightDate;
FlightNumber = copy.FlightNumber;
}

/// <inheritdoc/>
public void Parse(string typeBString)
{
Expand Down
15 changes: 15 additions & 0 deletions JMayer.Example.WindowsService/BSM/PassengerName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ public class PassengerName : ITypeB
[Required]
public string SurName { get; set; } = string.Empty;

/// <summary>
/// The default constructor.
/// </summary>
public PassengerName() { }

/// <summary>
/// The copy constructor.
/// </summary>
/// <param name="copy">The object to copy from.</param>
public PassengerName(PassengerName copy)
{
GivenNames.AddRange(copy.GivenNames);
SurName = copy.SurName;
}

/// <inheritdoc/>
public void Parse(string typeBString)
{
Expand Down
21 changes: 17 additions & 4 deletions JMayer.Example.WindowsService/BSM/VersionSupplementaryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public class VersionSupplementaryData : ITypeB
/// </summary>
public const string TransferBaggageSourceIndicator = "T";

/// <summary>
/// The default constructor.
/// </summary>
public VersionSupplementaryData() { }

/// <summary>
/// The copy constructor.
/// </summary>
/// <param name="copy">The object to copy from.</param>
public VersionSupplementaryData(VersionSupplementaryData copy)
{
AirportCode = copy.AirportCode;
BaggageSourceIndicator = copy.BaggageSourceIndicator;
DataDictionaryVersionNumber = copy.DataDictionaryVersionNumber;
}

/// <inheritdoc/>
public void Parse(string typeBString)
{
Expand All @@ -75,8 +91,5 @@ public void Parse(string typeBString)
}

/// <inheritdoc/>
public string ToTypeB()
{
return $"{DotVElement}/{DataDictionaryVersionNumber}{BaggageSourceIndicator}{AirportCode}{Environment.NewLine}";
}
public string ToTypeB() => $"{DotVElement}/{DataDictionaryVersionNumber}{BaggageSourceIndicator}{AirportCode}{Environment.NewLine}";
}
3 changes: 2 additions & 1 deletion JMayer.Example.WindowsService/BSMServerConnectionWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

if (id != Guid.Empty)
{
_logger.LogInformation("The BSM server accepted a remote client connection.");
string remoteEndPoint = _server.GetRemoteEndPoint(id);
_logger.LogInformation("The BSM server accepted a remote client connection from {EndPoint}.", remoteEndPoint);
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-JMayer.Example.WindowsService-4a84891d-50d1-410c-a081-1ab5bc58916f</UserSecretsId>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JMayer.Net" Version="1.0.0" />
<PackageReference Include="JMayer.Net" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
</ItemGroup>
Expand Down
154 changes: 154 additions & 0 deletions TestProject/Test/BSMEqualityComparerUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using JMayer.Example.WindowsService.BSM;

namespace TestProject.Test;

/// <summary>
/// The class manages testing the BSM equality comparer.
/// </summary>
public class BSMEqualityComparerUnitTest
{
/// <summary>
/// The constant for the .F airline.
/// </summary>
private const string DotFAirline = "AA";

/// <summary>
/// The constant for the .F class of travel.
/// </summary>
private const string DotFClassOfTravel = "A";

/// <summary>
/// The constant for the .F destination.
/// </summary>
private const string DotFDestination = "MSY";

/// <summary>
/// The constant for the .F flight number.
/// </summary>
private const string DotFFlightNumber = "1234";

/// <summary>
/// The constant for the .N tag number.
/// </summary>
private const string DotNTagNumber = "0001123456";

/// <summary>
/// The constant for the .P given name.
/// </summary>
private const string DotPGivenName = "PASSENGER";

/// <summary>
/// The constant for the .P surname.
/// </summary>
private const string DotPSurName = "TEST";

/// <summary>
/// The constant for the .V airport code.
/// </summary>
private const string DotVAirportCode = "MCO";

/// <summary>
/// The constant for the .V data dictionary version number.
/// </summary>
private const int DotVDataDictionaryVersionNumber = 1;

/// <summary>
/// The method verifies equality failure when the ChangeOfStatus property is different between the two objects.
/// </summary>
[Fact]
public void VerifyFailureChangeOfStatus()
{
BSM bsm1 = new()
{
ChangeOfStatus = BSM.Add,
};
BSM bsm2 = new()
{
ChangeOfStatus = BSM.Change,
};

Assert.False(new BSMEqualityComparer().Equals(bsm1, bsm2));
}

/// <summary>
/// The method verifies equality failure when two nulls are compared.
/// </summary>
[Fact]
public void VerifyFailureBothNull() => Assert.False(new BSMEqualityComparer().Equals(null, null));

/// <summary>
/// The method verifies equality failure when an object and null are compared.
/// </summary>
[Fact]
public void VerifyFailureOneIsNull()
{
BSM bsm = new()
{
BaggageTagDetails = new BaggageTagDetails()
{
BaggageTagNumbers = [DotNTagNumber],
},
ChangeOfStatus = BSM.Add,
OutboundFlight = new OutboundFlight()
{
Airline = DotFAirline,
ClassOfTravel = DotFClassOfTravel,
Destination = DotFDestination,
FlightDate = DateTime.Today.ToDayMonthFormat(),
FlightNumber = DotFFlightNumber,
},
PassengerName = new PassengerName()
{
GivenNames = [DotPGivenName],
SurName = DotPSurName,
},
VersionSupplementaryData = new()
{
AirportCode = DotVAirportCode,
BaggageSourceIndicator = VersionSupplementaryData.LocalBaggageSourceIndicator,
DataDictionaryVersionNumber = DotVDataDictionaryVersionNumber,
},
};

Assert.False(new BSMEqualityComparer().Equals(bsm, null));
Assert.False(new BSMEqualityComparer().Equals(null, bsm));
}

/// <summary>
/// The method verifies equality failure when an object and null are compared.
/// </summary>
[Fact]
public void VerifySuccess()
{
BSM bsm1 = new()
{
BaggageTagDetails = new BaggageTagDetails()
{
BaggageTagNumbers = [DotNTagNumber],
},
ChangeOfStatus = BSM.Add,
OutboundFlight = new OutboundFlight()
{
Airline = DotFAirline,
ClassOfTravel = DotFClassOfTravel,
Destination = DotFDestination,
FlightDate = DateTime.Today.ToDayMonthFormat(),
FlightNumber = DotFFlightNumber,
},
PassengerName = new PassengerName()
{
GivenNames = [DotPGivenName],
SurName = DotPSurName,
},
VersionSupplementaryData = new()
{
AirportCode = DotVAirportCode,
BaggageSourceIndicator = VersionSupplementaryData.LocalBaggageSourceIndicator,
DataDictionaryVersionNumber = DotVDataDictionaryVersionNumber,
},
};
BSM bsm2 = new(bsm1);

Assert.True(new BSMEqualityComparer().Equals(bsm1, bsm2));
}
}
Loading

0 comments on commit 0ef24ae

Please sign in to comment.