Skip to content

Commit

Permalink
Fix Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValDekh committed Apr 24, 2024
1 parent f7079a9 commit b60e145
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 48 deletions.
1 change: 0 additions & 1 deletion Streetcode/Streetcode.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
var app = builder.Build();

app.UseForwardedHeaders();
await app.SeedDataAsync();

var supportedCulture = new[]
{
Expand Down
3 changes: 1 addition & 2 deletions Streetcode/Streetcode.WebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"launchBrowser": false,
"environmentVariables": {
"STREETCODE_ENVIRONMENT": "Local",
"ASPNETCORE_ENVIRONMENT": "Local",
"ADMIN_PASSWORD": "passwordPP_@#!123345"
"ASPNETCORE_ENVIRONMENT": "Local"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5000;https://localhost:5001"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ConnectionStrings": {
//"DefaultConnection": "Server=localhost;Database=Streetcode_IntegrationTests_Db;User Id=sa;Password=sdlLKMCD234!@#lkcmds;MultipleActiveResultSets=True;TrustServerCertificate=true"
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDbtest;Integrated Security=True"
"DefaultConnection": "Server=localhost;Database=Streetcode_IntegrationTests_Db;User Id=sa;Password=sdlLKMCD234!@#lkcmds;MultipleActiveResultSets=True;TrustServerCertificate=true"

},
"Blob": {
Expand Down
3 changes: 1 addition & 2 deletions Streetcode/Streetcode.WebApi/appsettings.Local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ConnectionStrings": {
//"DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true"
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDb;Integrated Security=True"
"DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true"
},
"CORS": {
"AllowedOrigins": [ "http://localhost:3000" ],
Expand Down
3 changes: 1 addition & 2 deletions Streetcode/Streetcode.WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ConnectionStrings": {
// "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true"
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDbtest;Integrated Security=True"
"DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true"
},
"EmailConfiguration": {
"From": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class UniqueNumberGenerator
{
private static object _lock = new object();

public static int Generate()
public static int GenerateInt()
{
lock (_lock)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CoordinateControllerTests : BaseControllerTests<CoordinateClient>,
public CoordinateControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Coordinate")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
uniqueId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SubtitleControllerTests : BaseControllerTests<SubtitleClient>, ICla
public SubtitleControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "api/Subtitle")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testSubtitle = SubtitleExtracter.Extract(uniqueId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TagControllerTests : BaseControllerTests<TagClient>, IClassFixture<
public TagControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Tag")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testTag = TagExtracter.Extract(uniqueId);
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Streetcode.DAL.Entities.Streetcode;
using Streetcode.XIntegrationTest.Base;
using Streetcode.XIntegrationTest.Base;
using Streetcode.XIntegrationTest.ControllerTests.BaseController;
using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode;
using Streetcode.XIntegrationTest.ControllerTests.Utils;
using Xunit;
using Streetcode.DAL.Entities.Jobs;
Expand All @@ -21,7 +19,7 @@ public class JobCreateControllerTests : BaseAuthorizationControllerTests<JobClie
public JobCreateControllerTests(CustomWebApplicationFactory<Program> factory, TokenStorage tokenStorage)
: base(factory, "/api/Job", tokenStorage)
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testJob = JobExtracter
.Extract(uniqueId);
}
Expand All @@ -36,7 +34,7 @@ public override void Dispose()
public async Task Create_ReturnsSuccessStatusCode()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
var jobCreateDTO = ExtractCreateTestJob.JobCreateForTest;

// Act
var response = await this.client.CreateAsync(jobCreateDTO, this._tokenStorage.AdminToken);
Expand All @@ -50,7 +48,7 @@ public async Task Create_ReturnsSuccessStatusCode()
public async Task Create_TokenNotPassed_ReturnsUnauthorized()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
var jobCreateDTO = ExtractCreateTestJob.JobCreateForTest;

// Act
var response = await this.client.CreateAsync(jobCreateDTO);
Expand All @@ -64,7 +62,7 @@ public async Task Create_TokenNotPassed_ReturnsUnauthorized()
public async Task Create_NotAdminTokenPassed_ReturnsForbidden()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
var jobCreateDTO = ExtractCreateTestJob.JobCreateForTest;

// Act
var response = await this.client.CreateAsync(jobCreateDTO, this._tokenStorage.UserToken);
Expand All @@ -78,7 +76,7 @@ public async Task Create_NotAdminTokenPassed_ReturnsForbidden()
public async Task Create_CreatesNewJob()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
var jobCreateDTO = ExtractCreateTestJob.JobCreateForTest;

// Act
var response = await this.client.CreateAsync(jobCreateDTO, this._tokenStorage.AdminToken);
Expand All @@ -93,7 +91,7 @@ public async Task Create_CreatesNewJob()
public async Task Create_WithInvalidData_ReturnsBadRequest()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
var jobCreateDTO = ExtractCreateTestJob.JobCreateForTest;
jobCreateDTO.Title = null; // Invalid data

// Act
Expand All @@ -102,20 +100,5 @@ public async Task Create_WithInvalidData_ReturnsBadRequest()
// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact]
[ExtractCreateTestJob]
public async Task Create_WithExistingJob_ReturnsConflict()
{
// Arrange
var jobCreateDTO = ExtractCreateTestJob.JobForTest;
jobCreateDTO.Id = this._testJob.Id;

// Act
var response = await this.client.CreateAsync(jobCreateDTO, this._tokenStorage.AdminToken);

// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AudioControllerTests : BaseControllerTests<AudioClient>, IClassFixt
public AudioControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Audio")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testAudio = AudioExtracter.Extract(uniqueId);
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ArtControllerTests : BaseControllerTests<ArtClient>, IClassFixture<
public ArtControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Art")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testArt = ArtExtracter.Extract(uniqueId);
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ImageControllerTests : BaseControllerTests<ImageClient>, IClassFixt
public ImageControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Image")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testImage = ImageExtracter.Extract(uniqueId);
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class StreetcodeArtControllerTests : BaseControllerTests<StreetcodeArtCli
public StreetcodeArtControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/StreetcodeArt")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testArt = ArtExtracter.Extract(uniqueId);
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class VideoControllerTests : BaseControllerTests<VideoClient>, IClassFixt
public VideoControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Video")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testVideo = VideoExtracter.Extract(uniqueId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class NewsGetAllControllerTests : BaseControllerTests<NewsClient>, IClass
public NewsGetAllControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/News")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testNews = NewsExtracter.Extract(uniqueId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PartnersControllerTests : BaseControllerTests<PartnersClient>, ICla
public PartnersControllerTests(CustomWebApplicationFactory<Program> factory)
: base(factory, "/api/Partners")
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
this._testStreetcodeContent = StreetcodeContentExtracter
.Extract(
uniqueId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class StreetcodeCreateControllerTests : BaseAuthorizationControllerTests<
public StreetcodeCreateControllerTests(CustomWebApplicationFactory<Program> factory, TokenStorage tokenStorage)
: base(factory, "/api/Streetcode", tokenStorage)
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
_testStreetcodeContent = StreetcodeContentExtracter
.Extract(
uniqueId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class StreetcodeUpdateControllerTests :
public StreetcodeUpdateControllerTests(CustomWebApplicationFactory<Program> factory, TokenStorage tokenStorage)
: base(factory, "/api/Streetcode", tokenStorage)
{
int uniqueId = UniqueNumberGenerator.Generate();
int uniqueId = UniqueNumberGenerator.GenerateInt();
_testStreetcodeUpdateDTO = StreetcodeUpdateDTOExtracter.Extract(
uniqueId,
uniqueId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAt
public class ExtractCreateTestJob: BeforeAfterTestAttribute
{
public static JobDto JobForTest;
public static JobCreateDto JobCreateForTest;

public override void Before(MethodInfo methodUnderTest)
{
Expand All @@ -19,6 +20,14 @@ public override void Before(MethodInfo methodUnderTest)
Description = "Test",
Salary = "100",
};

JobCreateForTest = new JobCreateDto
{
Title = "Test",
Status = false,
Description = "Test",
Salary = "100",
};
}

public override void After(MethodInfo methodUnderTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public JobClient(HttpClient client, string secondPartUrl = "")
{
}

public async Task<RestResponse> CreateAsync(JobDto createJobDTO, string authToken = "")
public async Task<RestResponse> CreateAsync(JobCreateDto createJobDTO, string authToken = "")
{
return await this.SendCommand("/Create", Method.Post, createJobDTO, authToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ public static DAL.Entities.Jobs.Job Extract(int jobId)
DAL.Entities.Jobs.Job testJob = TestDataProvider.GetTestData<DAL.Entities.Jobs.Job>();

testJob.Id = jobId;
var extracter = BaseExtracter.Extract<DAL.Entities.Jobs.Job>(testJob, job => job.Id == jobId);
return extracter;
}

public static DAL.Entities.Jobs.Job ExtractByTitle(string title)
{
DAL.Entities.Jobs.Job testJob = TestDataProvider.GetTestData<DAL.Entities.Jobs.Job>();

return BaseExtracter.Extract<DAL.Entities.Jobs.Job>(testJob, job => job.Id == jobId);
testJob.Title = title;
var extracter = BaseExtracter.Extract<DAL.Entities.Jobs.Job>(testJob, job => job.Title.Equals(title));
return extracter;
}

public static void Remove(DAL.Entities.Jobs.Job entity)
Expand Down

0 comments on commit b60e145

Please sign in to comment.