Skip to content

Commit fa5a521

Browse files
차혁흔차혁흔
authored andcommitted
0 parents  commit fa5a521

File tree

300 files changed

+96843
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+96843
-0
lines changed

Chapter 10/AAA.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var CastleBuilder = (function () {
2+
function CastleBuilder() {
3+
}
4+
CastleBuilder.prototype.buildCastle = function (size) {
5+
var castle = new Castle();
6+
castle.size = size;
7+
return castle;
8+
};
9+
return CastleBuilder;
10+
})();
11+
12+
var Castle = (function () {
13+
function Castle() {
14+
}
15+
return Castle;
16+
})();
17+
18+
function When_building_a_castle_size_should_be_correctly_set() {
19+
var castleBuilder = new CastleBuilder();
20+
var expectedSize = 10;
21+
22+
var builtCastle = castleBuilder.buildCastle(10);
23+
24+
assertEqual(expectedSize, builtCastle.size);
25+
}
26+
27+
function assertEqual(expected, actual) {
28+
if (expected !== actual)
29+
throw "Got " + actual + " but expected " + expected;
30+
}
31+
32+
When_building_a_castle_size_should_be_correctly_set();

Chapter 10/AAA.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var assert
2+
3+
class CastleBuilder{
4+
buildCastle(size: number){
5+
var castle = new Castle();
6+
castle.size = size;
7+
return castle;
8+
}
9+
}
10+
11+
class Castle{
12+
public size: number;
13+
}
14+
15+
function When_building_a_castle_size_should_be_correctly_set(){
16+
var castleBuilder = new CastleBuilder();
17+
var expectedSize = 10;
18+
19+
var builtCastle = castleBuilder.buildCastle(10);
20+
21+
assertEqual(expectedSize, builtCastle.size);
22+
}
23+
24+
function assertEqual(expected, actual){
25+
if(expected !== actual)
26+
throw "Got " + actual + " but expected " + expected;
27+
}
28+
29+
When_building_a_castle_size_should_be_correctly_set();

Chapter 10/mock.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var Knight = (function () {
2+
function Knight(credentialFactory) {
3+
this.credentialFactory = credentialFactory;
4+
}
5+
Knight.prototype.presentCredentials = function (toRoyalty) {
6+
console.log("Presenting credentials to " + toRoyalty);
7+
this.credentialFactory.Create();
8+
return true;
9+
};
10+
return Knight;
11+
})();
12+
13+
var MockCredentialFactory = (function () {
14+
function MockCredentialFactory() {
15+
this.timesCalled = 0;
16+
}
17+
MockCredentialFactory.prototype.Create = function () {
18+
this.timesCalled++;
19+
};
20+
21+
MockCredentialFactory.prototype.Verify = function () {
22+
assert(this.timesCalled == 3);
23+
};
24+
return MockCredentialFactory;
25+
})();
26+
27+
function assert(value) {
28+
if (!value)
29+
throw "Assertion failure";
30+
}
31+
32+
var credentialFactory = new MockCredentialFactory();
33+
var knight = new Knight(credentialFactory);
34+
35+
var credentials = knight.presentCredentials("Lord Snow");
36+
credentials = knight.presentCredentials("Queen Cersei");
37+
credentials = knight.presentCredentials("Lord Stark");
38+
39+
credentialFactory.Verify();

Chapter 10/mock.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Knight{
2+
credentialFactory;
3+
constructor(credentialFactory){this.credentialFactory = credentialFactory;}
4+
5+
public presentCredentials(toRoyalty){
6+
console.log("Presenting credentials to " + toRoyalty);
7+
this.credentialFactory.Create();
8+
return true;
9+
}
10+
}
11+
12+
class MockCredentialFactory{
13+
timesCalled = 0;
14+
Create(){
15+
this.timesCalled++;
16+
}
17+
18+
Verify(){
19+
assert(this.timesCalled == 3);
20+
}
21+
}
22+
23+
function assert(value){
24+
if(!value)
25+
throw "Assertion failure";
26+
}
27+
28+
var credentialFactory = new MockCredentialFactory();
29+
var knight = new Knight(credentialFactory);
30+
31+
var credentials = knight.presentCredentials("Lord Snow");
32+
credentials = knight.presentCredentials("Queen Cersei");
33+
credentials = knight.presentCredentials("Lord Stark");
34+
35+
credentialFactory.Verify();

Chapter 10/mvvm.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var PageModel = (function () {
2+
function PageModel() {
3+
}
4+
return PageModel;
5+
})();
6+
7+
var User = (function () {
8+
function User() {
9+
}
10+
return User;
11+
})();

Chapter 10/mvvm.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class PageModel{
2+
titleVisible: boolean;
3+
users: Array<User>;
4+
}
5+
6+
var model = new PageModel();
7+
model.titleVisible = false;
8+
var controller = new UserListPageController(model);
9+
10+
controller.AddUser(new User());
11+
12+
assert.true(model.titleVisible);
13+
14+
class User{}

Chapter 10/node_modules/sinon/GPATH

56 KB
Binary file not shown.

Chapter 10/node_modules/sinon/GRTAGS

16 KB
Binary file not shown.

Chapter 10/node_modules/sinon/GSYMS

16 KB
Binary file not shown.

Chapter 10/node_modules/sinon/GTAGS

16 KB
Binary file not shown.

0 commit comments

Comments
 (0)