Example #1
0
        public void Construct(IResourceResult resourceResult)
        {
            var expectedDuration = 8;
            var expectedSetting  = CacheSetting.NoStore;

            var sut = new CacheControlDecorator(expectedDuration, expectedSetting, resourceResult);

            Assert.Equal(expectedDuration, sut.CacheDuration);
            Assert.Equal(expectedSetting, sut.CacheSetting);
        }
        public void Construct(IResourceResult resourceResult)
        {
            var expectedDuration = 8;
            var expectedSetting = CacheSetting.NoStore;

            var sut = new CacheControlDecorator(expectedDuration, expectedSetting, resourceResult);

            Assert.Equal(expectedDuration, sut.CacheDuration);
            Assert.Equal(expectedSetting, sut.CacheSetting);
        }
        /// <summary>
        /// Get a string from the dictionary.
        /// </summary>
        /// <typeparam name="T">The resource serial type.</typeparam>
        /// <param name="resource">The resource serial.</param>
        /// <param name="culture">The user cutlure.</param>
        /// <returns></returns>
        public IResourceResult <TResourceCode> GetResourceResult <TResourceCode>(TResourceCode resourceCode, CultureInfo culture, params object[] args)
            where TResourceCode : struct, IConvertible
        {
            try
            {
                if (!typeof(TResourceCode).IsEnum)
                {
                    throw new ArgumentException("Le type TResourceCode doit être une énumération.");
                }

                LocalizationUtilityAttribute localizationUtility = EnumHandler.GetCustomAttributeOnType <TResourceCode, LocalizationUtilityAttribute>();

                if (localizationUtility == null)
                {
                    throw new ArgumentException("Le type doit être une ressource de traduction.");
                }

                ResourceCodeDetailsAttribute resourceCodeDetails = EnumHandler.GetCustomAttributeOnValue <TResourceCode, ResourceCodeDetailsAttribute>(resourceCode);
                ResourceManager rm = this.GetResourceManager <TResourceCode>();

                IResourceResult <TResourceCode> resourceResult = null;

                // Set result
                if (resourceCodeDetails.ResourceType == EResourceType.Object)
                {
                    resourceResult = new ResourceResult <TResourceCode>(localizationUtility, resourceCodeDetails, resourceCode, rm.GetObject(resourceCode.ToString()));
                }
                if (resourceCodeDetails.ResourceType == EResourceType.Stream)
                {
                    resourceResult = new ResourceResult <TResourceCode>(localizationUtility, resourceCodeDetails, resourceCode, rm.GetStream(resourceCode.ToString()));
                }
                if (resourceCodeDetails.ResourceType == EResourceType.String)
                {
                    resourceResult = new ResourceResult <TResourceCode>(localizationUtility, resourceCodeDetails, resourceCode, rm.GetString(resourceCode.ToString()), args);
                }

                // Format result
                if (resourceCodeDetails.ResourceType == EResourceType.String &&
                    args != null &&
                    args.Any())
                {
                    resourceResult.StringContent = string.Format(resourceResult.StringContent, args);
                }

                return(resourceResult);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Example #4
0
        public void Execute(IResourceResult resourceResult, IResourceResultContext context)
        {
            var expectedDuration = 8;
            var expectedSetting  = CacheSetting.NoStore;
            var sut = new CacheControlDecorator(expectedDuration, expectedSetting, resourceResult);

            sut.Execute(context);
#if !DEBUG
            var regex = string.Format(@"{0}.+{1}", expectedSetting.ToDescription(), expectedDuration);
            context.FrameworkProvider.Verify(fp => fp.SetHttpResponseHeader("Cache-Control", It.IsRegex(regex)));
#else
            context.FrameworkProvider.Verify(fp => fp.SetHttpResponseHeader("Cache-Control", "no-cache"));
#endif
        }
        public void Execute(IResourceResult resourceResult, IResourceResultContext context)
        {
            var expectedDuration = 8;
            var expectedSetting = CacheSetting.NoStore;
            var sut = new CacheControlDecorator(expectedDuration, expectedSetting, resourceResult);

            sut.Execute(context);
#if !DEBUG
            var regex = string.Format(@"{0}.+{1}", expectedSetting.ToDescription(), expectedDuration);
            context.FrameworkProvider.Verify(fp => fp.SetHttpResponseHeader("Cache-Control", It.IsRegex(regex)));
#else
            context.FrameworkProvider.Verify(fp => fp.SetHttpResponseHeader("Cache-Control", "no-cache"));
#endif
        }
        private void LocalizableLogSubInternal <TResourceCode>(LogLevel level, Exception exception, TResourceCode resourceCode, params object[] args)
            where TResourceCode : struct, IConvertible
        {
            // get localized message
            IResourceResult <TResourceCode> resourceItem = this.ResourceHandler.GetResourceResult <TResourceCode>(resourceCode, Thread.CurrentThread.CurrentCulture, args);

            // create log
            LogEventInfo logEventInfo = LogEventInfo.Create(level, this.Name, exception, null, resourceItem.StringContent, args);

            logEventInfo.Properties.Add("ID", Guid.NewGuid());
            logEventInfo.Properties.Add("ResourceType", typeof(TResourceCode).FullName);
            logEventInfo.Properties.Add("ResourceCode", resourceCode);
            logEventInfo.Properties.Add("Args", args);

            base.Log(typeof(LocalizableLogHandler), logEventInfo);

            this.dbLogger.Create(logEventInfo);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheControlDecorator" /> class.
 /// </summary>
 /// <param name="cacheDuration">Duration of the cache.</param>
 /// <param name="cacheSetting">The cache setting.</param>
 /// <param name="wrappedResourceResult">The wrapped resource result.</param>
 public CacheControlDecorator(long cacheDuration, CacheSetting?cacheSetting, IResourceResult wrappedResourceResult) : base(wrappedResourceResult)
 {
     CacheDuration = cacheDuration;
     CacheSetting  = cacheSetting;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheControlDecorator" /> class.
 /// </summary>
 /// <param name="wrappedResourceResult">The wrapped resource result.</param>
 public CacheControlDecorator(IResourceResult wrappedResourceResult) : this(NoCaching, null, wrappedResourceResult)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheControlDecorator" /> class.
 /// </summary>
 /// <param name="cacheDuration">Duration of the cache.</param>
 /// <param name="cacheSetting">The cache setting.</param>
 /// <param name="wrappedResourceResult">The wrapped resource result.</param>
 public CacheControlDecorator(long cacheDuration, CacheSetting? cacheSetting, IResourceResult wrappedResourceResult)
     : base(wrappedResourceResult)
 {
     CacheDuration = cacheDuration;
     CacheSetting = cacheSetting;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheControlDecorator" /> class.
 /// </summary>
 /// <param name="wrappedResourceResult">The wrapped resource result.</param>
 public CacheControlDecorator(IResourceResult wrappedResourceResult)
     : this(NoCaching, null, wrappedResourceResult)
 {
 }
Example #11
0
        public void ExecuteWrappedResource([Frozen] IResourceResult resourceResult, CacheControlDecorator sut, IResourceResultContext context)
        {
            sut.Execute(context);

            resourceResult.Verify(rr => rr.Execute(It.IsAny <IResourceResultContext>()));
        }
Example #12
0
        public void ConstructWithDefaults(IResourceResult resourceResult)
        {
            var sut = new CacheControlDecorator(resourceResult);

            Assert.False(sut.CacheSetting.HasValue);
        }
        public void ConstructWithDefaults(IResourceResult resourceResult)
        {
            var sut = new CacheControlDecorator(resourceResult);

            Assert.False(sut.CacheSetting.HasValue);
        }