Skip to content

Commit f8e22a3

Browse files
authored
Merge pull request #203 from StoyanShopov/CompanyIntegrationTests
Company integration tests
2 parents c52e4cb + dab1333 commit f8e22a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+22661
-282
lines changed

Data/UpSkill.Data.Models/Course.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Course()
2020

2121
public int CategoryId { get; set; }
2222

23-
public decimal Price { get; set; }
23+
public decimal Price { get; set; }
2424

2525
public Category Category { get; set; }
2626

Data/UpSkill.Data.Models/Message.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ public class Message
1010

1111
public string Time { get; set; }
1212

13-
//public string GroupChatId { get; init; }
14-
13+
// public string GroupChatId { get; init; }
1514
public string OwnerName { get; init; }
1615
}
1716
}

Services/UpSkill.Services.Data/Category/CategoriesService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
using Microsoft.EntityFrameworkCore;
66

7-
using Contracts.Category;
87
using UpSkill.Data.Common.Repositories;
98
using UpSkill.Data.Models;
9+
using UpSkill.Services.Data.Contracts.Category;
1010

1111
public class CategoriesService : ICategoriesService
1212
{

Services/UpSkill.Services.Data/Coach/CoachesService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public async Task<Result> CreateAsync(CreateCoachRequestModel model)
4848
{
4949
FirstName = model.FirstName,
5050
LastName = model.LastName,
51-
Field=model.Field,
52-
Price=model.Price,
51+
Field = model.Field,
52+
Price = model.Price,
5353
FileId = file,
5454
CalendlyUrl = model.CalendlyUrl,
5555
};

Services/UpSkill.Services.Data/Course/CoursesService.cs

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ public async Task<BaseDeletableModel<int>> GetDbModelByIdAsync(int id)
187187
.Where(x => x.Id == id)
188188
.FirstOrDefaultAsync();
189189

190-
191190
public async Task<ICollection<UserInCourse>> GetAllUsersInCourse(int id) => await this.usersInCourses
192191
.AllAsNoTracking()
193192
.Where(uc => uc.CourseId == id)

Services/UpSkill.Services/Hubs/ChatHub.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
using System.Threading.Tasks;
77

88
using Microsoft.AspNetCore.SignalR;
9+
910
using UpSkill.Data.Common.Repositories;
1011
using UpSkill.Data.Models;
1112
using UpSkill.Web.ViewModels.Chat;
1213

1314
public class ChatHub : Hub
1415
{
16+
private const string Room = "devs";
1517
private readonly string bot;
16-
private const string room = "devs";
17-
1818

1919
private readonly IRepository<Message> messages;
2020

@@ -32,13 +32,13 @@ public ChatHub(
3232
public async Task JoinRoom(UserConnection userConnection)
3333
{
3434
await this.Groups
35-
.AddToGroupAsync(this.Context.ConnectionId, room);
35+
.AddToGroupAsync(this.Context.ConnectionId, Room);
3636

3737
this.connections[this.Context.ConnectionId] = userConnection;
3838

3939
await this.Clients
40-
.Group(room)
41-
.SendAsync("ReceiveMessage", this.bot, $"{userConnection.Name} has joined the {room} room!", DateTime.UtcNow.ToString(), userConnection.Name);
40+
.Group(Room)
41+
.SendAsync("ReceiveMessage", this.bot, $"{userConnection.Name} has joined the {Room} room!", DateTime.UtcNow.ToString(), userConnection.Name);
4242
}
4343

4444
public async Task Send(string message, string user)
@@ -56,7 +56,7 @@ public async Task Send(string message, string user)
5656
await this.messages.AddAsync(messageDb);
5757
await this.messages.SaveChangesAsync();
5858

59-
await this.Clients.Group(room)
59+
await this.Clients.Group(Room)
6060
.SendAsync("ReceiveMessage", userConnection.Name, message, currentTime.ToString("H:mm"), user);
6161
}
6262
}
@@ -83,12 +83,11 @@ public override async Task OnDisconnectedAsync(Exception exception)
8383
{
8484
this.connections.Remove(this.Context.ConnectionId);
8585

86-
await this.Clients.Group(room)
86+
await this.Clients.Group(Room)
8787
.SendAsync("ReceiveMessage", this.bot, $"{userConnection.Name} has left!", DateTime.UtcNow.ToString(), this.bot);
8888
}
8989

9090
await base.OnDisconnectedAsync(exception);
9191
}
92-
9392
}
9493
}

Services/UpSkill.Services/Identity/IdentityService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010

1111
using Microsoft.AspNetCore.Identity;
12-
using Microsoft.EntityFrameworkCore;
12+
using Microsoft.EntityFrameworkCore;
1313
using Microsoft.Extensions.Options;
1414
using Microsoft.IdentityModel.Tokens;
1515

Tests/UpSkill.Services.Data.Tests/Common/TestWithData.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
namespace UpSkill.Services.Data.Tests.Common
22
{
3-
using System.Threading.Tasks;
4-
53
using UpSkill.Data;
64
using UpSkill.Data.Models;
75
using UpSkill.Services.Data.Tests.Fakes;
86

97
public abstract class TestWithData
108
{
11-
protected async Task InitializeDatabase(string databaseName)
9+
protected void InitializeDatabase(string databaseName)
1210
{
1311
var fakeDatabase = new FakeUpSkillDbContext(databaseName);
1412

15-
await AddFakeData(fakeDatabase);
13+
AddFakeData(fakeDatabase);
1614

1715
this.Database = fakeDatabase.Data;
1816
}
1917

2018
protected ApplicationDbContext Database { get; private set; }
2119

22-
private static async Task AddFakeData(FakeUpSkillDbContext dbContext)
23-
=> await dbContext.AddFakeDataAsync(
20+
private static void AddFakeData(FakeUpSkillDbContext dbContext)
21+
=> dbContext.AddFakeData(
2422
new Company()
2523
{
2624
Id = 1,
2725
Name = "TestCompany",
2826
},
27+
new Coach()
28+
{
29+
Id = 1,
30+
FirstName = "TestFirstName",
31+
LastName = "TestLastName",
32+
Field = "1",
33+
Price = 100,
34+
},
2935
new ApplicationUser()
3036
{
3137
Id = "1",

Tests/UpSkill.Services.Data.Tests/Fakes/FakeUpSkillDbContext.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace UpSkill.Services.Data.Tests.Fakes
22
{
3-
using System.Threading.Tasks;
4-
53
using Microsoft.EntityFrameworkCore;
64

75
using UpSkill.Data;
@@ -19,10 +17,10 @@ public FakeUpSkillDbContext(string name)
1917

2018
public ApplicationDbContext Data { get; }
2119

22-
public async Task AddFakeDataAsync(params object[] data)
20+
public void AddFakeData(params object[] data)
2321
{
2422
this.Data.AddRange(data);
25-
await this.Data.SaveChangesAsync();
23+
this.Data.SaveChanges();
2624
}
2725
}
2826
}

Tests/UpSkill.Services.Data.Tests/Services/CoursesServicesTest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task DeleteAsyncShouldDeleteCourse()
5353
const int Id = 1;
5454
const string DatabaseName = "DeleteCourse";
5555

56-
await this.InitializeDatabase(DatabaseName);
56+
this.InitializeDatabase(DatabaseName);
5757

5858
var repository = new Mock<IDeletableEntityRepository<Course>>();
5959

@@ -79,7 +79,7 @@ public async Task EditAsyncShouldEditCourse()
7979

8080
const string DatabaseName = "EditCourse";
8181

82-
await this.InitializeDatabase(DatabaseName);
82+
this.InitializeDatabase(DatabaseName);
8383

8484
var repository = new Mock<IDeletableEntityRepository<Course>>();
8585

@@ -112,7 +112,7 @@ public async Task GetByIdAsyncShouldGetCourseById()
112112

113113
const int Id = 1;
114114

115-
await this.InitializeDatabase(DatabaseName);
115+
this.InitializeDatabase(DatabaseName);
116116

117117
var repository = new Mock<IDeletableEntityRepository<Course>>();
118118

@@ -130,7 +130,7 @@ public async Task GetAllAsyncShouldGetAllCourses()
130130
const string DatabaseName = "GetAllCourses";
131131
const int DatabaseRecordsCount = 2;
132132

133-
await this.InitializeDatabase(DatabaseName);
133+
this.InitializeDatabase(DatabaseName);
134134

135135
var repository = new Mock<IDeletableEntityRepository<Course>>();
136136

0 commit comments

Comments
 (0)