diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs
index 46c87378bb..da0c7c59de 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ActivatorTests.cs
@@ -65,6 +65,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
[Fact]
public async Task ViewActivator_ActivatesDefaultInjectedProperties()
{
+ // Arrange
var server = TestServer.Create(_provider, _app);
var client = server.CreateClient();
var expected = @" world! /View/ConsumeServicesFromBaseType";
@@ -79,6 +80,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
[Fact]
public async Task ViewActivator_ActivatesAndContextualizesInjectedServices()
{
+ // Arrange
var server = TestServer.Create(_provider, _app);
var client = server.CreateClient();
var expected = "4 test-value";
@@ -93,10 +95,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
[Fact]
public async Task ViewActivator_ActivatesServicesFromBaseType()
{
+ // Arrange
var server = TestServer.Create(_provider, _app);
var client = server.CreateClient();
- var expected =
-@"/content/scripts/test.js";
+ var expected = @"/content/scripts/test.js";
// Act
var body = await client.GetStringAsync("http://localhost/View/ConsumeServicesFromBaseType");
@@ -104,5 +106,65 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Assert
Assert.Equal(expected, body.Trim());
}
+
+ [Fact]
+ public async Task ViewComponentActivator_ActivatesProperties()
+ {
+ // Arrange
+ var server = TestServer.Create(_provider, _app);
+ var client = server.CreateClient();
+ var expected = @"Random Number:4";
+
+ // Act
+ var body = await client.GetStringAsync("http://localhost/View/ConsumeViewComponent");
+
+ // Assert
+ Assert.Equal(expected, body.Trim());
+ }
+
+ [Fact]
+ public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem()
+ {
+ // Arrange
+ var server = TestServer.Create(_provider, _app);
+ var client = server.CreateClient();
+ var expected = "test-value";
+
+ // Act
+ var body = await client.GetStringAsync("http://localhost/View/ConsumeValueComponent?test=test-value");
+
+ // Assert
+ Assert.Equal(expected, body.Trim());
+ }
+
+ [Fact]
+ public async Task ViewComponentActivator_ActivatesPropertiesAndContextualizesThem_WhenMultiplePropertiesArePresent()
+ {
+ // Arrange
+ var server = TestServer.Create(_provider, _app);
+ var client = server.CreateClient();
+ var expected = "Random Number:4 test-value";
+
+ // Act
+ var body = await client.GetStringAsync("http://localhost/View/ConsumeViewAndValueComponent?test=test-value");
+
+ // Assert
+ Assert.Equal(expected, body.Trim());
+ }
+
+ [Fact]
+ public async Task ViewComponentThatCannotBeActivated_ThrowsWhenAttemptedToBeInvoked()
+ {
+ // Arrange
+ var server = TestServer.Create(_provider, _app);
+ var client = server.CreateClient();
+ var expectedMessage = "TODO: No service for type 'ActivatorWebSite.CannotBeActivatedComponent+FakeType' " +
+ "has been registered.";
+
+ // Act & Assert
+ var ex = await Assert.ThrowsAsync(
+ () => client.GetAsync("http://localhost/View/ConsumeCannotBeActivatedComponent"));
+ Assert.Equal(expectedMessage, ex.Message);
+ }
}
}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Components/CannotBeActivatedComponent.cs b/test/WebSites/ActivatorWebSite/Components/CannotBeActivatedComponent.cs
new file mode 100644
index 0000000000..a3ab11f3ea
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Components/CannotBeActivatedComponent.cs
@@ -0,0 +1,23 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using Microsoft.AspNet.Mvc;
+
+namespace ActivatorWebSite
+{
+ [ViewComponent(Name = "CannotBeActivated")]
+ public class CannotBeActivatedComponent : ViewComponent
+ {
+ [Activate]
+ private FakeType Service { get; set; }
+
+ public IViewComponentResult Invoke()
+ {
+ return Content("Test");
+ }
+
+ private sealed class FakeType
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Components/NumberComponent.cs b/test/WebSites/ActivatorWebSite/Components/NumberComponent.cs
new file mode 100644
index 0000000000..e3ca8fa851
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Components/NumberComponent.cs
@@ -0,0 +1,19 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using Microsoft.AspNet.Mvc;
+
+namespace ActivatorWebSite
+{
+ [ViewComponent(Name = "Number")]
+ public class NumberComponent : ViewComponent
+ {
+ [Activate]
+ public MyService MyTestService { get; set; }
+
+ public IViewComponentResult Invoke(string content)
+ {
+ return Content(content + ":" + MyTestService.Random);
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Components/ValueComponent.cs b/test/WebSites/ActivatorWebSite/Components/ValueComponent.cs
new file mode 100644
index 0000000000..0aa2c55810
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Components/ValueComponent.cs
@@ -0,0 +1,19 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using Microsoft.AspNet.Mvc;
+
+namespace ActivatorWebSite
+{
+ [ViewComponent(Name ="Value")]
+ public class ValueComponent : ViewComponent
+ {
+ [Activate]
+ public ViewService MyViewService { get; set; }
+
+ public IViewComponentResult Invoke()
+ {
+ return Content(MyViewService.GetValue());
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Components/ViewAndValueComponent.cs b/test/WebSites/ActivatorWebSite/Components/ViewAndValueComponent.cs
new file mode 100644
index 0000000000..b27ffd1d30
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Components/ViewAndValueComponent.cs
@@ -0,0 +1,22 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using Microsoft.AspNet.Mvc;
+
+namespace ActivatorWebSite
+{
+ [ViewComponent(Name = "ViewAndValue")]
+ public class ViewAndValueComponent : ViewComponent
+ {
+ [Activate]
+ public MyService MySampleService { get; set; }
+
+ [Activate]
+ public ViewService MyViewService { get; set; }
+
+ public IViewComponentResult Invoke(string content)
+ {
+ return Content(content + ":" + MySampleService.Random + " " + MyViewService.GetValue());
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Controllers/ViewController.cs b/test/WebSites/ActivatorWebSite/Controllers/ViewController.cs
index 2dfbdefa68..aa9208c3dd 100644
--- a/test/WebSites/ActivatorWebSite/Controllers/ViewController.cs
+++ b/test/WebSites/ActivatorWebSite/Controllers/ViewController.cs
@@ -24,5 +24,25 @@ namespace ActivatorWebSite
{
return View();
}
+
+ public ViewResult ConsumeViewComponent()
+ {
+ return View();
+ }
+
+ public ViewResult ConsumeValueComponent()
+ {
+ return View();
+ }
+
+ public ViewResult ConsumeViewAndValueComponent()
+ {
+ return View();
+ }
+
+ public ViewResult ConsumeCannotBeActivatedComponent()
+ {
+ return View();
+ }
}
}
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Views/View/ConsumeCannotBeActivatedComponent.cshtml b/test/WebSites/ActivatorWebSite/Views/View/ConsumeCannotBeActivatedComponent.cshtml
new file mode 100644
index 0000000000..ecfed37d72
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Views/View/ConsumeCannotBeActivatedComponent.cshtml
@@ -0,0 +1 @@
+@Component.Invoke("CannotBeActivated")
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Views/View/ConsumeValueComponent.cshtml b/test/WebSites/ActivatorWebSite/Views/View/ConsumeValueComponent.cshtml
new file mode 100644
index 0000000000..7faf0f4679
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Views/View/ConsumeValueComponent.cshtml
@@ -0,0 +1 @@
+@Component.Invoke("Value")
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewAndValueComponent.cshtml b/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewAndValueComponent.cshtml
new file mode 100644
index 0000000000..a3edd15e7f
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewAndValueComponent.cshtml
@@ -0,0 +1 @@
+@Component.Invoke("ViewAndValue", "Random Number")
\ No newline at end of file
diff --git a/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewComponent.cshtml b/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewComponent.cshtml
new file mode 100644
index 0000000000..139735af1f
--- /dev/null
+++ b/test/WebSites/ActivatorWebSite/Views/View/ConsumeViewComponent.cshtml
@@ -0,0 +1 @@
+@Component.Invoke("Number", "Random Number")
\ No newline at end of file