public void MapRoute3WithNameSpaces()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();

            //string[] namespaces = new string[] { "nsA.nsB.nsC", "ns1.ns2.ns3" };

            // Act
            routes.MapRoute("RouteName", "SomeUrl", _nameSpaces);

            // Assert
            Route route = Assert.Single(routes.Cast <Route>());

            Assert.NotNull(route);
            Assert.NotNull(route.DataTokens);
            Assert.NotNull(route.DataTokens["Namespaces"]);
            string[] routeNameSpaces = route.DataTokens["Namespaces"] as string[];
            Assert.Equal(routeNameSpaces.Length, 2);
            Assert.Same(route, routes["RouteName"]);
            Assert.Same(routeNameSpaces, _nameSpaces);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType <MvcRouteHandler>(route.RouteHandler);
            Assert.Empty(route.Defaults);
            Assert.Empty(route.Constraints);
        }
Exemplo n.º 2
0
        public static void TestEvent <TEventArgs>(object instance, string eventName, TEventArgs eventArgs) where TEventArgs : EventArgs
        {
            EventInfo eventInfo = GetEventInfo(instance, eventName);

            // Assert category "Action"
            TestAttribute(eventInfo, new CategoryAttribute("Action"));

            // Call protected method with no event handlers, assert no error
            MethodInfo methodInfo = GetMethodInfo(instance, "On" + eventName, attrs: MethodAttributes.Family | MethodAttributes.Virtual);

            methodInfo.Invoke(instance, new object[] { eventArgs });

            // Attach handler, call method, assert fires once
            List <object>             eventHandlerArgs = new List <object>();
            EventHandler <TEventArgs> handler          = new EventHandler <TEventArgs>(delegate(object sender, TEventArgs t)
            {
                eventHandlerArgs.Add(sender);
                eventHandlerArgs.Add(t);
            });

            eventInfo.AddEventHandler(instance, handler);
            methodInfo.Invoke(instance, new object[] { eventArgs });
            Assert.Equal(new[] { instance, eventArgs }, eventHandlerArgs.ToArray());

            // Detach handler, call method, assert not fired
            eventHandlerArgs = new List <object>();
            eventInfo.RemoveEventHandler(instance, handler);
            methodInfo.Invoke(instance, new object[] { eventArgs });
            Assert.Empty(eventHandlerArgs);
        }
        public void Validate_SkipsValidationIfSuppressed()
        {
            // Arrange
            List <string>             log           = new List <string>();
            LoggingDataErrorInfoModel model         = new LoggingDataErrorInfoModel(log);
            ModelMetadata             modelMetadata = GetModelMetadata(model);

            ControllerContext controllerContext = new ControllerContext
            {
                Controller = new EmptyController()
            };
            ModelValidationNode node = new ModelValidationNode(modelMetadata, "theKey")
            {
                SuppressValidation = true
            };

            node.Validating += (sender, e) => { log.Add("In OnValidating()"); };
            node.Validated  += delegate { log.Add("In OnValidated()"); };

            // Act
            node.Validate(controllerContext);

            // Assert
            Assert.Empty(log);
        }
        public void NonAliasedMethodsProperty()
        {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);

            // Act
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Assert
            Assert.Equal(6, selector.NonAliasedMethods.Count);

            List <MethodInfo> sortedMethods = selector.NonAliasedMethods["foo"].OrderBy(methodInfo => methodInfo.GetParameters().Length).ToList();

            Assert.Equal("Foo", sortedMethods[0].Name);
            Assert.Empty(sortedMethods[0].GetParameters());
            Assert.Equal("Foo", sortedMethods[1].Name);
            Assert.Equal(typeof(string), sortedMethods[1].GetParameters()[0].ParameterType);

            Assert.Equal(1, selector.NonAliasedMethods["EventPattern"].Count());
            Assert.Equal("EventPatternAsync", selector.NonAliasedMethods["EventPattern"].First().Name);
            Assert.Equal(1, selector.NonAliasedMethods["EventPatternAmbiguous"].Count());
            Assert.Equal("EventPatternAmbiguousAsync", selector.NonAliasedMethods["EventPatternAmbiguous"].First().Name);
            Assert.Equal(1, selector.NonAliasedMethods["EventPatternWithoutCompletionMethod"].Count());
            Assert.Equal("EventPatternWithoutCompletionMethodAsync", selector.NonAliasedMethods["EventPatternWithoutCompletionMethod"].First().Name);

            Assert.Equal(1, selector.NonAliasedMethods["TaskPattern"].Count());
            Assert.Equal("TaskPattern", selector.NonAliasedMethods["TaskPattern"].First().Name);
            Assert.Equal(1, selector.NonAliasedMethods["GenericTaskPattern"].Count());
            Assert.Equal("GenericTaskPattern", selector.NonAliasedMethods["GenericTaskPattern"].First().Name);
        }
Exemplo n.º 5
0
        public void MapRoute5WithDefaultsAndConstraintsAsDictionary()
        {
            // Arrange
            RouteCollection routes   = new RouteCollection();
            var             defaults = new Dictionary <string, object> {
                { "Foo", "DefaultFoo" }
            };
            var constraints = new Dictionary <string, object> {
                { "Foo", "ConstraintFoo" }
            };

            // Act
            routes.MapRoute("RouteName", "SomeUrl", defaults, constraints);

            // Assert
            Route route = Assert.Single(routes.Cast <Route>());

            Assert.NotNull(route);
            Assert.Same(route, routes["RouteName"]);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType <MvcRouteHandler>(route.RouteHandler);
            Assert.Equal("DefaultFoo", route.Defaults["Foo"]);
            Assert.Equal("ConstraintFoo", route.Constraints["Foo"]);
            Assert.Empty(route.DataTokens);
        }
Exemplo n.º 6
0
            public void TestCopyTo()
            {
                // Arrange
                IDictionary <TKey, TValue> controlDictionary = new Dictionary <TKey, TValue>(Comparer);
                IDictionary <TKey, TValue> testDictionary    = Creator();

                foreach (var entry in MakeKeyValuePairs())
                {
                    controlDictionary.Add(entry.Key, entry.Value);
                    testDictionary.Add(entry.Key, entry.Value);
                }
                KeyValuePair <TKey, TValue>[] testKvps = new KeyValuePair <TKey, TValue> [testDictionary.Count + 2];

                // Act
                testDictionary.CopyTo(testKvps, 2);

                // Assert
                for (int i = 0; i < 2; i++)
                {
                    var defaultValue = default(KeyValuePair <TKey, TValue>);
                    var entry        = testKvps[i];
                    Assert.Equal(defaultValue, entry);
                }
                for (int i = 2; i < testKvps.Length; i++)
                {
                    var entry = testKvps[i];
                    Assert.True(controlDictionary.Contains(entry), String.Format("The value '{0}' wasn't present in the control dictionary.", entry));
                    controlDictionary.Remove(entry);
                }

                Assert.Empty(controlDictionary);
            }
        public void DefaultConstructor()
        {
            // Act
            ModelBinderProviderCollection collection = new ModelBinderProviderCollection();

            // Assert
            Assert.Empty(collection);
        }
Exemplo n.º 8
0
        public void GetValidatorsReturnsNothingForValidModel()
        {
            InvalidModelValidatorProvider validatorProvider = new InvalidModelValidatorProvider();

            IEnumerable <ModelValidator> validators = validatorProvider.GetValidators(_metadataProvider.GetMetadataForType(null, typeof(ValidModel)), _noValidatorProviders);

            Assert.Empty(validators);
        }
Exemplo n.º 9
0
        public void DefaultConstructor()
        {
            // Act
            ValueProviderFactoryCollection collection = new ValueProviderFactoryCollection();

            // Assert
            Assert.Empty(collection);
        }
        public void DefaultConstructor()
        {
            // Act
            ViewEngineCollection collection = new ViewEngineCollection();

            // Assert
            Assert.Empty(collection);
        }
        public void Clear_RemovesAllValuesFromAspNetRouteCollection()
        {
            _aspNetRoutes.Add(new Mock <RouteBase>().Object);

            _webApiRoutes.Clear();

            Assert.Empty(_aspNetRoutes);
        }
Exemplo n.º 12
0
 private static void VerifyCommonDefaults(RazorEngineHost host)
 {
     Assert.Equal(GeneratedClassContext.Default, host.GeneratedClassContext);
     Assert.Empty(host.NamespaceImports);
     Assert.False(host.DesignTimeMode);
     Assert.Equal(RazorEngineHost.InternalDefaultClassName, host.DefaultClassName);
     Assert.Equal(RazorEngineHost.InternalDefaultNamespace, host.DefaultNamespace);
 }
Exemplo n.º 13
0
        public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary()
        {
            // Arrange
            var valueProvider = new NameValueCollectionValueProvider(_backingStore, null);

            // Act
            IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("abc");

            // Assert
            Assert.Empty(result);
        }
Exemplo n.º 14
0
        public void ConstructorWithNullValuesDictionary()
        {
            // Act
            var result = new RedirectToRouteResult(routeValues: null);

            // Assert
            Assert.NotNull(result.RouteValues);
            Assert.Empty(result.RouteValues);
            Assert.Equal(String.Empty, result.RouteName);
            Assert.False(result.Permanent);
        }
Exemplo n.º 15
0
        public void GetCustomAttributesReturnsEmptyArrayOfAttributeType()
        {
            // Arrange
            ControllerDescriptor cd = GetControllerDescriptor();

            // Act
            ObsoleteAttribute[] attrs = (ObsoleteAttribute[])cd.GetCustomAttributes(typeof(ObsoleteAttribute), true);

            // Assert
            Assert.Empty(attrs);
        }
Exemplo n.º 16
0
        public void Load_NullSession_ReturnsEmptyDictionary()
        {
            // Arrange
            SessionStateTempDataProvider testProvider = new SessionStateTempDataProvider();

            // Act
            IDictionary <string, object> tempDataDictionary = testProvider.LoadTempData(GetControllerContext());

            // Assert
            Assert.Empty(tempDataDictionary);
        }
        public void RemoveDeletesFilterByInstance()
        {
            // Arrange
            _collection.Add(_filterInstance);

            // Act
            _collection.Remove(_filterInstance);

            // Assert
            Assert.Empty(_collection);
        }
        public void GetCustomAttributesReturnsEmptyArrayOfAttributeType()
        {
            // Arrange
            ActionDescriptor ad = GetActionDescriptor();

            // Act
            ObsoleteAttribute[] attrs = (ObsoleteAttribute[])ad.GetCustomAttributes(typeof(ObsoleteAttribute), true);

            // Assert
            Assert.Empty(attrs);
        }
        public void Contents_IsEmpty()
        {
            // Arrange
            TProvider provider = new TProvider();

            // Act
            Collection <HttpContent> contents = provider.Contents;

            // Assert
            Assert.Empty(contents);
        }
        public void ClientModelValidator_Validate_ReturnsEmptyCollection()
        {
            // Arrange
            ModelMetadata metadata  = _metadataProvider.GetMetadataForType(null, typeof(object));
            var           validator = new ClientDataTypeModelValidatorProvider.ClientModelValidator(metadata, new ControllerContext(), "testValidationType", "testErrorMessage");

            // Act
            IEnumerable <ModelValidationResult> result = validator.Validate(null);

            // Assert
            Assert.Empty(result);
        }
Exemplo n.º 21
0
        public void FieldValidatorsProperty()
        {
            // Arrange
            FormContext context = new FormContext();

            // Act
            IDictionary <String, FieldValidationMetadata> fieldValidators = context.FieldValidators;

            // Assert
            Assert.NotNull(fieldValidators);
            Assert.Empty(fieldValidators);
        }
        public void GetSelectorsReturnsEmptyCollection()
        {
            // Arrange
            ActionDescriptor ad = GetActionDescriptor();

            // Act
            ICollection <ActionSelector> selectors = ad.GetSelectors();

            // Assert
            Assert.IsType <ActionSelector[]>(selectors);
            Assert.Empty(selectors);
        }
Exemplo n.º 23
0
        public void GetKeysFromPrefix_PrefixNotFound()
        {
            // Arrange
            var    container = new PrefixContainer(new[] { "foo[bar]", "something[other]", "foo.baz", "foot[hello]", "fo[nothing]", "foo" });
            string prefix    = "notfound";

            // Act
            IDictionary <string, string> result = container.GetKeysFromPrefix(prefix);

            // Assert
            Assert.Empty(result);
        }
Exemplo n.º 24
0
        public void NoClientRulesByDefault()
        {
            // Arrange
            ModelMetadata     metadata = ModelMetadataProviders.Current.GetMetadataForProperty(() => 15, typeof(string), "Length");
            ControllerContext context  = new ControllerContext();

            // Act
            TestableModelValidator validator = new TestableModelValidator(metadata, context);

            // Assert
            Assert.Empty(validator.GetClientValidationRules());
        }
        public void ClassWithDataMemberIsRequiredTrueWithoutDataContract_NoValidator()
        {
            // Arrange
            var provider = new DataMemberModelValidatorProvider();
            var metadata = _metadataProvider.GetMetadataForProperty(() => null, typeof(ClassWithDataMemberIsRequiredTrueWithoutDataContract), "TheProperty");

            // Act
            IEnumerable <ModelValidator> validators = provider.GetValidators(metadata, new[] { provider });

            // Assert
            Assert.Empty(validators);
        }
        public void ReferenceTypesDontGetImplicitRequiredAttribute()
        {
            // Arrange
            var provider = new DataAnnotationsModelValidatorProvider();
            var context  = new ControllerContext();
            var metadata = ModelMetadataProviders.Current.GetMetadataForType(() => null, typeof(string));

            // Act
            IEnumerable <ModelValidator> validators = provider.GetValidators(metadata, context);

            // Assert
            Assert.Empty(validators);
        }
        public void IValidatableObjectWhichIsNullReturnsNoErrors()
        {
            // Arrange
            var context   = new ControllerContext();
            var metadata  = ModelMetadataProviders.Current.GetMetadataForType(() => null, typeof(IValidatableObject));
            var validator = new ValidatableObjectAdapter(metadata, context);

            // Act
            IEnumerable <ModelValidationResult> results = validator.Validate(null);

            // Assert
            Assert.Empty(results);
        }
        public void IncludePropertyReturnsEmptyArrayIfNoBindAttributeSpecified()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasNoBindAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection <string> includes = bindingInfo.Include;

            // Assert
            Assert.NotNull(includes);
            Assert.Empty(includes);
        }
Exemplo n.º 29
0
        public void DisposeRequestResources_WhenResourceListExists_DisposesResourceAndClearsReferences()
        {
            var list = new List <IDisposable> {
                _disposable
            };

            _request.Properties[HttpPropertyKeys.DisposableRequestResourcesKey] = list;

            _request.DisposeRequestResources();

            _disposableMock.Verify(d => d.Dispose());
            Assert.Empty(list);
        }
Exemplo n.º 30
0
        public void RouteDataPropertyReturnsEmptyRouteDataIfRequestContextNotPresent()
        {
            // Arrange
            ControllerContext controllerContext = new ControllerContext();

            // Act
            RouteData routeData  = controllerContext.RouteData;
            RouteData routeData2 = controllerContext.RouteData;

            // Assert
            Assert.Equal(routeData, routeData2);
            Assert.Empty(routeData.Values);
        }