Skip to content

Commit 501692d

Browse files
committed
Pull from develop
2 parents 5aec995 + 137f803 commit 501692d

File tree

15 files changed

+950
-195
lines changed

15 files changed

+950
-195
lines changed

VSDiagnostics/VSDiagnostics/VSDiagnostics.Test/Tests/General/SwitchDoesNotHandleAllEnumOptionsTests.cs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,5 +826,194 @@ void Method()
826826
VerifyDiagnostic(original, SwitchDoesNotHandleAllEnumOptionsAnalyzer.Rule.MessageFormat.ToString());
827827
VerifyFix(original, result);
828828
}
829+
830+
[TestMethod]
831+
public void SwitchDoesNotHandleAllEnumOptions_MissingEnumStatements_CaseValueIsCastToEnumType()
832+
{
833+
var original = @"
834+
namespace ConsoleApplication1
835+
{
836+
class MyClass
837+
{
838+
enum MyEnum
839+
{
840+
Fizz, Buzz, FizzBuzz
841+
}
842+
843+
void Method()
844+
{
845+
var e = MyEnum.Fizz;
846+
switch (e)
847+
{
848+
case (MyEnum) 0:
849+
break;
850+
}
851+
}
852+
}
853+
}";
854+
855+
VerifyDiagnostic(original);
856+
}
857+
858+
[TestMethod]
859+
public void SwitchDoesNotHandleAllEnumOptions_NoCaseStatements_NoUsings()
860+
{
861+
var original = @"
862+
namespace ConsoleApplication1
863+
{
864+
class MyClass
865+
{
866+
void Method()
867+
{
868+
var e = System.IO.FileOptions.DeleteOnClose;
869+
switch (e)
870+
{
871+
}
872+
}
873+
}
874+
}";
875+
876+
var result = @"
877+
namespace ConsoleApplication1
878+
{
879+
class MyClass
880+
{
881+
void Method()
882+
{
883+
var e = System.IO.FileOptions.DeleteOnClose;
884+
switch (e)
885+
{
886+
case System.IO.FileOptions.Encrypted:
887+
throw new System.NotImplementedException();
888+
case System.IO.FileOptions.SequentialScan:
889+
throw new System.NotImplementedException();
890+
case System.IO.FileOptions.DeleteOnClose:
891+
throw new System.NotImplementedException();
892+
case System.IO.FileOptions.RandomAccess:
893+
throw new System.NotImplementedException();
894+
case System.IO.FileOptions.Asynchronous:
895+
throw new System.NotImplementedException();
896+
case System.IO.FileOptions.WriteThrough:
897+
throw new System.NotImplementedException();
898+
case System.IO.FileOptions.None:
899+
throw new System.NotImplementedException();
900+
}
901+
}
902+
}
903+
}";
904+
905+
VerifyDiagnostic(original, SwitchDoesNotHandleAllEnumOptionsAnalyzer.Rule.MessageFormat.ToString());
906+
VerifyFix(original, result);
907+
}
908+
909+
[TestMethod]
910+
public void SwitchDoesNotHandleAllEnumOptions_NoCaseStatements_NormalUsing()
911+
{
912+
var original = @"
913+
using System.IO;
914+
915+
namespace ConsoleApplication1
916+
{
917+
class MyClass
918+
{
919+
void Method()
920+
{
921+
var e = FileOptions.DeleteOnClose;
922+
switch (e)
923+
{
924+
}
925+
}
926+
}
927+
}";
928+
929+
var result = @"
930+
using System.IO;
931+
932+
namespace ConsoleApplication1
933+
{
934+
class MyClass
935+
{
936+
void Method()
937+
{
938+
var e = FileOptions.DeleteOnClose;
939+
switch (e)
940+
{
941+
case FileOptions.Encrypted:
942+
throw new System.NotImplementedException();
943+
case FileOptions.SequentialScan:
944+
throw new System.NotImplementedException();
945+
case FileOptions.DeleteOnClose:
946+
throw new System.NotImplementedException();
947+
case FileOptions.RandomAccess:
948+
throw new System.NotImplementedException();
949+
case FileOptions.Asynchronous:
950+
throw new System.NotImplementedException();
951+
case FileOptions.WriteThrough:
952+
throw new System.NotImplementedException();
953+
case FileOptions.None:
954+
throw new System.NotImplementedException();
955+
}
956+
}
957+
}
958+
}";
959+
960+
VerifyDiagnostic(original, SwitchDoesNotHandleAllEnumOptionsAnalyzer.Rule.MessageFormat.ToString());
961+
VerifyFix(original, result);
962+
}
963+
964+
[TestMethod]
965+
public void SwitchDoesNotHandleAllEnumOptions_NoCaseStatements_UsingStatic()
966+
{
967+
var original = @"
968+
using static System.IO.FileOptions;
969+
970+
namespace ConsoleApplication1
971+
{
972+
class MyClass
973+
{
974+
void Method()
975+
{
976+
var e = DeleteOnClose;
977+
switch (e)
978+
{
979+
}
980+
}
981+
}
982+
}";
983+
984+
var result = @"
985+
using static System.IO.FileOptions;
986+
987+
namespace ConsoleApplication1
988+
{
989+
class MyClass
990+
{
991+
void Method()
992+
{
993+
var e = DeleteOnClose;
994+
switch (e)
995+
{
996+
case Encrypted:
997+
throw new System.NotImplementedException();
998+
case SequentialScan:
999+
throw new System.NotImplementedException();
1000+
case DeleteOnClose:
1001+
throw new System.NotImplementedException();
1002+
case RandomAccess:
1003+
throw new System.NotImplementedException();
1004+
case Asynchronous:
1005+
throw new System.NotImplementedException();
1006+
case WriteThrough:
1007+
throw new System.NotImplementedException();
1008+
case None:
1009+
throw new System.NotImplementedException();
1010+
}
1011+
}
1012+
}
1013+
}";
1014+
1015+
VerifyDiagnostic(original, SwitchDoesNotHandleAllEnumOptionsAnalyzer.Rule.MessageFormat.ToString());
1016+
VerifyFix(original, result);
1017+
}
8291018
}
8301019
}

0 commit comments

Comments
 (0)