1+ using Migrator . Framework ;
2+ using NUnit . Framework ;
3+ using DotNetProjects . Migrator . Framework ;
4+ using System ;
5+ using System . Linq ;
6+
7+ namespace Migrator . Tests . Framework . ColumnProperties ;
8+
9+ public class ColumnPropertyExtensionsTests
10+ {
11+ [ Test ]
12+ public void Clear ( )
13+ {
14+ // Arrange
15+ var columnProperty = ColumnProperty . PrimaryKey | ColumnProperty . NotNull ;
16+
17+ // Act
18+ columnProperty = columnProperty . Clear ( ColumnProperty . PrimaryKey ) ;
19+
20+ // Assert
21+ Assert . That ( columnProperty . HasFlag ( ColumnProperty . PrimaryKey ) , Is . False ) ;
22+ }
23+
24+ [ Test ]
25+ public void IsSet ( )
26+ {
27+ // Arrange
28+ var columnProperty = ColumnProperty . PrimaryKeyWithIdentity | ColumnProperty . NotNull ;
29+
30+ // Act
31+ var actualData = GetAllSingleColumnProperties ( ) . Select ( x => new
32+ {
33+ ColumnPropertyString = x . ToString ( ) ,
34+ IsSet = columnProperty . IsSet ( x ) ,
35+ IsNotSet = columnProperty . IsNotSet ( x )
36+ } )
37+ . ToList ( ) ;
38+
39+ // Assert
40+ string [ ] expectedSet = [ nameof ( ColumnProperty . PrimaryKey ) , nameof ( ColumnProperty . NotNull ) , nameof ( ColumnProperty . Identity ) ] ;
41+ var actualDataShouldBeTrue = actualData . Where ( x => expectedSet . Any ( y => y == x . ColumnPropertyString ) ) . ToList ( ) ;
42+ var actualDataShouldBeFalse = actualData . Where ( x => ! expectedSet . Any ( y => y == x . ColumnPropertyString ) ) . ToList ( ) ;
43+
44+ Assert . That ( actualDataShouldBeTrue . Select ( x => x . IsSet ) , Has . All . True ) ;
45+ Assert . That ( actualDataShouldBeFalse . Select ( x => x . IsSet ) , Has . All . False ) ;
46+ }
47+
48+ [ Test ]
49+ public void IsNotSet ( )
50+ {
51+ // Arrange
52+ var columnProperty = ColumnProperty . PrimaryKeyWithIdentity | ColumnProperty . NotNull ;
53+
54+ // Act
55+ var actualData = GetAllSingleColumnProperties ( ) . Select ( x => new
56+ {
57+ ColumnPropertyString = x . ToString ( ) ,
58+ IsSet = columnProperty . IsNotSet ( x ) ,
59+ IsNotSet = columnProperty . IsNotSet ( x )
60+ } )
61+ . ToList ( ) ;
62+
63+ // Assert
64+ string [ ] expectedSet = [ nameof ( ColumnProperty . PrimaryKey ) , nameof ( ColumnProperty . NotNull ) , nameof ( ColumnProperty . Identity ) ] ;
65+ var actualDataShouldBeFalse = actualData . Where ( x => expectedSet . Any ( y => y == x . ColumnPropertyString ) ) . ToList ( ) ;
66+ var actualDataShouldBeTrue = actualData . Where ( x => ! expectedSet . Any ( y => y == x . ColumnPropertyString ) ) . ToList ( ) ;
67+
68+ Assert . That ( actualDataShouldBeTrue . Select ( x => x . IsNotSet ) , Has . All . True ) ;
69+ Assert . That ( actualDataShouldBeFalse . Select ( x => x . IsNotSet ) , Has . All . False ) ;
70+ }
71+
72+ [ Test ]
73+ public void Set_Success ( )
74+ {
75+ // Arrange
76+ var columnProperty = ColumnProperty . NotNull ;
77+
78+ // Act
79+ var result = columnProperty . Set ( ColumnProperty . PrimaryKeyWithIdentity ) ;
80+
81+ // Assert
82+ var expected = ColumnProperty . NotNull | ColumnProperty . PrimaryKeyWithIdentity ;
83+
84+ Assert . That ( result , Is . EqualTo ( expected ) ) ;
85+ }
86+
87+ private ColumnProperty [ ] GetAllSingleColumnProperties ( )
88+ {
89+ return [ .. Enum . GetValues < ColumnProperty > ( ) . Where ( x => x == 0 || ( x & ( x - 1 ) ) == 0 ) ] ;
90+ }
91+ }
0 commit comments