// 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 System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.OptionDescriptors; using Microsoft.Framework.OptionsModel; using Moq; using Xunit; namespace Microsoft.AspNet.Mvc.Razor.OptionDescriptors { public class DefaultViewLocationExpanderProviderTest { [Fact] public void ViewLocationExpanders_ReturnsActivatedListOfExpanders() { // Arrange var service = Mock.Of(); var expander = Mock.Of(); var type = typeof(TestViewLocationExpander); var serviceProvider = new Mock(); serviceProvider.Setup(p => p.GetService(typeof(ITestService))) .Returns(service); var typeActivatorCache = new DefaultTypeActivatorCache(); var options = new RazorViewEngineOptions(); options.ViewLocationExpanders.Add(type); options.ViewLocationExpanders.Add(expander); var accessor = new Mock>(); accessor.SetupGet(a => a.Options) .Returns(options); var provider = new DefaultViewLocationExpanderProvider(accessor.Object, typeActivatorCache, serviceProvider.Object); // Act var result = provider.ViewLocationExpanders; // Assert Assert.Equal(2, result.Count); var testExpander = Assert.IsType(result[0]); Assert.Same(service, testExpander.Service); Assert.Same(expander, result[1]); } private class TestViewLocationExpander : IViewLocationExpander { public TestViewLocationExpander(ITestService service) { Service = service; } public ITestService Service { get; private set; } public IEnumerable ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable viewLocations) { throw new NotImplementedException(); } public void PopulateValues(ViewLocationExpanderContext context) { throw new NotImplementedException(); } } public interface ITestService { } } }