-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed4050e
commit 694054d
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AutoMapper; | ||
using User; | ||
using UserService.Models; | ||
|
||
namespace UserService.Mappers; | ||
|
||
public class UserMapperProfile : Profile | ||
{ | ||
public UserMapperProfile() | ||
{ | ||
CreateMap<UserEntity, UserDto>(); | ||
CreateMap<UserDto, UserEntity>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto3"; | ||
import "google/protobuf/wrappers.proto"; | ||
import "google/protobuf/empty.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
package user; | ||
|
||
service User{ | ||
rpc SaveUser (UserDto) returns (google.protobuf.Empty); | ||
/* | ||
rpc GetUsers(google.protobuf.Empty) returns (stream UserDto); | ||
rpc GetUserByGovId (UserGovIdRequest) returns (stream UserDto); | ||
rpc GetUserByStudentId (UserStudentIdRequest) returns (stream UserDto); | ||
*/ | ||
} | ||
|
||
message UserDto { | ||
google.protobuf.StringValue name = 1; | ||
google.protobuf.StringValue surname = 2; | ||
google.protobuf.StringValue gov_id = 3; | ||
google.protobuf.StringValue student_id = 4; | ||
google.protobuf.StringValue email = 5; | ||
google.protobuf.StringValue password = 6; | ||
google.protobuf.StringValue role = 7; | ||
google.protobuf.StringValue phone = 8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using AutoMapper; | ||
using JetBrains.Annotations; | ||
using MongoDB.Bson; | ||
using User; | ||
using UserService.Mappers; | ||
using UserService.Models; | ||
using Xunit; | ||
|
||
namespace UserService.Tests.Unit; | ||
|
||
[TestSubject(typeof(UserMapperProfile))] | ||
public class UserMapperProfileTest | ||
{ | ||
private readonly IMapper _mapper; | ||
|
||
public UserMapperProfileTest() | ||
{ | ||
var config = new MapperConfiguration(cfg => cfg.AddProfile<UserMapperProfile>()); | ||
_mapper = config.CreateMapper(); | ||
} | ||
|
||
[Fact] | ||
public void Map_UserDto_To_UserEntity() | ||
{ | ||
var userDto = new UserDto | ||
{ | ||
Name = "John", | ||
Surname = "asas", | ||
Email = "dasd", | ||
GovId = "2e", | ||
Password = "as", | ||
Role = "xc", | ||
Phone = "z" | ||
}; | ||
|
||
var userEntity = _mapper.Map<UserEntity>(userDto); | ||
Assert.Equal(userEntity.Name, userDto.Name); | ||
Assert.Equal(userEntity.Surname, userDto.Surname); | ||
Assert.Equal(userEntity.Email, userDto.Email); | ||
Assert.Equal(userEntity.GovId, userDto.GovId); | ||
Assert.Equal(userEntity.Password, userDto.Password); | ||
Assert.Equal(userEntity.Role, userDto.Role); | ||
Assert.Equal(userEntity.Phone, userDto.Phone); | ||
} | ||
|
||
[Fact] | ||
public void Map_UserEntity_To_UserDto() | ||
{ | ||
var userEntity = new UserEntity | ||
{ | ||
Id = ObjectId.GenerateNewId(), | ||
Name = "John", | ||
Surname = "Comp", | ||
Email = "umb", | ||
GovId = "pippo", | ||
Password = "dsda", | ||
Role = "lol", | ||
Phone = "2psd" | ||
}; | ||
|
||
var userDto = _mapper.Map<UserDto>(userEntity); | ||
Assert.Equal(userEntity.Name, userDto.Name); | ||
Assert.Equal(userEntity.Surname, userDto.Surname); | ||
Assert.Equal(userEntity.Email, userDto.Email); | ||
Assert.Equal(userEntity.GovId, userDto.GovId); | ||
Assert.Equal(userEntity.Password, userDto.Password); | ||
Assert.Equal(userEntity.Role, userDto.Role); | ||
Assert.Equal(userEntity.Phone, userDto.Phone); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters