1+ using FluentAssertions ;
2+ using Microsoft . CodeAnalysis ;
3+ using Moq ;
4+ using Xunit ;
5+
6+ namespace ProjectR . Tests . Mapping ;
7+
8+ public class LegacyMappingClassesTests
9+ {
10+ [ Fact ]
11+ public void MappingInstruction_IsAbstractBaseClass ( )
12+ {
13+ // Assert
14+ typeof ( MappingInstruction ) . Should ( ) . BeAbstract ( ) ;
15+ }
16+
17+ [ Fact ]
18+ public void NestedObjectMapperMapping_InheritsFromMappingInstruction ( )
19+ {
20+ // Assert
21+ typeof ( NestedObjectMapperMapping ) . Should ( ) . BeDerivedFrom < MappingInstruction > ( ) ;
22+ }
23+
24+ [ Fact ]
25+ public void NestedObjectMapperMapping_Properties_CanBeSetAndRetrieved ( )
26+ {
27+ // Arrange
28+ var mockSourceProperty = new Mock < IPropertySymbol > ( ) ;
29+ var mockDestinationProperty = new Mock < IPropertySymbol > ( ) ;
30+ var mockMapperType = new Mock < INamedTypeSymbol > ( ) ;
31+ var mapping = new NestedObjectMapperMapping ( ) ;
32+
33+ // Act
34+ mapping . SourceProperty = mockSourceProperty . Object ;
35+ mapping . DestinationProperty = mockDestinationProperty . Object ;
36+ mapping . MapperType = mockMapperType . Object ;
37+
38+ // Assert
39+ mapping . SourceProperty . Should ( ) . Be ( mockSourceProperty . Object ) ;
40+ mapping . DestinationProperty . Should ( ) . Be ( mockDestinationProperty . Object ) ;
41+ mapping . MapperType . Should ( ) . Be ( mockMapperType . Object ) ;
42+ }
43+
44+ [ Fact ]
45+ public void ParameterMapping_Properties_CanBeSetAndRetrieved ( )
46+ {
47+ // Arrange
48+ var mapping = new ParameterMapping ( ) ;
49+ var sourcePropertyName = "SourceProperty" ;
50+ var destinationParameterName = "destinationParam" ;
51+
52+ // Act
53+ mapping . SourcePropertyName = sourcePropertyName ;
54+ mapping . DestinationParameterName = destinationParameterName ;
55+
56+ // Assert
57+ mapping . SourcePropertyName . Should ( ) . Be ( sourcePropertyName ) ;
58+ mapping . DestinationParameterName . Should ( ) . Be ( destinationParameterName ) ;
59+ }
60+
61+ [ Fact ]
62+ public void PropertyMapping_InheritsFromMappingInstruction ( )
63+ {
64+ // Assert
65+ typeof ( PropertyMapping ) . Should ( ) . BeDerivedFrom < MappingInstruction > ( ) ;
66+ }
67+
68+ [ Fact ]
69+ public void PropertyMapping_Properties_CanBeSetAndRetrieved ( )
70+ {
71+ // Arrange
72+ var mapping = new PropertyMapping ( ) ;
73+ var sourcePropertyName = "SourceProperty" ;
74+ var destinationPropertyName = "DestinationProperty" ;
75+
76+ // Act
77+ mapping . SourcePropertyName = sourcePropertyName ;
78+ mapping . DestinationPropertyName = destinationPropertyName ;
79+
80+ // Assert
81+ mapping . SourcePropertyName . Should ( ) . Be ( sourcePropertyName ) ;
82+ mapping . DestinationPropertyName . Should ( ) . Be ( destinationPropertyName ) ;
83+ }
84+
85+ [ Fact ]
86+ public void PropertyMappingInstruction_IsAbstractBaseClass ( )
87+ {
88+ // Assert
89+ typeof ( PropertyMappingInstruction ) . Should ( ) . BeAbstract ( ) ;
90+ }
91+
92+ [ Fact ]
93+ public void PropertyMappingInstruction_InheritsFromMappingInstruction ( )
94+ {
95+ // Assert
96+ typeof ( PropertyMappingInstruction ) . Should ( ) . BeDerivedFrom < MappingInstruction > ( ) ;
97+ }
98+
99+ [ Fact ]
100+ public void PropertyMappingInstruction_Constructor_SetsDestinationProperty ( )
101+ {
102+ // Arrange
103+ var mockDestinationProperty = new Mock < IPropertySymbol > ( ) ;
104+
105+ // Act
106+ var instruction = new TestPropertyMappingInstruction ( mockDestinationProperty . Object ) ;
107+
108+ // Assert
109+ instruction . DestinationProperty . Should ( ) . Be ( mockDestinationProperty . Object ) ;
110+ }
111+
112+ [ Fact ]
113+ public void PropertyMappingInstruction_DestinationProperty_IsReadOnly ( )
114+ {
115+ // Arrange
116+ var mockDestinationProperty = new Mock < IPropertySymbol > ( ) ;
117+ var instruction = new TestPropertyMappingInstruction ( mockDestinationProperty . Object ) ;
118+
119+ // Assert
120+ var property = typeof ( PropertyMappingInstruction ) . GetProperty ( nameof ( PropertyMappingInstruction . DestinationProperty ) ) ;
121+ property ! . CanWrite . Should ( ) . BeFalse ( ) ;
122+ property . CanRead . Should ( ) . BeTrue ( ) ;
123+ }
124+
125+ // Test implementation of abstract PropertyMappingInstruction
126+ private class TestPropertyMappingInstruction : PropertyMappingInstruction
127+ {
128+ public TestPropertyMappingInstruction ( IPropertySymbol destinationProperty ) : base ( destinationProperty ) { }
129+ }
130+ }
0 commit comments