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