допилы тестов

This commit is contained in:
2025-04-09 15:46:21 +04:00
parent bd0c52b9f1
commit 5e249e488c
4 changed files with 16 additions and 14 deletions

View File

@@ -110,5 +110,5 @@ internal class RequestStorageContract : IRequestStorageContract
}
}
private Request? GetRequestById(string id) => _dbContext.Requests.Include(x => x.Worker).Include(x => x.InstallationRequests).FirstOrDefault(x => x.Id == id);
private Request? GetRequestById(string id) => _dbContext.Requests.Include(x => x.Worker).Include(x => x.InstallationRequests).ThenInclude(x => x.Software).FirstOrDefault(x => x.Id == id);
}

View File

@@ -109,9 +109,11 @@ internal static class SmallSoftwareDbContextExtensions
{
foreach (var elem in softwares)
{
var software = dbContext.Softwares.Find(elem.Item1);
Request.InstallationRequests.Add(new InstallationRequest
{
SoftwareId = elem.Item1,
Software = software!,
RequestId = Request.Id,
Count = elem.Item2,
Price = elem.Item3

View File

@@ -179,7 +179,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
public async Task GetElement_ById_WhenHaveRecord_ShouldSuccess_Test()
{
//Arrange
var request = SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "", 10, true, softwares: [(_softwareId, 10, 1.1)]);
var request = SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test", sum: 10, true, softwares: [(_softwareId, 10, 1.1)]);
//Act
var response = await HttpClient.GetAsync($"/api/requests/getrecord/{request.Id}");
//Assert
@@ -233,13 +233,13 @@ internal class RequestControllerTests : BaseWebApiControllerTest
var requestModelWithCountIncorrect = new RequestBindingModel {Id = requestId, WorkerId = _workerId , Softwares = [new InstallationRequestBindingModel { RequestId = requestId, SoftwareId = _softwareId, Count = -10, Price = 1.1 }] };
var requestModelWithPriceIncorrect = new RequestBindingModel {Id = requestId, WorkerId = _workerId, Softwares = [new InstallationRequestBindingModel { RequestId = requestId, SoftwareId = _softwareId, Count = 10, Price = -1.1 }] };
//Act
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithIdIncorrect));
var responseWithWorkerIdIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithWorkerIdIncorrect));
var responseWithBuyerIdIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithBuyerIdIncorrect));
var responseWithSoftwaresIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithSoftwaresIncorrect));
var responseWithSoftwareIdIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithSoftwareIdIncorrect));
var responseWithCountIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithCountIncorrect));
var responseWithPriceIncorrect = await HttpClient.PostAsync($"/api/requests/request", MakeContent(requestModelWithPriceIncorrect));
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithIdIncorrect));
var responseWithWorkerIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithWorkerIdIncorrect));
var responseWithBuyerIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithBuyerIdIncorrect));
var responseWithSoftwaresIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithSoftwaresIncorrect));
var responseWithSoftwareIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithSoftwareIdIncorrect));
var responseWithCountIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithCountIncorrect));
var responseWithPriceIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(requestModelWithPriceIncorrect));
//Assert
Assert.Multiple(() =>
{
@@ -257,8 +257,9 @@ internal class RequestControllerTests : BaseWebApiControllerTest
public async Task Post_WhenSendEmptyData_ShouldBadRequest_Test()
{
//Act
var response = await HttpClient.PostAsync($"/api/requests/request", MakeContent(string.Empty));
var response = await HttpClient.PostAsync($"/api/posts", MakeContent(string.Empty));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
}
@@ -266,7 +267,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
public async Task Post_WhenSendWrongFormatData_ShouldBadRequest_Test()
{
//Act
var response = await HttpClient.PostAsync($"/api/requests/request", MakeContent(new { Data = "test", Position = 10 }));
var response = await HttpClient.PostAsync($"/api/posts", MakeContent(new { Data = "test", Position = 10 }));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
}
@@ -336,7 +337,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
{
Assert.Multiple(() =>
{
Assert.That(actual.Softwares[i].SoftwareName, Is.EqualTo(expected.InstallationRequests[i].Software!.SoftwareName));
Assert.That(actual.Softwares[i].SoftwareId, Is.EqualTo(expected.InstallationRequests[i].SoftwareId));
Assert.That(actual.Softwares[i].Count, Is.EqualTo(expected.InstallationRequests[i].Count));
});
}

View File

@@ -431,8 +431,7 @@ Is.EqualTo(HttpStatusCode.NotFound));
public async Task Post_WhenSendEmptyData_ShouldBadRequest_Test()
{
//Act
var response = await HttpClient.PostAsync($"/api/softwares/register",
MakeContent(string.Empty));
var response = await HttpClient.PostAsync($"/api/softwares/register",MakeContent(string.Empty));
//Assert
Assert.That(response.StatusCode,
Is.EqualTo(HttpStatusCode.BadRequest));