diff --git a/API/API.sln b/API/API.sln index 10a4a07..fe73a47 100644 --- a/API/API.sln +++ b/API/API.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API.csproj", "{32068D16-7CA1-4F9F-95E1-9C71FC411182}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "..\Tests\Tests.csproj", "{6ECC12EE-9060-45C9-8ABA-52A7105E2204}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "..\Tests\IntegrationTests.csproj", "{6ECC12EE-9060-45C9-8ABA-52A7105E2204}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Tests/IntegrationTests/AccountsControllerTests.cs b/Tests/AccountsControllerTests.cs similarity index 95% rename from Tests/IntegrationTests/AccountsControllerTests.cs rename to Tests/AccountsControllerTests.cs index 66e877a..ffb860f 100644 --- a/Tests/IntegrationTests/AccountsControllerTests.cs +++ b/Tests/AccountsControllerTests.cs @@ -12,7 +12,7 @@ using System.Net.Http.Headers; using System.Text; -namespace Tests.IntegrationTests +namespace IntegrationTests { public class AccountsControllerTests(WebApplicationFactory factory) : BaseControllerTest(factory) { @@ -28,7 +28,7 @@ public async Task UserShouldRegisterSuccessfully() Gender = "Male", DateOfBirth = DateTime.Now.AddYears(-20), }; - _context.Users.Where(x=>x.UserName=="Test").ExecuteDelete(); + _context.Users.Where(x => x.UserName == "Test").ExecuteDelete(); var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); @@ -98,12 +98,12 @@ public async Task UserShouldRetriveListOfUsers() { await InitializeUsers(); var scope = _factory.Services.CreateScope(); - + var userManager = scope.ServiceProvider.GetRequiredService>(); var user = await userManager.FindByNameAsync("TestList"); var token = GenerateJwtToken(user.Id.ToString()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - + var response = await _client.GetAsync("/Accounts/List"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -112,7 +112,7 @@ public async Task UserShouldRetriveListOfUsers() var accountsList = JsonConvert.DeserializeObject>(stringResponse); Assert.NotNull(accountsList); - Assert.False(accountsList.Items.Select(x=>x.UserName).Contains("TestList")); + Assert.False(accountsList.Items.Select(x => x.UserName).Contains("TestList")); } private async Task InitializeUsers() diff --git a/Tests/IntegrationTests/BaseControllerTest.cs b/Tests/BaseControllerTest.cs similarity index 98% rename from Tests/IntegrationTests/BaseControllerTest.cs rename to Tests/BaseControllerTest.cs index 64afbd0..d961ca6 100644 --- a/Tests/IntegrationTests/BaseControllerTest.cs +++ b/Tests/BaseControllerTest.cs @@ -10,7 +10,7 @@ using System.Security.Claims; using System.Text; -namespace Tests.IntegrationTests +namespace IntegrationTests { public abstract class BaseControllerTest : IClassFixture> { diff --git a/Tests/IntegrationTests/BodyControllerTests.cs b/Tests/BodyControllerTests.cs similarity index 94% rename from Tests/IntegrationTests/BodyControllerTests.cs rename to Tests/BodyControllerTests.cs index efbdfbf..f363359 100644 --- a/Tests/IntegrationTests/BodyControllerTests.cs +++ b/Tests/BodyControllerTests.cs @@ -11,7 +11,7 @@ using System.Net.Http.Headers; using System.Text; -namespace Tests.IntegrationTests +namespace IntegrationTests { public class BodyControllerTests(WebApplicationFactory factory) : BaseControllerTest(factory) { @@ -20,9 +20,9 @@ public class BodyControllerTests(WebApplicationFactory factory) : BaseC public async Task UserShouldSetHeightProperly() { await InitializeUsers(); - var user = _context.Users.Include(x=>x.BodyWeight).First(x=>x.UserName== "TestBodyWeight"); + var user = _context.Users.Include(x => x.BodyWeight).First(x => x.UserName == "TestBodyWeight"); var query = new SetHeightCommand { Height = 110 }; - var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); var token = GenerateJwtToken(user.Id.ToString()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); @@ -52,7 +52,7 @@ public async Task UserShouldAddBodyWeightWithOnlyWeight() var userAfterChanges = GetNewContext() .Users .Include(x => x.BodyWeight) - .ThenInclude(x=>x.WeightRecords) + .ThenInclude(x => x.WeightRecords) .First(x => x.UserName == "TestBodyWeight"); var weightRecord = userAfterChanges.BodyWeight.WeightRecords.Last(); @@ -64,7 +64,8 @@ public async Task UserShouldAddBodyWeightWithFullData() { await InitializeUsers(); var user = _context.Users.Include(x => x.BodyWeight).First(x => x.UserName == "TestBodyWeight"); - var query = new AddBodyWeightRecordCommand { + var query = new AddBodyWeightRecordCommand + { Weight = 110, Neck = 10, Chest = 10, @@ -74,7 +75,7 @@ public async Task UserShouldAddBodyWeightWithFullData() Hip = 10, Thigh = 10, Calf = 10 - }; + }; var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); var token = GenerateJwtToken(user.Id.ToString()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); diff --git a/Tests/Tests.csproj b/Tests/IntegrationTests.csproj similarity index 90% rename from Tests/Tests.csproj rename to Tests/IntegrationTests.csproj index 4ca6ddc..5de1246 100644 --- a/Tests/Tests.csproj +++ b/Tests/IntegrationTests.csproj @@ -9,6 +9,12 @@ true + + + + + + @@ -25,10 +31,6 @@ - - - - diff --git a/Tests/IntegrationTests/PlansControllerTests.cs b/Tests/PlansControllerTests.cs similarity index 92% rename from Tests/IntegrationTests/PlansControllerTests.cs rename to Tests/PlansControllerTests.cs index c4e9d6e..5b15bf2 100644 --- a/Tests/IntegrationTests/PlansControllerTests.cs +++ b/Tests/PlansControllerTests.cs @@ -15,7 +15,7 @@ using System.Text; using static API.Handlers.Plans.AddRecord.AddRecordsCommand; -namespace Tests.IntegrationTests +namespace IntegrationTests { public class PlansControllerTests(WebApplicationFactory factory) : BaseControllerTest(factory) { @@ -58,7 +58,7 @@ public async Task UserShouldPublishPlan() } } }; - _context.FitnessPlanTemplates.Where(x=>x.Name==query.Name).ExecuteDelete(); + _context.FitnessPlanTemplates.Where(x => x.Name == query.Name).ExecuteDelete(); var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/Plans/Publish", content); @@ -70,17 +70,17 @@ public async Task UserShouldPublishPlan() public async Task UserShouldAddPlan() { await InitializePlans(); - var user = _context.Users.First(x=>x.UserName== "TestUserPlan"); + var user = _context.Users.First(x => x.UserName == "TestUserPlan"); var token = GenerateJwtToken(user.Id.ToString()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - var planId = _context.FitnessPlanTemplates.Where(x=>x.AuthorId==user.Id).First().Id; + var planId = _context.FitnessPlanTemplates.Where(x => x.AuthorId == user.Id).First().Id; var response = await _client.GetAsync($"/Plans/Add/{planId}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - var userAfterChanges = GetNewContext().Users.Include(x=>x.FitnessPlans).FirstOrDefault(x=>x.Id == user.Id); - Assert.Equal(2,userAfterChanges.FitnessPlans.Count); + var userAfterChanges = GetNewContext().Users.Include(x => x.FitnessPlans).FirstOrDefault(x => x.Id == user.Id); + Assert.Equal(2, userAfterChanges.FitnessPlans.Count); } [Fact] @@ -88,8 +88,8 @@ public async Task UserShouldAddRecord() { await InitializePlans(); var user = _context.Users - .Include(x=>x.FitnessPlans) - .ThenInclude(x=>x.Exercises) + .Include(x => x.FitnessPlans) + .ThenInclude(x => x.Exercises) .First(x => x.UserName == "TestUserPlan"); var token = GenerateJwtToken(user.Id.ToString()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); @@ -107,7 +107,7 @@ public async Task UserShouldAddRecord() }; var content = new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"); - var response = await _client.PostAsync($"/Plans/Add",content); + var response = await _client.PostAsync($"/Plans/Add", content); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } @@ -145,7 +145,7 @@ public async Task UserShouldGetSinglePlan() Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - + [Fact] public async Task UserShouldArchivePlan() { @@ -157,11 +157,11 @@ public async Task UserShouldArchivePlan() _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var plan = user.FitnessPlans.First(); - var response = await _client.PatchAsync($"/Plans/archive/{plan.Id}",null); + var response = await _client.PatchAsync($"/Plans/archive/{plan.Id}", null); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - var planAfterChanges = GetNewContext().FitnessPlans.First(x=>x.Id==plan.Id); + var planAfterChanges = GetNewContext().FitnessPlans.First(x => x.Id == plan.Id); Assert.NotEqual(plan.Archived, planAfterChanges.Archived); } @@ -234,7 +234,7 @@ private async Task InitializePlans() new() { Name = "Test exercise", - Records = new List + Records = new List { new() { @@ -247,9 +247,9 @@ private async Task InitializePlans() } }; var user1 = _context.Users - .Include(x=>x.FitnessPlansTemplates) - .Include(x=>x.FitnessPlans) - .First(x=>x.UserName=="TestUserPlan"); + .Include(x => x.FitnessPlansTemplates) + .Include(x => x.FitnessPlans) + .First(x => x.UserName == "TestUserPlan"); user1.FitnessPlansTemplates.Add(planTemplate); user1.FitnessPlans.Add(plan); var planTemplate2 = new FitnessPlanTemplate