1
+ using System ;
2
+ using Microsoft . OData . Edm ;
3
+ using Microsoft . OData . Edm . Vocabularies ;
4
+ using Microsoft . OpenApi . OData . Vocabulary . Core ;
5
+ using Xunit ;
6
+
7
+ namespace Microsoft . OpenApi . OData . Reader . Vocabulary . Capabilities . Tests ;
8
+
9
+ public class DeprecatedRevisionTypeTests
10
+ {
11
+ [ Fact ]
12
+ public void DefaultPropertyAsNull ( )
13
+ {
14
+ // Arrange & Act
15
+ DeprecatedRevisionsType revision = new ( ) ;
16
+
17
+ // Assert
18
+ Assert . Null ( revision . Date ) ;
19
+ Assert . Null ( revision . RemovalDate ) ;
20
+ Assert . Null ( revision . Description ) ;
21
+ Assert . Null ( revision . Version ) ;
22
+ Assert . Null ( revision . Kind ) ;
23
+ }
24
+ [ Fact ]
25
+ public void InitializeWithNullRecordThrows ( )
26
+ {
27
+ // Arrange & Act
28
+ DeprecatedRevisionsType revision = new ( ) ;
29
+
30
+ // Assert
31
+ Assert . Throws < ArgumentNullException > ( "record" , ( ) => revision . Initialize ( record : null ) ) ;
32
+ }
33
+ private readonly static EdmEnumType enumType = new ( "Org.OData.Core.V1" , "RevisionKind" ) ;
34
+ private readonly static EdmEnumMember deprecatedValue = new ( enumType , "Deprecated" , new EdmEnumMemberValue ( 2 ) ) ;
35
+ private readonly static EdmEnumMember addedValue = new ( enumType , "Added" , new EdmEnumMemberValue ( 0 ) ) ;
36
+ [ Fact ]
37
+ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess ( )
38
+ {
39
+ // Arrange
40
+ IEdmRecordExpression record = new EdmRecordExpression (
41
+ new EdmPropertyConstructor ( "Date" , new EdmDateConstant ( new Date ( 2021 , 8 , 24 ) ) ) ,
42
+ new EdmPropertyConstructor ( "RemovalDate" , new EdmDateConstant ( new Date ( 2021 , 10 , 24 ) ) ) ,
43
+ new EdmPropertyConstructor ( "Kind" , new EdmEnumMemberExpression ( deprecatedValue ) ) ,
44
+ new EdmPropertyConstructor ( "Description" , new EdmStringConstant ( "The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API." ) ) ,
45
+ new EdmPropertyConstructor ( "Version" , new EdmStringConstant ( "2021-05/test" ) ) ) ;
46
+
47
+ // Act
48
+ DeprecatedRevisionsType revision = new ( ) ;
49
+ revision . Initialize ( record ) ;
50
+
51
+ // Assert
52
+ Assert . NotNull ( revision . Version ) ;
53
+ Assert . Equal ( "2021-05/test" , revision . Version ) ;
54
+
55
+ Assert . NotNull ( revision . Description ) ;
56
+ Assert . Equal ( "The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API." , revision . Description ) ;
57
+
58
+ Assert . NotNull ( revision . Date ) ;
59
+ Assert . Equal ( new DateTime ( 2021 , 8 , 24 ) , revision . Date ) ;
60
+
61
+ Assert . NotNull ( revision . RemovalDate ) ;
62
+ Assert . Equal ( new DateTime ( 2021 , 10 , 24 ) , revision . RemovalDate ) ;
63
+ }
64
+ [ Fact ]
65
+ public void ThrowsOnWrongKind ( )
66
+ {
67
+ // Arrange
68
+ IEdmRecordExpression record = new EdmRecordExpression (
69
+ new EdmPropertyConstructor ( "Date" , new EdmDateConstant ( new Date ( 2021 , 8 , 24 ) ) ) ,
70
+ new EdmPropertyConstructor ( "RemovalDate" , new EdmDateConstant ( new Date ( 2021 , 10 , 24 ) ) ) ,
71
+ new EdmPropertyConstructor ( "Kind" , new EdmEnumMemberExpression ( addedValue ) ) ,
72
+ new EdmPropertyConstructor ( "Description" , new EdmStringConstant ( "The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API." ) ) ,
73
+ new EdmPropertyConstructor ( "Version" , new EdmStringConstant ( "2021-05/test" ) ) ) ;
74
+
75
+ // Act
76
+ DeprecatedRevisionsType revision = new ( ) ;
77
+
78
+ // Assert
79
+ Assert . Throws < InvalidOperationException > ( ( ) => revision . Initialize ( record ) ) ;
80
+ }
81
+ }
0 commit comments