416 lines
13 KiB
C#
416 lines
13 KiB
C#
namespace LaaProduction.Data.Cordonel.UnitTests
|
|
{
|
|
using LaaProduction.Data.Cordonel.Models;
|
|
using LaaProduction.Data.Cordonel.Sentinel;
|
|
using LaaProduction.Data.Cordonel.UnitTests.Mock;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
[TestClass]
|
|
public class SentinelTestClass
|
|
{
|
|
private readonly SentinelTestContext sentinelTestContext;
|
|
private readonly Sentinel sentinel;
|
|
private readonly int pcbId;
|
|
|
|
public SentinelTestClass()
|
|
{
|
|
var jsonFile = @"..\..\Mock\sentinel-data.json";
|
|
this.sentinelTestContext = new SentinelTestContext(jsonFile);
|
|
this.sentinel = this.sentinelTestContext.Sentinel;
|
|
this.pcbId = 212120036;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetUniqueProductionData_ShouldThrowWhenDataIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullProductionData();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetUniqueProductionData(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetUniqueProductionData_ShouldThrowWhenNoData()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareEmptyProductionData();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetUniqueProductionData(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetUniqueProductionData_ShouldThrowOnMultipleData()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareMultipleProductionData();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetUniqueProductionData(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetUniqueProductionData_ShouldGetUniqueProductionData()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareUniqueProductionData();
|
|
|
|
// Act
|
|
this.sentinel.TryGetUniqueProductionData(this.pcbId, out var productionData);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(productionData);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetEOLProgressModel_ShouldThrowWhenModelIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullEOLProgressModel();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetEOLProgressModel(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetEOLProgressModel_ShouldThrowWhenModelDoseNotValidates()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareEmptyEOLProgressModel();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetEOLProgressModel(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetEOLProgressModel_ShouldGetEOLProgressModel()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareEOLProgressModel();
|
|
|
|
// Act
|
|
this.sentinel.TryGetEOLProgressModel(this.pcbId, out var eolProgressModel);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(eolProgressModel);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelRequirements_ShouldThrowWhenRequierementsModelIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullRequirements();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelRequirements(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelRequirements_ShouldGetRequirementsModel()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareRequiremnets();
|
|
|
|
// Act
|
|
this.sentinel.TryGetCordonelRequirements(this.pcbId, out var requirements);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(requirements);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndRegisterValues_ShouldThrowWhenAppsDictionaryIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullAppsDictionary();
|
|
this.sentinelTestContext.PrepareNullRegisterHistory();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndRegisterValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndRegisterValues_ShouldThrowWhenRegisterHistoryIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareDefaultAppsDictionary();
|
|
this.sentinelTestContext.PrepareNullRegisterHistory();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndRegisterValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndRegisterValues_ShouldThrowWhenRegisterHistoryIsEmpty()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareDefaultAppsDictionary();
|
|
this.sentinelTestContext.PrepareEmptyRegisterHistory();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndRegisterValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndRegisterValues_ShouldGetRegisterHistory()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareDefaultAppsDictionary();
|
|
this.sentinelTestContext.PrepareRegisterHistory();
|
|
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndRegisterValues(this.pcbId, out var appsDictionary);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(appsDictionary);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndFWVersionValues_ShouldThrowWhenAppsVersionsIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullAppsVersionsCrcs();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndFWVersionValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndFWVersionValues_ShouldThrowWhenAppsVersionsIsEmpty()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareEmptyAppsVersionsCrcs();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndFWVersionValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelAppsAndFWVersionValues_ShouldThrowGetAppsVersionsCrcs()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareAppsVersionsCrcs();
|
|
|
|
// Act
|
|
this.sentinel.TryGetCordonelAppsAndFWVersionValues(this.pcbId, out var appsVersionsCrcs);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(appsVersionsCrcs);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelMetrologyValues_ShouldThrowWhenMetrologyValuesIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullMetrologyValues();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelMetrologyValues(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelMetrologyValues_ShouldGetMetrologyValues()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareMetrologyValues();
|
|
|
|
// Act
|
|
this.sentinel.TryGetCordonelMetrologyValues(this.pcbId, out var metrologyValues);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(metrologyValues);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelRadioDefaults_ShouldThrowWhenRSSIValuesIsNull()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareNullRSSIValues();
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryGetCordonelRadioDefaults(this.pcbId, out var _);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetCordonelRadioDefaults_ShouldGetRSSIValues()
|
|
{
|
|
// Arrange
|
|
this.sentinelTestContext.PrepareRSSIValues();
|
|
|
|
// Act
|
|
this.sentinel.TryGetCordonelRadioDefaults(this.pcbId, out var rssiValues);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(rssiValues);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldNotCompareWhenEOLStatusNA()
|
|
=> this.sentinel.TryCompareRequirementsIdAndVersion(new EOLProgressModel { RequirementRequestChecked = EOLStatus.NA }, null);
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldThrowByDifferentStandardIds()
|
|
{
|
|
// Arrange
|
|
var args = this.sentinelTestContext.TryCompareRequirementsIdAndVersionTestCase(1, 2, 3, 4, 2, 2, 3, 4);
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryCompareRequirementsIdAndVersion(args.Item1, args.Item2);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldThrowByDifferentStandardVersions()
|
|
{
|
|
// Arrange
|
|
var args = this.sentinelTestContext.TryCompareRequirementsIdAndVersionTestCase(1, 2, 3, 4, 1, 3, 3, 4);
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryCompareRequirementsIdAndVersion(args.Item1, args.Item2);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldThrowByDifferentSpecialIds()
|
|
{
|
|
// Arrange
|
|
var args = this.sentinelTestContext.TryCompareRequirementsIdAndVersionTestCase(1, 2, 3, 4, 1, 2, 4, 4);
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryCompareRequirementsIdAndVersion(args.Item1, args.Item2);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldThrowByDifferentSpecialVersions()
|
|
{
|
|
// Arrange
|
|
var args = this.sentinelTestContext.TryCompareRequirementsIdAndVersionTestCase(1, 2, 3, 4, 1, 2, 3, 5);
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryCompareRequirementsIdAndVersion(args.Item1, args.Item2);
|
|
});
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRequirementsIdAndVersion_ShouldDoNothingWhenIdAndVersionAreSame()
|
|
{
|
|
// Arrange
|
|
var args = this.sentinelTestContext.TryCompareRequirementsIdAndVersionTestCase(1, 2, 3, 4, 1, 2, 3, 4);
|
|
|
|
// Act
|
|
this.sentinel.TryCompareRequirementsIdAndVersion(args.Item1, args.Item2);
|
|
|
|
// Assert OK
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRegionSizeKey_ShouldDoNothingWhenNA()
|
|
{
|
|
// Arrange
|
|
var eolProgress = new EOLProgressModel { RequirementRegionChecked = EOLStatus.NA };
|
|
|
|
// Act
|
|
this.sentinel.TryCompareRegionSizeKey(null, null, eolProgress);
|
|
|
|
// Assert
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRegionSizeKey_ShouldDoNothingWhenRegionSizeKeyAreSame()
|
|
{
|
|
// Arrange
|
|
var eolProgress = new EOLProgressModel { RequirementRegionChecked = EOLStatus.OK };
|
|
var productionData = new CordonelProductionData { RegionSizeKey = "AB" };
|
|
var requirements = new CordonelRequirements { RegionSizeKey = "AB" };
|
|
|
|
// Act
|
|
this.sentinel.TryCompareRegionSizeKey(productionData, requirements, eolProgress);
|
|
|
|
// Assert
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryCompareRegionSizeKey_ShouldThrowWhenRegionSizeKeyAreDifferent()
|
|
{
|
|
// Arrange
|
|
var eolProgress = new EOLProgressModel { RequirementRegionChecked = EOLStatus.OK };
|
|
var productionData = new CordonelProductionData { RegionSizeKey = "AB" };
|
|
var requirements = new CordonelRequirements { RegionSizeKey = "CD" };
|
|
|
|
// Assert
|
|
Assert.ThrowsException<SentinelException>(() =>
|
|
{
|
|
// Act
|
|
this.sentinel.TryCompareRegionSizeKey(productionData, requirements, eolProgress);
|
|
});
|
|
}
|
|
}
|
|
}
|