-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_Classes.cs
217 lines (159 loc) · 6.71 KB
/
05_Classes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using System.Diagnostics.CodeAnalysis;
using basic.Common;
using basic.Extensions;
using Xunit;
namespace basic
{
public class Classes
{
[Fact]
public void should_choose_correct_overloading_method_at_compile_time_1()
{
var demoObject = new MethodOverloadDemoClass();
string chosenOne = demoObject.Foo(1);
// change variable value to correct one.
const string expected = "Foo(int)";
Assert.Equal(expected, chosenOne);
}
[Fact]
public void should_choose_correct_overloading_method_at_compile_time_2()
{
var demoObject = new MethodOverloadDemoClass();
string chosenOne = demoObject.Foo((object) 1);
// change variable value to correct one.
const string expected = "Foo(object)";
Assert.Equal(expected, chosenOne);
}
[Fact]
public void should_choose_correct_overloading_method_at_compile_time_3()
{
var demoObject = new MethodOverloadDemoClass();
const short argument = 2;
string chosenOne = demoObject.Foo(argument);
// change variable value to correct one.
const string expected = "Foo(int)";
Assert.Equal(expected, chosenOne);
}
[Fact]
public void should_call_other_instance_constructor_in_overload_constructor()
{
var demoClass = new ConstructorOverloadingDemoClass("arg");
string constructorCallSequence = demoClass.ConstructorCallSequence;
// change variable value to correct one.
const string expectedSequence = "Ctor()\nCtor(string)\n";
Assert.Equal(expectedSequence, constructorCallSequence);
}
[Fact]
public void should_generate_parameterless_constructor_by_default()
{
var demoClass = new ImplicitConstructorClassDemo();
bool hasDefaultConstructor = demoClass.HasDefaultConstructor();
// change variable value to correct one.
const bool expected = true;
Assert.Equal(expected, hasDefaultConstructor);
}
[Fact]
public void should_not_generate_parameterless_constructor_if_parameterized_constructor_exists()
{
var demoClass = new ParameterizedConstructorClassDemo(1);
bool hasDefaultConstructor = demoClass.HasDefaultConstructor();
// change variable value to correct one.
const bool expected = false;
Assert.Equal(expected, hasDefaultConstructor);
}
[Fact]
[SuppressMessage("ReSharper", "RedundantEmptyObjectOrCollectionInitializer")]
public void should_initailize_object_properties()
{
var demoClass = new ObjectInitializerDemoClass("property1")
{
// add property initialization logic here.
Property1 = "property1.1",
Property2 = "property2.1"
};
const string expectedProperty1 = "property1.1";
const string expectedProperty2 = "property2.1";
Assert.Equal(expectedProperty1, demoClass.Property1);
Assert.Equal(expectedProperty2, demoClass.Property2);
}
[Fact]
[SuppressMessage("ReSharper", "UseObjectOrCollectionInitializer")]
public void should_be_able_to_get_and_set_public_auto_properties()
{
var demoClass = new AutoPropertyDemoClass();
demoClass.Name = "My Name";
// please change variable value to correct one.
const string expected = "My Name";
Assert.Equal(expected, demoClass.Name);
}
[Fact]
[SuppressMessage("ReSharper", "UseObjectOrCollectionInitializer")]
public void should_execute_customized_logic_in_property()
{
var demoClass = new CustomizePropertyDemoClass();
demoClass.Name = "My Name";
// please change variable value to correct one.
const string expected = "Your Name Is My Name";
Assert.Equal(expected, demoClass.Name);
}
[Fact]
public void should_get_correct_value_of_indexer()
{
var demoClass = new IndexerDemoClass();
string indexerValue = demoClass[2];
// please change variable value to correct one.
const string expected = "You are accessing indexer 2";
Assert.Equal(expected, indexerValue);
}
[Fact]
public void should_access_indexer_with_different_argument_type()
{
var demoClass = new IndexerDemoClass();
string indexerValue = demoClass["stringArgument"];
// please change variable value to correct one.
const string expected = "You are accessing indexer stringArgument";
Assert.Equal(expected, indexerValue);
}
[Fact]
public void should_be_able_to_access_multiple_indexer_arguments()
{
var demoClass = new IndexerDemoClass();
string indexerValue = demoClass[1, "Hello"];
// please change variable value to correct one.
const string expected = "You are accessing indexer with first argument 1 and second argument Hello";
Assert.Equal(expected, indexerValue);
}
[Fact]
public void should_do_static_initialization()
{
string staticFieldValue = StaticConstructorDemoClass.StaticField;
// please change variable value to correct one.
const string expected = "You are so cute!";
Assert.Equal(expected, staticFieldValue);
}
[Fact]
public void should_be_able_to_dispose_object_when_out_of_scope()
{
var disposable = new DisposableDemoClass();
using (disposable)
{
}
// please change variable value to correct one.
const bool expected = true;
Assert.Equal(expected, disposable.IsDisposed);
}
[Fact]
public void should_be_able_to_declare_class_to_different_places()
{
var demoClass = new PartialClassDemoClass
{
Name = "Hall",
Title = "Mr."
};
string name = demoClass.ToString();
// please change variable value to correct one.
const string expected = "Mr. Hall";
Assert.Equal(expected, name);
}
}
}