Esempio n. 1
0
        public void Add_GuardClauses()
        {
            // Arrange
            var config          = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(
                () => defaultServices.Add(serviceType: null, service: new object()),
                "serviceType"
                );
            Assert.ThrowsArgumentNull(
                () => defaultServices.Add(typeof(object), service: null),
                "service"
                );
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(object), new object()),
                "serviceType",
                "The service type Object is not supported."
                );
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(IHttpActionInvoker), new object()),
                "service",
                "The type Object must derive from IHttpActionInvoker."
                );
        }
Esempio n. 2
0
        public void Add_AddsServiceToEndOfServicesList()
        {
            // Arrange
            var config          = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider  = new Mock <IFilterProvider>().Object;
            IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.Add(typeof(IFilterProvider), filterProvider);

            // Assert
            IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));

            Assert.Equal(servicesBefore.Concat(new[] { filterProvider }), servicesAfter);
        }
        public void Add_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(() => defaultServices.Add(serviceType: null, service: new object()), "serviceType");
            Assert.ThrowsArgumentNull(() => defaultServices.Add(typeof(object), service: null), "service");
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(object), new object()),
                "serviceType",
                "The service type Object is not supported.");
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(IHttpActionInvoker), new object()),
                "service",
                "The type Object must derive from IHttpActionInvoker.");
        }
        public void Add_AddsServiceToEndOfServicesList()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider = new Mock<IFilterProvider>().Object;
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.Add(typeof(IFilterProvider), filterProvider);

            // Assert
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
            Assert.Equal(servicesBefore.Concat(new[] { filterProvider }), servicesAfter);
        }