PCRB Type field
This commit is contained in:
parent
bf3e46a784
commit
e452047dfb
@ -25,25 +25,33 @@ public static class MockMemoryCacheService {
|
|||||||
public class PCRBServiceTests {
|
public class PCRBServiceTests {
|
||||||
private readonly Mock<ILogger<PCRBService>> _loggerMock;
|
private readonly Mock<ILogger<PCRBService>> _loggerMock;
|
||||||
private readonly Mock<IDalService> _dalServiceMock;
|
private readonly Mock<IDalService> _dalServiceMock;
|
||||||
private readonly Mock<IMemoryCache> _cacheMock;
|
private Mock<IMemoryCache> _cacheMock;
|
||||||
private readonly Mock<IUserService> _userServiceMock;
|
private readonly Mock<IUserService> _userServiceMock;
|
||||||
private readonly Mock<IApprovalService> _approvalServiceMock;
|
private readonly Mock<IApprovalService> _approvalServiceMock;
|
||||||
private readonly Mock<ISmtpService> _smtpServiceMock;
|
private readonly Mock<ISmtpService> _smtpServiceMock;
|
||||||
private readonly PCRBService _pcrbService;
|
private PCRBService _pcrbService;
|
||||||
|
|
||||||
|
private static IEnumerable<PCRB> PCRBS = new List<PCRB>() {
|
||||||
|
new PCRB {
|
||||||
|
PlanNumber = 1,
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
InsertTimeStamp = DateTime.Now,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static IEnumerable<PCRBFollowUp> FOLLOW_UPS = new List<PCRBFollowUp>() {
|
private static IEnumerable<PCRBFollowUp> FOLLOW_UPS = new List<PCRBFollowUp>() {
|
||||||
new PCRBFollowUp { ID = 1, PlanNumber = 1, Step = 1, FollowUpDate = DateTime.Now }
|
new PCRBFollowUp { ID = 1, PlanNumber = 1, Step = 1, FollowUpDate = DateTime.Now }
|
||||||
};
|
};
|
||||||
|
|
||||||
public PCRBServiceTests() {
|
private static AppSettings appSettings = new AppSettings(
|
||||||
_loggerMock = new Mock<ILogger<PCRBService>>();
|
|
||||||
_dalServiceMock = new Mock<IDalService>();
|
|
||||||
_userServiceMock = new Mock<IUserService>();
|
|
||||||
_approvalServiceMock = new Mock<IApprovalService>();
|
|
||||||
_smtpServiceMock = new Mock<ISmtpService>();
|
|
||||||
_cacheMock = MockMemoryCacheService.GetMemoryCache(FOLLOW_UPS);
|
|
||||||
|
|
||||||
var appSettings = new AppSettings(
|
|
||||||
Company: "Infineon",
|
Company: "Infineon",
|
||||||
DbConnectionString: "connectionString",
|
DbConnectionString: "connectionString",
|
||||||
JwtAudience: "audience",
|
JwtAudience: "audience",
|
||||||
@ -56,6 +64,14 @@ public class PCRBServiceTests {
|
|||||||
WorkingDirectoryName: "workingDirectoryName"
|
WorkingDirectoryName: "workingDirectoryName"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public PCRBServiceTests() {
|
||||||
|
_loggerMock = new Mock<ILogger<PCRBService>>();
|
||||||
|
_dalServiceMock = new Mock<IDalService>();
|
||||||
|
_userServiceMock = new Mock<IUserService>();
|
||||||
|
_approvalServiceMock = new Mock<IApprovalService>();
|
||||||
|
_smtpServiceMock = new Mock<ISmtpService>();
|
||||||
|
_cacheMock = MockMemoryCacheService.GetMemoryCache(FOLLOW_UPS);
|
||||||
|
|
||||||
_pcrbService = new PCRBService(
|
_pcrbService = new PCRBService(
|
||||||
_loggerMock.Object,
|
_loggerMock.Object,
|
||||||
_dalServiceMock.Object,
|
_dalServiceMock.Object,
|
||||||
@ -67,6 +83,161 @@ public class PCRBServiceTests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateNewPCRB_WithValidParam_ShouldCreatePCRB() {
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
InsertTimeStamp = DateTime.Now,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.ReturnsAsync(1);
|
||||||
|
|
||||||
|
await _pcrbService.CreateNewPCRB(pcrb);
|
||||||
|
|
||||||
|
_dalServiceMock.Verify(d => d.ExecuteAsync(It.IsAny<string>(), pcrb), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateNewPCRB_WithNullParam_ShouldThrowException() {
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => _pcrbService.CreateNewPCRB(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateNewPCRB_WithDatabaseFailure_ShouldThrowException() {
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
InsertTimeStamp = DateTime.Now,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.ReturnsAsync(0);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<Exception>(() => _pcrbService.CreateNewPCRB(pcrb));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateNewPCRB_WithDatabaseException_ShouldThrowException() {
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
InsertTimeStamp = DateTime.Now,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.Throws<Exception>();
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<Exception>(() => _pcrbService.CreateNewPCRB(pcrb));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UpdatePCRB_WithValidParam_ShouldUpdatePCRB() {
|
||||||
|
_cacheMock = MockMemoryCacheService.GetMemoryCache(PCRBS);
|
||||||
|
|
||||||
|
_pcrbService = new PCRBService(
|
||||||
|
_loggerMock.Object,
|
||||||
|
_dalServiceMock.Object,
|
||||||
|
_cacheMock.Object,
|
||||||
|
_userServiceMock.Object,
|
||||||
|
_approvalServiceMock.Object,
|
||||||
|
_smtpServiceMock.Object,
|
||||||
|
appSettings
|
||||||
|
);
|
||||||
|
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
PlanNumber = 1,
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
ClosedDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.ReturnsAsync(1);
|
||||||
|
|
||||||
|
await _pcrbService.UpdatePCRB(pcrb);
|
||||||
|
|
||||||
|
_dalServiceMock.Verify(d => d.ExecuteAsync(It.IsAny<string>(), pcrb), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UpdatePCRB_WithNullParam_ShouldThrowException() {
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => _pcrbService.UpdatePCRB(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UpdatePCRB_WithDatabaseFailure_ShouldThrowException() {
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
PlanNumber = 1,
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
ClosedDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.ReturnsAsync(0);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<Exception>(() => _pcrbService.UpdatePCRB(pcrb));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UpdatePCRB_WithDatabaseException_ShouldThrowException() {
|
||||||
|
var pcrb = new PCRB {
|
||||||
|
PlanNumber = 1,
|
||||||
|
OwnerID = 1,
|
||||||
|
Title = "Test Title",
|
||||||
|
ChangeLevel = "Level 1",
|
||||||
|
ReasonForChange = "Test Reason",
|
||||||
|
ChangeDescription = "Test Description",
|
||||||
|
IsITAR = false,
|
||||||
|
CurrentStep = 1,
|
||||||
|
LastUpdateDate = DateTime.Now,
|
||||||
|
ClosedDate = DateTime.Now,
|
||||||
|
Type = "Type 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
|
||||||
|
.Throws<Exception>();
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<Exception>(() => _pcrbService.UpdatePCRB(pcrb));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateFollowUp_WithValidParam_ShouldCreateFollowUp() {
|
public async Task CreateFollowUp_WithValidParam_ShouldCreateFollowUp() {
|
||||||
var followUp = new PCRBFollowUp {
|
var followUp = new PCRBFollowUp {
|
||||||
|
@ -78,16 +78,15 @@ public class PCRBService : IPCRBService {
|
|||||||
|
|
||||||
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
|
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
|
||||||
|
|
||||||
|
pcrb.LastUpdateDate = DateTime.Now;
|
||||||
|
|
||||||
StringBuilder queryBuilder = new();
|
StringBuilder queryBuilder = new();
|
||||||
queryBuilder.Append("insert into CCChangeControl (OwnerID, Title, ChangeLevel, ReasonForChange, ");
|
queryBuilder.Append("insert into CCChangeControl (OwnerID, Title, ChangeLevel, ReasonForChange, ");
|
||||||
queryBuilder.Append("ChangeDescription, IsITAR, CurrentStep, InsertTimeStamp, LastUpdateDate) ");
|
queryBuilder.Append("ChangeDescription, IsITAR, CurrentStep, InsertTimeStamp, LastUpdateDate, Type) ");
|
||||||
queryBuilder.Append($"values ({pcrb.OwnerID}, '{pcrb.Title}', '{pcrb.ChangeLevel}', ");
|
queryBuilder.Append("values (@OwnerID, @Title, @ChangeLevel, @ReasonForChange, @ChangeDescription, ");
|
||||||
queryBuilder.Append($"'{pcrb.ReasonForChange}', '{pcrb.ChangeDescription}', ");
|
queryBuilder.Append("@IsITAR, @CurrentStep, @InsertTimeStamp, @LastUpdateDate, @Type)");
|
||||||
queryBuilder.Append($"{Convert.ToInt32(pcrb.IsITAR)}, {pcrb.CurrentStep}, ");
|
|
||||||
queryBuilder.Append($"'{pcrb.InsertTimeStamp.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
|
||||||
queryBuilder.Append($"'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')");
|
|
||||||
|
|
||||||
int rowsCreated = await _dalService.ExecuteAsync(queryBuilder.ToString());
|
int rowsCreated = await _dalService.ExecuteAsync(queryBuilder.ToString(), pcrb);
|
||||||
|
|
||||||
if (rowsCreated <= 0) throw new Exception("unable to insert new PCRB in the database");
|
if (rowsCreated <= 0) throw new Exception("unable to insert new PCRB in the database");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -198,18 +197,16 @@ public class PCRBService : IPCRBService {
|
|||||||
|
|
||||||
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
|
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
|
||||||
|
|
||||||
StringBuilder queryBuilder = new();
|
pcrb.LastUpdateDate = DateTime.Now;
|
||||||
queryBuilder.Append($"update CCChangeControl set OwnerID={pcrb.OwnerID}, ");
|
|
||||||
queryBuilder.Append($"Title='{pcrb.Title.Replace("'", "''")}', ChangeLevel='{pcrb.ChangeLevel}', ");
|
|
||||||
queryBuilder.Append($"CurrentStep={pcrb.CurrentStep}, ReasonForChange='{pcrb.ReasonForChange.Replace("'", "''")}', ");
|
|
||||||
queryBuilder.Append($"ChangeDescription='{pcrb.ChangeDescription.Replace("'", "''")}', ");
|
|
||||||
queryBuilder.Append($"IsITAR={Convert.ToInt32(pcrb.IsITAR)}, ");
|
|
||||||
queryBuilder.Append($"InsertTimeStamp='{pcrb.InsertTimeStamp.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
|
||||||
queryBuilder.Append($"ClosedDate='{pcrb.ClosedDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
|
||||||
queryBuilder.Append($"LastUpdateDate='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' ");
|
|
||||||
queryBuilder.Append($"where PlanNumber={pcrb.PlanNumber}");
|
|
||||||
|
|
||||||
int rowsAffected = await _dalService.ExecuteAsync(queryBuilder.ToString());
|
StringBuilder queryBuilder = new();
|
||||||
|
queryBuilder.Append("update CCChangeControl set OwnerID=@OwnerID, Title=@Title, ChangeLevel=@ChangeLevel, ");
|
||||||
|
queryBuilder.Append("Type=@Type, CurrentStep=@CurrentStep, ReasonForChange=@ReasonForChange, ");
|
||||||
|
queryBuilder.Append("ChangeDescription=@ChangeDescription, IsITAR=@IsITAR, ClosedDate=@ClosedDate, ");
|
||||||
|
queryBuilder.Append("LastUpdateDate=@LastUpdateDate ");
|
||||||
|
queryBuilder.Append($"where PlanNumber=@PlanNumber");
|
||||||
|
|
||||||
|
int rowsAffected = await _dalService.ExecuteAsync(queryBuilder.ToString(), pcrb);
|
||||||
|
|
||||||
if (rowsAffected <= 0) throw new Exception("unable to perform update in database");
|
if (rowsAffected <= 0) throw new Exception("unable to perform update in database");
|
||||||
|
|
||||||
|
@ -137,6 +137,20 @@
|
|||||||
<MudSelectItem Value="@("Other Site + Mesa - Class 2")" />
|
<MudSelectItem Value="@("Other Site + Mesa - Class 2")" />
|
||||||
<MudSelectItem Value="@("Mesa - Class 3")" />
|
<MudSelectItem Value="@("Mesa - Class 3")" />
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
<MudSelect T="string"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
Required
|
||||||
|
Clearable
|
||||||
|
AnchorOrigin="Origin.BottomCenter"
|
||||||
|
Disabled="@pcrbIsSubmitted"
|
||||||
|
@bind-Value="@pcrb.Type"
|
||||||
|
Text="@pcrb.Type"
|
||||||
|
Label="Change Type">
|
||||||
|
<MudSelectItem Value="@("Cost Savings")" />
|
||||||
|
<MudSelectItem Value="@("Process Efficiency")" />
|
||||||
|
<MudSelectItem Value="@("Process Improvement")" />
|
||||||
|
<MudSelectItem Value="@("Business Continuity")" />
|
||||||
|
</MudSelect>
|
||||||
<MudCheckBox Disabled="@pcrbIsSubmitted"
|
<MudCheckBox Disabled="@pcrbIsSubmitted"
|
||||||
Color="Color.Tertiary"
|
Color="Color.Tertiary"
|
||||||
@bind-Value=pcrb.IsITAR
|
@bind-Value=pcrb.IsITAR
|
||||||
@ -152,6 +166,11 @@
|
|||||||
Value="@DateTimeUtilities.GetDateAsStringMinDefault(pcrb.LastUpdateDate)"
|
Value="@DateTimeUtilities.GetDateAsStringMinDefault(pcrb.LastUpdateDate)"
|
||||||
Label="Last Update"
|
Label="Last Update"
|
||||||
Variant="Variant.Outlined" />
|
Variant="Variant.Outlined" />
|
||||||
|
<MudTextField Disabled="true"
|
||||||
|
T="string"
|
||||||
|
Value="@DateTimeUtilities.GetDateAsStringMaxDefault(pcrb.ClosedDate)"
|
||||||
|
Label="Complete Date"
|
||||||
|
Variant="Variant.Outlined" />
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
|
|
||||||
<MudPaper Outlined="true"
|
<MudPaper Outlined="true"
|
||||||
|
@ -23,4 +23,5 @@ public class PCRB {
|
|||||||
public DateTime InsertTimeStamp { get; set; } = DateTimeUtilities.MIN_DT;
|
public DateTime InsertTimeStamp { get; set; } = DateTimeUtilities.MIN_DT;
|
||||||
public DateTime LastUpdateDate { get; set; } = DateTimeUtilities.MIN_DT;
|
public DateTime LastUpdateDate { get; set; } = DateTimeUtilities.MIN_DT;
|
||||||
public DateTime ClosedDate { get; set; } = DateTimeUtilities.MAX_DT;
|
public DateTime ClosedDate { get; set; } = DateTimeUtilities.MAX_DT;
|
||||||
|
public string Type { get; set; } = "";
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user