Skip to content

Commit 9d932b4

Browse files
author
mostafa fbh
committed
it was refer to reza for to resolved it
1 parent 501b9ee commit 9d932b4

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

Source/BSN.Commons.AutoMapper/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@ To use this package, you need to first install it in your client service. You ca
1010
- Install-Package BSN.Commons.AutoMapper
1111

1212
Once you've installed the package, you need to add the following code to your Startup.cs file:
13-
- services.AddAutoMapper(config => config.AddProfile<AppServiceViewMapperProfile>());
13+
- services.AddAutoMapper(config => config.AddProfile<AppServiceViewMapperProfile>());
14+
15+
1.AppServiceViewMapperProfile: This profile maps objects related to App Services, including:
16+
- AppService to AppServiceViewModel
17+
- AppServiceDto to AppServiceViewModel
18+
- AppServiceViewModel to AppService
19+
- AppServiceViewModel to AppServiceDto
20+
21+
2.UserViewMapperProfile: This profile maps objects related to Users, including:
22+
- User to UserViewModel
23+
- UserDto to UserViewModel
24+
- UserViewModel to User
25+
- UserViewModel to UserDto
26+
27+
3.RoleViewMapperProfile: This profile maps objects related to Roles, including:
28+
- Role to RoleViewModel
29+
- RoleDto to RoleViewModel
30+
- RoleViewModel to Role
31+
- RoleViewModel to RoleDto
32+
33+
These profiles cover some of the most common use cases for mapping objects in enterprise applications. However, if you need to add support for additional complex types, you can create your own profile and add it to the configuration in the Startup.cs file.

Test/BSN.Commons.AutoMapper.Tests/CommonMapperProfileTests .cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using AutoMapper;
2-
using BSN.Commons.AutoMapper;
32
using BSN.Commons.Responses;
43

5-
namespace BSN.Commons.Tests
4+
namespace BSN.Commons.AutoMapper.Tests
65
{
76
[TestFixture]
87
public class CommonMapperProfileTests
@@ -47,5 +46,48 @@ public void GenericIEnumerableToCollectionViewModelConverter_ConvertsCorrectly()
4746
Assert.IsNotNull(result);
4847
Assert.AreEqual(items.Count, result.Items.Count());
4948
}
49+
50+
[Test]
51+
public void CustomProfileConverter_ConvertsCorrectly()
52+
{
53+
// Arrange
54+
var customProfile = new CustomMapperProfile();
55+
var profile = new CommonMapperProfile();
56+
var configuration = new MapperConfiguration(cfg =>
57+
{
58+
cfg.AddProfile(profile);
59+
cfg.AddProfile(customProfile);
60+
});
61+
var mapper = new Mapper(configuration);
62+
var customEntity = new CustomEntity { Id = 1, Name = "Custom Entity" };
63+
64+
// Act
65+
var result = mapper.Map<CustomViewModel>(customEntity);
66+
67+
// Assert
68+
Assert.IsNotNull(result);
69+
Assert.AreEqual(customEntity.Id, result.Id);
70+
Assert.AreEqual(customEntity.Name, result.Name);
71+
}
72+
73+
public class CustomMapperProfile : Profile
74+
{
75+
public CustomMapperProfile()
76+
{
77+
CreateMap<CustomEntity, CustomViewModel>();
78+
}
79+
}
80+
81+
public class CustomEntity
82+
{
83+
public int Id { get; set; }
84+
public string Name { get; set; }
85+
}
86+
87+
public class CustomViewModel
88+
{
89+
public int Id { get; set; }
90+
public string Name { get; set; }
91+
}
5092
}
5193
}

0 commit comments

Comments
 (0)