-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Compiler UT] Ut readonly property (#984)
* add property method test * format * Update tests/Neo.Compiler.CSharp.TestContracts/Contract_PropertyMethod.cs * update UT * fix readonly set * update comments * add document reference * fix comments * remvoe static set. Its not supported by C# * format * remove constructor check as syntax analyzer will handle it. --------- Co-authored-by: Shargon <[email protected]>
- Loading branch information
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/Neo.Compiler.CSharp.TestContracts/Contract_PropertyMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Neo.Compiler.CSharp.UnitTests.TestClasses; | ||
|
||
public class Contract_PropertyMethod : SmartContract.Framework.SmartContract | ||
{ | ||
public static (string, int) testProperty() | ||
{ | ||
var p = new Person("NEO3", 10); | ||
return (p.Name, p.Age); | ||
} | ||
|
||
public static void testProperty2() | ||
{ | ||
var p = new Person("NEO3", 10); | ||
} | ||
|
||
public class Person | ||
{ | ||
public string Name { get; set; } | ||
public int Age { get; } | ||
|
||
public Person(string name, int age) | ||
{ | ||
Name = name; | ||
Age = age; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Property_Method.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.SmartContract.TestEngine; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
|
||
namespace Neo.Compiler.CSharp.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_Property_Method | ||
{ | ||
private TestEngine testEngine; | ||
|
||
[TestInitialize] | ||
public void Init() | ||
{ | ||
testEngine = new TestEngine(); | ||
testEngine.AddNoOptimizeEntryScript(Utils.Extensions.TestContractRoot + "Contract_PropertyMethod.cs"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPropertyMethod() | ||
{ | ||
testEngine.Reset(); | ||
var res = testEngine.ExecuteTestCaseStandard("testProperty"); | ||
Assert.AreEqual(testEngine.State, VMState.HALT); | ||
var arr = (Array)res.Pop(); | ||
Assert.AreEqual(arr[0].GetString(), "NEO3"); | ||
Assert.AreEqual(arr[1].GetInteger(), 10); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPropertyMethod2() | ||
{ | ||
testEngine.Reset(); | ||
var res = testEngine.ExecuteTestCaseStandard("testProperty2"); | ||
Assert.AreEqual(testEngine.State, VMState.HALT); | ||
} | ||
} | ||
} |