GenerateDefaultConstructorsTests.vb 13.0 KB
Newer Older
1 2
' Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

C
CyrusNajmabadi 已提交
3
Imports Microsoft.CodeAnalysis.CodeRefactorings
4
Imports Microsoft.CodeAnalysis.CodeRefactorings.GenerateDefaultConstructors
5 6 7 8 9

Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings.GenerateDefaultConstructors
    Public Class GenerateDefaultConstructorsTests
        Inherits AbstractVisualBasicCodeActionTest

C
CyrusNajmabadi 已提交
10
        Protected Overrides Function CreateCodeRefactoringProvider(workspace As Workspace, fixProviderData As Object) As CodeRefactoringProvider
11 12 13
            Return New GenerateDefaultConstructorsCodeRefactoringProvider()
        End Function

14
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
15 16
        Public Async Function TestException0() As Task
            Await TestAsync(
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
36
index:=0)
37
        End Function
38

39
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
40 41
        Public Async Function TestException1() As Task
            Await TestAsync(
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
61
index:=1)
62
        End Function
63

64
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
65 66
        Public Async Function TestException2() As Task
            Await TestAsync(
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Class Program
    Inherits Exception
    Protected Sub New(info As SerializationInfo, context As StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
87
index:=2)
88
        End Function
89

90
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
91 92
        Public Async Function TestException3() As Task
            Await TestAsync(
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Class Program
    Inherits Exception
    Public Sub New()
    End Sub
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As SerializationInfo, context As StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
121
index:=3)
122
        End Function
123

124
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
J
Jared Parsons 已提交
125
        <WorkItem(539676, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539676")>
126 127
        Public Async Function TestNotOfferedOnResolvedBaseClassName() As Task
            Await TestMissingAsync(
128 129 130 131 132
"Class Base
End Class
Class Derived
    Inherits B[||]ase
End Class")
133
        End Function
134

135
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
136 137
        Public Async Function TestNotOfferedOnUnresolvedBaseClassName() As Task
            Await TestMissingAsync(
138 139 140
"Class Derived
    Inherits [||]Base
End Class")
141
        End Function
142

143
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
144 145
        Public Async Function TestNotOfferedOnInheritsStatementForStructures() As Task
            Await TestMissingAsync(
146 147 148
"Structure Derived
    Inherits [||]Base
End Structure")
149
        End Function
150

151
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
152 153
        Public Async Function TestNotOfferedForIncorrectlyParentedInheritsStatement() As Task
            Await TestMissingAsync(
154
"Inherits [||]Foo")
155
        End Function
156

157
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
158 159
        Public Async Function TestWithDefaultConstructor() As Task
            Await TestAsync(
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Public Sub New()
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Class Program
    Inherits Exception
    Public Sub New()
    End Sub
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As SerializationInfo, context As StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
190
index:=3)
191
        End Function
192

193
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
194 195
        Public Async Function TestWithDefaultConstructorMissing1() As Task
            Await TestAsync(
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New()
    End Sub
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
232
index:=0)
233
        End Function
234

235
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
236 237
        Public Async Function TestWithDefaultConstructorMissing2() As Task
            Await TestAsync(
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits [||]Exception
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New()
    End Sub
    Public Sub New()
    End Sub
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Public Sub New(message As String, innerException As Exception)
        MyBase.New(message, innerException)
    End Sub
    Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
273
index:=2)
274
        End Function
275

J
Jared Parsons 已提交
276
        <WorkItem(540712, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540712")>
277
        <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
278 279
        Public Async Function TestEndOfToken() As Task
            Await TestAsync(
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception[||]
    Sub Main(args As String())
    End Sub
End Class",
"Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New(message As String)
        MyBase.New(message)
    End Sub
    Sub Main(args As String())
    End Sub
End Class",
299
index:=0)
300
        End Function
301

302
        <Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
303 304
        Public Async Function TestFormattingInGenerateDefaultConstructor() As Task
            Await TestAsync(
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
<Text>Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exce[||]ption
    Public Sub New()
    End Sub
    Sub Main(args As String())
    End Sub
End Class</Text>.Value.Replace(vbLf, vbCrLf),
<Text>Imports System
Imports System.Collections.Generic
Imports System.Linq
Class Program
    Inherits Exception
    Public Sub New()
    End Sub

    Public Sub New(message As String)
        MyBase.New(message)
    End Sub

    Sub Main(args As String())
    End Sub
End Class</Text>.Value.Replace(vbLf, vbCrLf),
index:=0,
compareTokens:=False)
332
        End Function
333

J
Jared Parsons 已提交
334
        <WorkItem(889349, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/889349")>
335
        <Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
336 337
        Public Async Function TestDefaultConstructorGeneration() As Task
            Await TestAsync(
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
<Text>Class C
    Inherits B[||]
    Public Sub New(y As Integer)
    End Sub
End Class

Class B
    Friend Sub New(x As Integer)
    End Sub
End Class</Text>.Value.Replace(vbLf, vbCrLf),
<Text>Class C
    Inherits B
    Public Sub New(y As Integer)
    End Sub

    Friend Sub New(x As Integer)
        MyBase.New(x)
    End Sub
End Class

Class B
    Friend Sub New(x As Integer)
    End Sub
End Class</Text>.Value.Replace(vbLf, vbCrLf),
index:=0,
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
compareTokens:=False)
        End Function

        <Fact(Skip:="https://github.com/dotnet/roslyn/issues/15005"), Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
        Public Async Function TestFixAll() As Task
            Await TestAsync(
<Text>
Class C
    Inherits [||]B

    Public Sub New(y As Boolean)
    End Sub
End Class

Class B
    Friend Sub New(x As Integer)
    End Sub

    Protected Sub New(x As String)
    End Sub

    Public Sub New(x As Boolean)
    End Sub

    Public Sub New(x As Long)
    End Sub
End Class
</Text>.Value.Replace(vbLf, vbCrLf),
<Text>
Class C
    Inherits B

    Friend Sub New(x As Integer)
        MyBase.New(x)
    End Sub

    Protected Sub New(x As String)
        MyBase.New(x)
    End Sub

    Public Sub New(x As Long)
        MyBase.New(x)
    End Sub

    Public Sub New(y As Boolean)
    End Sub
End Class

Class B
    Friend Sub New(x As Integer)
    End Sub

    Protected Sub New(x As String)
    End Sub

    Public Sub New(x As Boolean)
    End Sub

    Public Sub New(x As Long)
    End Sub
End Class
</Text>.Value.Replace(vbLf, vbCrLf),
index:=2,
compareTokens:=False)
            Throw New Exception() ' (Skip:="https://github.com/dotnet/roslyn/issues/15005")
        End Function

        <Fact(Skip:="https://github.com/dotnet/roslyn/issues/15005"), Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors)>
        Public Async Function TestFixAll_WithTuples() As Task
            Await TestAsync(
<Text>
Class C
    Inherits [||]B

    Public Sub New(y As (Boolean, Boolean))
    End Sub
End Class

Class B
    Friend Sub New(x As (Integer, Integer))
    End Sub

    Protected Sub New(x As (String, String))
    End Sub

    Public Sub New(x As (Boolean, Boolean))
    End Sub

    Public Sub New(x As (Long, Long))
    End Sub
End Class
</Text>.Value.Replace(vbLf, vbCrLf),
<Text>
Class C
    Inherits B

    Friend Sub New(x As (Integer, Integer))
        MyBase.New(x)
    End Sub

    Protected Sub New(x As (String, String))
        MyBase.New(x)
    End Sub

    Public Sub New(x As (Long, Long))
        MyBase.New(x)
    End Sub

    Public Sub New(y As (Boolean, Boolean))
    End Sub
End Class

Class B
    Friend Sub New(x As (Integer, Integer))
    End Sub

    Protected Sub New(x As (String, String))
    End Sub

    Public Sub New(x As (Boolean, Boolean))
    End Sub

    Public Sub New(x As (Long, Long))
    End Sub
End Class
</Text>.Value.Replace(vbLf, vbCrLf),
index:=2,
490
compareTokens:=False)
491
        End Function
492
    End Class
493
End Namespace