예제 #1
0
        public void Initialize_Initializes_SerializerSettings()
        {
            // Arrange
            var attr     = new MobileAppControllerAttribute();
            var settings = new HttpControllerSettings(this.nullConfig);

            // Act
            attr.Initialize(settings, null);

            // Assert
            // Verify SerializerSettings are set up as we expect
            var serializerSettings = settings.Formatters.JsonFormatter.SerializerSettings;

            Assert.Equal(typeof(ServiceContractResolver), serializerSettings.ContractResolver.GetType());
            Assert.Equal(DefaultValueHandling.Include, serializerSettings.DefaultValueHandling);
            Assert.Equal(NullValueHandling.Include, serializerSettings.NullValueHandling);

            // Verify Converters
            var stringEnumConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(StringEnumConverter)) as StringEnumConverter;

            Assert.False(stringEnumConverter.CamelCaseText);

            var isoDateTimeConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(IsoDateTimeConverter)) as IsoDateTimeConverter;

            Assert.Equal(DateTimeStyles.AdjustToUniversal, isoDateTimeConverter.DateTimeStyles);
            Assert.Equal("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFZ", isoDateTimeConverter.DateTimeFormat);
            Assert.Equal(CultureInfo.InvariantCulture, isoDateTimeConverter.Culture);

            Assert.NotSame(this.nullConfig.Formatters.JsonFormatter.SerializerSettings.ContractResolver, settings.Formatters.JsonFormatter.SerializerSettings.ContractResolver);
            Assert.Same(settings.Formatters.JsonFormatter, settings.Formatters[0]);
        }
예제 #2
0
        public void HasCachingHeaders_ReturnsTrueWhenCacheControlOrExpiresIsPresent(HttpResponseMessage response, bool expected)
        {
            // Act
            bool actual = MobileAppControllerAttribute.HasCachingHeaders(response);

            // Assert
            Assert.Equal(expected, actual);
        }
예제 #3
0
        public void IsCacheableMethod_ReturnsTrueForCacheableMethods(HttpMethod method, bool expected)
        {
            // Act
            bool actual = MobileAppControllerAttribute.IsCacheableMethod(method);

            // Assert
            Assert.Equal(expected, actual);
        }
예제 #4
0
        public void SetVersionHeader_SetsVersionHeader()
        {
            // Arrange
            HttpResponseMessage response = new HttpResponseMessage();
            Assembly            asm      = typeof(MobileAppControllerAttribute).Assembly;
            string expected = "net-" + AssemblyUtils.GetExecutingAssemblyFileVersionOrDefault(asm);

            // Act
            MobileAppControllerAttribute.SetVersionHeader(response);
            string actual = response.Headers.GetValues("x-zumo-server-version").Single();

            // Assert
            Assert.Equal(expected, actual);
        }
        public MobileAppControllerAttributeTests()
        {
            this.providerMock = new Mock<ICachePolicyProvider>();
            this.config = new HttpConfiguration();
            this.config.SetCachePolicyProvider(this.providerMock.Object);

            this.request = new HttpRequestMessage();
            this.mobileAppControllerAttr = new MobileAppControllerAttribute();
            this.actionExecutedContext = new HttpActionExecutedContext();
            this.controllerContext = new HttpControllerContext();
            this.controllerContext.Configuration = this.nullConfig;
            this.controllerContext.Request = this.request;
            this.actionContext = new HttpActionContext();
            this.actionContext.ControllerContext = this.controllerContext;
            this.actionExecutedContext.ActionContext = this.actionContext;
        }
예제 #6
0
        public MobileAppControllerAttributeTests()
        {
            this.providerMock = new Mock <ICachePolicyProvider>();
            this.config       = new HttpConfiguration();
            this.config.SetCachePolicyProvider(this.providerMock.Object);

            this.request = new HttpRequestMessage();
            this.mobileAppControllerAttr         = new MobileAppControllerAttribute();
            this.actionExecutedContext           = new HttpActionExecutedContext();
            this.controllerContext               = new HttpControllerContext();
            this.controllerContext.Configuration = this.nullConfig;
            this.controllerContext.Request       = this.request;
            this.actionContext = new HttpActionContext();
            this.actionContext.ControllerContext     = this.controllerContext;
            this.actionExecutedContext.ActionContext = this.actionContext;
        }
예제 #7
0
        public void Initialize_CallsRegisteredConfigProvider()
        {
            // Arrange
            var httpConfig         = new HttpConfiguration();
            var mockConfigProvider = new Mock <IMobileAppControllerConfigProvider>();

            httpConfig.SetMobileAppControllerConfigProvider(mockConfigProvider.Object);
            var attr       = new MobileAppControllerAttribute();
            var settings   = new HttpControllerSettings(httpConfig);
            var descriptor = new HttpControllerDescriptor()
            {
                Configuration = httpConfig
            };

            // Act
            attr.Initialize(settings, descriptor);

            // Assert
            mockConfigProvider.Verify(m => m.Configure(settings, descriptor), Times.Once);
        }
        public void Initialize_Initializes_SerializerSettings()
        {
            // Arrange
            var attr = new MobileAppControllerAttribute();
            var settings = new HttpControllerSettings(this.nullConfig);

            // Act
            attr.Initialize(settings, null);

            // Assert
            // Verify SerializerSettings are set up as we expect
            var serializerSettings = settings.Formatters.JsonFormatter.SerializerSettings;
            Assert.Equal(typeof(ServiceContractResolver), serializerSettings.ContractResolver.GetType());
            Assert.Equal(DefaultValueHandling.Include, serializerSettings.DefaultValueHandling);
            Assert.Equal(NullValueHandling.Include, serializerSettings.NullValueHandling);

            // Verify Converters
            var stringEnumConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(StringEnumConverter)) as StringEnumConverter;
            Assert.True(stringEnumConverter.CamelCaseText);

            var isoDateTimeConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(IsoDateTimeConverter)) as IsoDateTimeConverter;
            Assert.Equal(DateTimeStyles.AdjustToUniversal, isoDateTimeConverter.DateTimeStyles);
            Assert.Equal("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFZ", isoDateTimeConverter.DateTimeFormat);
            Assert.Equal(CultureInfo.InvariantCulture, isoDateTimeConverter.Culture);

            Assert.NotSame(this.nullConfig.Formatters.JsonFormatter.SerializerSettings.ContractResolver, settings.Formatters.JsonFormatter.SerializerSettings.ContractResolver);
            Assert.Same(settings.Formatters.JsonFormatter, settings.Formatters[0]);
        }
        public void Initialize_CallsRegisteredConfigProvider()
        {
            // Arrange
            var httpConfig = new HttpConfiguration();
            var mockConfigProvider = new Mock<IMobileAppControllerConfigProvider>();
            httpConfig.SetMobileAppControllerConfigProvider(mockConfigProvider.Object);
            var attr = new MobileAppControllerAttribute();
            var settings = new HttpControllerSettings(httpConfig);
            var descriptor = new HttpControllerDescriptor()
            {
                Configuration = httpConfig
            };

            // Act
            attr.Initialize(settings, descriptor);

            // Assert
            mockConfigProvider.Verify(m => m.Configure(settings, descriptor), Times.Once);
        }