diff --git a/WebApplication1/WebApplication1/Controllers/HomeController.cs b/WebApplication1/WebApplication1/Controllers/HomeController.cs index a7287b0..a7f910b 100644 --- a/WebApplication1/WebApplication1/Controllers/HomeController.cs +++ b/WebApplication1/WebApplication1/Controllers/HomeController.cs @@ -23,5 +23,10 @@ public ActionResult Services() { return View(); } + + public ActionResult ComponentExample() + { + return View(); + } } } \ No newline at end of file diff --git a/WebApplication1/WebApplication1/Jasmine/SpecRunner.html b/WebApplication1/WebApplication1/Jasmine/SpecRunner.html deleted file mode 100644 index 4162e2c..0000000 --- a/WebApplication1/WebApplication1/Jasmine/SpecRunner.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Jasmine Spec Runner v2.3.4 - - - - - - - - - - - - - - - - - diff --git a/WebApplication1/WebApplication1/Jasmine/spec/ComponentExampleControllerSpec.js b/WebApplication1/WebApplication1/Jasmine/spec/ComponentExampleControllerSpec.js new file mode 100644 index 0000000..1aa4706 --- /dev/null +++ b/WebApplication1/WebApplication1/Jasmine/spec/ComponentExampleControllerSpec.js @@ -0,0 +1,44 @@ +/// + +describe("controller: componentExampleController", function () { + var model = { + players: [ + { Name: "Player1", Age: 20, Hits: 0 }, + { Name: "Player2", Age: 30, Hits: 0 } + ] + }; + + beforeEach(function() { + module("myApp"); + + module(function ($provide) { + $provide.factory("dataService", function () { + var data = model; + return data; + }); + }); + }); + + beforeEach(inject(function ($controller, $rootScope) { + this.scope = $rootScope.$new(); + $controller("componentExampleController", { + $scope: this.scope + }); + })); + + describe("check componentExampleController", function () { + it("should contain players", function () { + expect(this.scope.model).toEqual(model); + }); + + it("should hit player", function () { + var player = { Name: "PlayerX", Age: 1, Hits: 0 }; + + this.scope.hitFn(player); + expect(player.Hits).toBe(1); + + this.scope.hitFn(player); + expect(player.Hits).toBe(2); + }); + }); +}); diff --git a/WebApplication1/WebApplication1/Jasmine/spec/ComponentExamplePlayerSpec.js b/WebApplication1/WebApplication1/Jasmine/spec/ComponentExamplePlayerSpec.js new file mode 100644 index 0000000..039694e --- /dev/null +++ b/WebApplication1/WebApplication1/Jasmine/spec/ComponentExamplePlayerSpec.js @@ -0,0 +1,43 @@ +/// + +describe("module: componentExamplePlayer", function () { + beforeEach(function() { + module("myApp"); + }); + + beforeEach(inject(function ($controller, $rootScope) { + this.scope = $rootScope.$new(); + $controller("componentExampleController", { + $scope: this.scope + }); + spyOn(this.scope, "hitFn"); + })); + + beforeEach(inject(function ($compile) { + this.scope.myPlayer = { Name: "Player1", Age: 20, Hits: 0 }; + + this.element = + "
" + + "

Player Info

" + + "

Name: {{player.Name}}

" + + "

Age: {{player.Age}}

" + + "

Hits: {{player.Hits}}

" + + "" + + "
"; + this.element = $compile(this.element)(this.scope); + this.scope.$digest(); + })); + + describe("check componentExampleController", function () { + it("should contain myPlayer", function () { + var isolated = this.element.isolateScope(); + expect(isolated.player).toEqual(this.scope.myPlayer); + }); + + it("should hit myPlayer", function () { + var isolated = this.element.isolateScope(); + isolated.hit({player: isolated.player}); + expect(this.scope.hitFn).toHaveBeenCalledWith(isolated.player); + }); + }); +}); diff --git a/WebApplication1/WebApplication1/Jasmine/spec/SimpleControllerSpec.js b/WebApplication1/WebApplication1/Jasmine/spec/SimpleControllerSpec.js index 4f2ffc7..c1f5752 100644 --- a/WebApplication1/WebApplication1/Jasmine/spec/SimpleControllerSpec.js +++ b/WebApplication1/WebApplication1/Jasmine/spec/SimpleControllerSpec.js @@ -1,12 +1,7 @@ -/// -/// -/// - -/// -/// +/// describe("controller: simple", function () { - beforeEach(function() { + beforeEach(function () { module("myApp"); // angular.mock.module("app"); }); diff --git a/WebApplication1/WebApplication1/Jasmine/spec/SubControllerSpec.js b/WebApplication1/WebApplication1/Jasmine/spec/SubControllerSpec.js index 0380186..052f8aa 100644 --- a/WebApplication1/WebApplication1/Jasmine/spec/SubControllerSpec.js +++ b/WebApplication1/WebApplication1/Jasmine/spec/SubControllerSpec.js @@ -1,9 +1,4 @@ -/// -/// -/// - -/// -/// +/// describe("controller: sub", function () { beforeEach(function() { diff --git a/WebApplication1/WebApplication1/Jasmine/spec/_tests_references.js b/WebApplication1/WebApplication1/Jasmine/spec/_tests_references.js new file mode 100644 index 0000000..1fdfd81 Binary files /dev/null and b/WebApplication1/WebApplication1/Jasmine/spec/_tests_references.js differ diff --git a/WebApplication1/WebApplication1/Scripts/_references.js b/WebApplication1/WebApplication1/Scripts/_references.js index 4c2633c..c660530 100644 Binary files a/WebApplication1/WebApplication1/Scripts/_references.js and b/WebApplication1/WebApplication1/Scripts/_references.js differ diff --git a/WebApplication1/WebApplication1/Views/Home/ComponentExample.cshtml b/WebApplication1/WebApplication1/Views/Home/ComponentExample.cshtml new file mode 100644 index 0000000..86c1d9e --- /dev/null +++ b/WebApplication1/WebApplication1/Views/Home/ComponentExample.cshtml @@ -0,0 +1,18 @@ +@{ + ViewBag.Title = "Component Example"; +} + +

@ViewBag.Title

+ +
+ +
+
+

Player Info

+

Name: {{player.Name}}

+

Age: {{player.Age}}

+

Hits: {{player.Hits}}

+ + +
+
diff --git a/WebApplication1/WebApplication1/Views/Shared/_Layout.cshtml b/WebApplication1/WebApplication1/Views/Shared/_Layout.cshtml index c3c1d25..2527275 100644 --- a/WebApplication1/WebApplication1/Views/Shared/_Layout.cshtml +++ b/WebApplication1/WebApplication1/Views/Shared/_Layout.cshtml @@ -23,6 +23,7 @@
  • @Html.ActionLink("2", "Controllers", "Home")
  • @Html.ActionLink("3", "DataBindings", "Home")
  • @Html.ActionLink("4", "Services", "Home")
  • +
  • @Html.ActionLink("5", "ComponentExample", "Home")
  • @Html.Partial("_LoginPartial") diff --git a/WebApplication1/WebApplication1/WebApplication1.csproj b/WebApplication1/WebApplication1/WebApplication1.csproj index 3b704dd..304329a 100644 --- a/WebApplication1/WebApplication1/WebApplication1.csproj +++ b/WebApplication1/WebApplication1/WebApplication1.csproj @@ -183,6 +183,8 @@ + + @@ -194,9 +196,11 @@ - + + + @@ -1029,6 +1033,7 @@ + diff --git a/WebApplication1/WebApplication1/dist/App.js b/WebApplication1/WebApplication1/dist/App.js index d962ce3..da91ac2 100644 --- a/WebApplication1/WebApplication1/dist/App.js +++ b/WebApplication1/WebApplication1/dist/App.js @@ -1,5 +1,5 @@ (function () { "use strict"; - angular.module("myApp", []); + angular.module("myApp", ["myApp.player"]); })(); \ No newline at end of file diff --git a/WebApplication1/WebApplication1/dist/ComponentExamplePlayerModule.js b/WebApplication1/WebApplication1/dist/ComponentExamplePlayerModule.js new file mode 100644 index 0000000..9fbf938 --- /dev/null +++ b/WebApplication1/WebApplication1/dist/ComponentExamplePlayerModule.js @@ -0,0 +1,32 @@ +(function () { + "use strict"; + + function playerDirective() { + function linkFn(scope, element, attrs, ctrls, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + + function controllerFn($scope) { + $scope.defaultAttribute = $scope.defaultAttribute || "defaultAttributeValue"; + } + controllerFn.$inject = ["$scope"]; + + return { + restrict: "C", + scope: { + player: "=", + defaultAttribute: "=", + undefinedAttribute: "=", + hit: "&" + }, + transclude: true, + link: linkFn, + controller: controllerFn + }; + } + + angular.module("myApp.player", []) + .directive("playerDirective", playerDirective); +})(); \ No newline at end of file diff --git a/WebApplication1/WebApplication1/dist/ComponentExampleView.js b/WebApplication1/WebApplication1/dist/ComponentExampleView.js new file mode 100644 index 0000000..1488825 --- /dev/null +++ b/WebApplication1/WebApplication1/dist/ComponentExampleView.js @@ -0,0 +1,34 @@ +(function () { + "use strict"; + + function dataService() { + var data = { + players: [ + { + Name: "Player1", + Age: 20, + Hits: 0 + }, + { + Name: "Player2", + Age: 30, + Hits: 0 + } + ] + }; + return data; + } + + function componentExampleController($scope, dataService) { + $scope.model = dataService; + + $scope.hitFn = function (player) { + player.Hits++; + }; + } + componentExampleController.$inject = ["$scope", "dataService"]; + + angular.module("myApp") + .controller("componentExampleController", componentExampleController) + .factory("dataService", dataService); +})(); \ No newline at end of file