コード例 #1
0
 internal static bool CheckFooBarEquality(Foobar source, Foobar retrieved, bool shouldBeEqual = true)
 {
     if (shouldBeEqual)
     {
         Assert.Equal(source.Foo, retrieved.Foo);
         if (source.Bar == 0 && retrieved.Bar == 0)
         {
             Assert.Equal(source.Bar, retrieved.Bar);
         }
         else
         {
             Assert.NotEqual(source.Bar, retrieved.Bar);
         }
         Assert.Equal(default(int), retrieved.Bar);
     }
     else
     {
         Assert.NotEqual(source.Foo, retrieved.Foo);
         if (source.Bar == 0 && retrieved.Bar == 0)
         {
             Assert.Equal(source.Bar, retrieved.Bar);
         }
         else
         {
             Assert.NotEqual(source.Bar, retrieved.Bar);
         }
         Assert.Equal(default(int), retrieved.Bar);
     }
     return(true);
 }
コード例 #2
0
        public void TestEnumerators(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable = RedisHelpers.GetCachableObject();

            string cachableKey = RedisHelpers.CachableKey;

            service.Cache(cachableKey, cachable);

            IEnumerator <KeyValuePair <string, ICachedObjectBasic> > typedEnumerator
                = service.GetEnumerator();
            IEnumerator enumerator = ((IEnumerable)service).GetEnumerator();

            typedEnumerator.MoveNext();
            enumerator.MoveNext();

            Foobar returned = RedisHelpers.SerializationService.DeserializeObject <Foobar>(
                (string)((ICachedObjectBasic)(typedEnumerator.Current).Value).UntypedValue, RedisHelpers.SerializationSettings);

            Assert.NotNull(returned);
            Assert.NotEqual(cachable, returned);
            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, returned));

            Foobar returned2 = RedisHelpers.SerializationService.DeserializeObject <Foobar>(
                (string)((ICachedObjectBasic)((KeyValuePair <string, ICachedObjectBasic>)
                                                  (enumerator.Current)).Value).UntypedValue, RedisHelpers.SerializationSettings);

            Assert.NotNull(returned2);
            Assert.NotEqual(cachable, returned2);
            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, returned2));
        }
コード例 #3
0
    public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
    {
        var result = base.Validate(validationContext).ToList();

        result.AddRange(Foobar.Validate(validationContext));
        return(result);
    }
コード例 #4
0
    public TResult Interact <TResult> (Func <Foobar, TResult> lambdaCode)
    {
        var x = new Foobar();

        Initialize(x);     //or whatever
        return(lambdaCode(x));
    }
コード例 #5
0
        public void Caching(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable = RedisHelpers.GetCachableObject();

            string cachableKey = RedisHelpers.CachableKey;

            service.Cache(cachableKey, cachable);
            Assert.Single(service);
            Assert.Equal(cacheLifeTime, service.DefaultCacheLifespan);
            Assert.False(service.IsReadOnly);
            Assert.Single(service.Keys);
            Assert.Equal(cachableKey, ((RedisId)service.Keys.Single()).ObjectIdentifier);
            Assert.Single(service.Values);
            string returnedString = service.Values.Single().UntypedValue as string;

            Assert.False(string.IsNullOrWhiteSpace(returnedString));
            Foobar returned = RedisHelpers.SerializationService.DeserializeObject <Foobar>(returnedString, RedisHelpers.SerializationSettings);

            Assert.NotNull(returned);
            Assert.NotEqual(cachable, returned);
            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, returned));
        }
コード例 #6
0
        public void Add(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            string cachableKey = RedisHelpers.CachableKey;
            Foobar cachable    = RedisHelpers.GetCachableObject();
            DefaultCachedObject <object> dto = new DefaultCachedObject <object>
            {
                Value      = cachable,
                CachedTime = DateTime.UtcNow,
                ExpireTime = DateTime.UtcNow.Add(cacheLifeTime)
            };

            service.Add(cachableKey, dto);
            Assert.Single(service);
            var    theSingle      = service.Values.Single();
            var    theValue       = theSingle.UntypedValue;
            string returnedString = theValue as string;

            Assert.False(string.IsNullOrWhiteSpace(returnedString));
            Foobar returned = RedisHelpers.SerializationService.DeserializeObject <Foobar>(returnedString, RedisHelpers.SerializationSettings);

            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, returned));
        }
コード例 #7
0
    static void Main(string[] args)
    {
        Foobar x = new Foobar();

        Console.WriteLine(x.bla);         //this works (prints hello world)
        Console.WriteLine(x["bla"]);      //this wont work but is my achivment
    }
コード例 #8
0
        public void Indexing(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            string cachableKey = RedisHelpers.CachableKey;

            // this shouldn't throw
            Assert.Null(service[cachableKey]);
            Foobar cachable = RedisHelpers.GetCachableObject();
            DefaultCachedObject <object> dto = new DefaultCachedObject <object>
            {
                Value      = cachable,
                CachedTime = DateTime.UtcNow,
                ExpireTime = DateTime.UtcNow.Add(cacheLifeTime)
            };

            service[cachableKey] = dto;
            Assert.Single(service);
            ICachedObjectBasic retrieved = service[cachableKey];
            Foobar             returned  = RedisHelpers.SerializationService.DeserializeObject <Foobar>(
                (string)retrieved.UntypedValue, RedisHelpers.SerializationSettings);

            Assert.NotNull(returned);
            Assert.NotEqual(cachable, returned);
            Assert.True(RedisHelpers.CheckFooBarEquality((Foobar)dto.Value, returned));
        }
コード例 #9
0
        public void StaticUsage(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromSeconds(1);
            RedisCachingService service       = RedisHelpers.GetCustomRedis(compressValues: compressValues, useBasic: useBasic, defaultExpireTimeSpanSeconds: (int)cacheLifeTime.TotalSeconds);

            service.Clear();
            Foobar cachable = RedisHelpers.GetCachableObject();

            string   cachableKey    = RedisHelpers.CachableKey;
            DateTime startedCaching = DateTime.UtcNow;

            service.Cache(cachableKey, cachable);
            DateTime endedCaching = DateTime.UtcNow;
            ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey);

            RedisCachingService    service2 = RedisHelpers.GetCustomRedis(compressValues: compressValues, useBasic: useBasic, defaultExpireTimeSpanSeconds: (int)cacheLifeTime.TotalSeconds);
            ICachedObject <Foobar> existsRetrievedWrapper2 = service2.Retrieve <Foobar>(cachableKey);

            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, existsRetrievedWrapper.Value));
            Assert.True(RedisHelpers.CheckFooBarEquality(existsRetrievedWrapper.Value, existsRetrievedWrapper2.Value));
            // they aren't reference equal
            Assert.NotEqual(existsRetrievedWrapper.Value, existsRetrievedWrapper2.Value);
            service2.Clear();
            Assert.Null(service.Retrieve <Foobar>(cachableKey));
        }
コード例 #10
0
        public void LogExceptionWithObjectWithoutMessage()
        {
            Json serializationService         = new Json();
            TextLoggingService loggingService = new TextLoggingService(Path, serializationService, LogExtension);

            ClearTestLogDirectory(loggingService);

            const string title    = "Test Log";
            Foobar       original = new Foobar
            {
                Foo = 4,
                Bar = 6
            };

            InvalidOperationException exception;

            try
            {
                throw new InvalidOperationException(title);
            }
            catch (InvalidOperationException ex)
            {
                exception = ex;
            }

            DateTime startLogging = DateTime.UtcNow;

            loggingService.LogExceptionWithObject(exception, original);
            DateTime endLogging = DateTime.UtcNow;

            IEnumerable <string> logs = Directory.EnumerateFiles(Path);

            Assert.Single(logs);

            string fullLogName   = logs.Single();
            string fullLogString = File.ReadAllText(fullLogName);

            Assert.NotNull(fullLogString);

            Log <Foobar> log = serializationService.DeserializeObject <Log <Foobar> >(fullLogString);

            string description = "Exception Log - " + title;

            Assert.NotNull(log);
            Assert.True(log.TimeStamp >= startLogging.AddMilliseconds(-5) && log.TimeStamp <= endLogging.AddMilliseconds(5));
            Assert.Equal(title, log.Title);
            Assert.Equal(description, log.Message);
            Assert.Equal(LogLevel.Error, log.LogLevel);
            Assert.Equal(description, log.Description);

            Assert.NotNull(log.Target);
            Assert.Equal(original.Foo, log.Target.Foo);
            Assert.Equal(0, log.Target.Bar);

            Assert.NotNull(log.Exception);
            Assert.Equal(typeof(SerializableException), log.Exception.GetType());
            Assert.Equal(title, log.Exception.Message);

            ClearTestLogDirectory(loggingService);
        }
コード例 #11
0
 public void property_should_have_the_assigned_value()
 {
     var value = 123;
     var foobar = new Foobar();
     var setter = PropertySetter.Create(foobar.GetType(), "Number");
     setter.Set(foobar, value);
     Assert.That(foobar.Number, Is.EqualTo(value));
 }
コード例 #12
0
        public void GetGreeting_ReturnsHelloWorld()
        {
            var foobar = new Foobar();

            string greeting = foobar.GetGreeting();

            Assert.AreEqual("Hello World!", greeting);
        }
コード例 #13
0
    public Foobar Foobar1(string param1 = "foo", string param2 = "bar")
    {
        Foobar f = new Foobar();

        f.Foo = param1;
        f.Bar = param2;
        return(f);
    }
コード例 #14
0
        public void LogExceptionWithObject()
        {
            MemoryCachingService cachingService = new MemoryCachingService(TimeSpan.FromMinutes(5));
            Json serializationService           = new Json();
            CacheLoggingService loggingService  = new CacheLoggingService(cachingService, serializationService, _partSeperator);

            const string title    = "Test Log";
            const string message  = "A test log";
            Foobar       original = new Foobar
            {
                Foo = 4,
                Bar = 6
            };

            InvalidOperationException exception;

            try
            {
                throw new InvalidOperationException(title);
            }
            catch (InvalidOperationException ex)
            {
                exception = ex;
            }

            DateTime startLogging = DateTime.UtcNow;

            loggingService.LogExceptionWithObject(exception, original, message);
            DateTime endLogging = DateTime.UtcNow;

            Assert.Single(cachingService);

            string fullLogName = cachingService.EnumerateDictionary().Single().Key;

            Assert.NotNull(fullLogName);

            Log <Foobar> log = (Log <Foobar>)cachingService.EnumerateDictionary().Single().Value.UntypedValue;

            string description = "Exception Log - " + title;

            Assert.NotNull(log);
            Assert.True(log.TimeStamp >= startLogging.AddMilliseconds(-5) && log.TimeStamp <= endLogging.AddMilliseconds(5));
            Assert.Equal(title, log.Title);
            Assert.Equal(message, log.Message);
            Assert.Equal(LogLevel.Error, log.LogLevel);
            Assert.Equal(description, log.Description);

            Assert.NotNull(log.Target);
            Assert.Equal(original.Foo, log.Target.Foo);
            // The memory caching service never serializes or deserializes so the non-serialized values won't change
            // Assert.Equal(0, log.Target.Bar);

            Assert.NotNull(log.Exception);
            Assert.Equal(typeof(SerializableException), log.Exception.GetType());
            Assert.Equal(title, log.Exception.Message);
        }
コード例 #15
0
        internal static Foobar GetCachableObject()
        {
            Foobar cachable = new Foobar
            {
                Foo = Random.Next(-1000, 1000),
                Bar = Random.Next(-1000, 1000)
            };

            return(cachable);
        }
コード例 #16
0
        private Foobar GetCachableObject()
        {
            Foobar cachable = new Foobar
            {
                Foo = _random.Next(-1000, 1000),
                Bar = _random.Next(-1000, 1000)
            };

            return(cachable);
        }
コード例 #17
0
        public void SerializeJson()
        {
            string originalString = "{\"Foo\":4, \"Bar\":3}";
            Foobar original       = new Foobar
            {
                Foo = 4
            };

            Assert.NotNull(original.SerializeJson <Foobar>());
            Assert.NotEqual(originalString, original.SerializeJson <Foobar>());
        }
コード例 #18
0
        public void DeserializeObjectTest()
        {
            string expected = "expected";
            Foobar foobar   = new Foobar {
                Foo = 4, Bar = 9
            };
            Mock <ISerializationService> serializationServiceProxy = new Mock <ISerializationService>(MockBehavior.Strict);

            serializationServiceProxy.Setup(x => x.DeserializeObject <Foobar>(expected, null)).Returns(foobar);
            Assert.Equal(foobar, serializationServiceProxy.Object.DeserializeObject <Foobar>(expected));
        }
コード例 #19
0
        public void ContainsKey()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            string cachableKey = this.cachableKey;
            Foobar cachable    = GetCachableObject();

            service.Cache <Foobar>(cachableKey, cachable);
            Assert.Single(service);;
            Assert.True(service.ContainsKey(cachableKey));
        }
コード例 #20
0
        public void Contains()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            Foobar cachable    = GetCachableObject();
            string cachableKey = this.cachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

            Assert.DoesNotContain(item, service);
            service.Add(item);
            Assert.Contains(item, service);
        }
コード例 #21
0
        public TextBoxes()
        {
            SuggestionsViewModel = new SuggestionsViewModel(new SerialTaskScheduler(),
                                                            new UiDispatcher(Dispatcher.CurrentDispatcher));

            InitializeComponent();

            Dispatcher.BeginInvoke(new Action(() =>
            {
                Foobar.Focus();
            }));
        }
コード例 #22
0
        public void Update(Foobar instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance", "null");
            }

            instance.UpdateDate = DateTime.Now;

            this._Repository.Update(instance);
            this._Repository.SaveChanges();
        }
コード例 #23
0
        public void SerializeTest()
        {
            JwtJsonSerializer serializer = new JwtJsonSerializer();
            Foobar            foobar     = new Foobar
            {
                Bar = 4,
                Foo = 1
            };
            string expected = foobar.SerializeJson();

            Assert.Equal(expected, serializer.Serialize(foobar));
        }
コード例 #24
0
        public void LogMessageWithObjectTest()
        {
            string   title   = "test";
            LogLevel level   = LogLevel.Debug;
            string   message = "this is a test";
            Foobar   foobar  = new Foobar {
                Foo = 4, Bar = 3
            };
            Mock <ILoggingService> loggingService = new Mock <ILoggingService>(MockBehavior.Strict);

            loggingService.Setup(x => x.LogMessage(title, foobar, level, message));
            loggingService.Object.LogMessage(title, foobar, level, message);
        }
コード例 #25
0
        public void Count(bool compressValues, bool useBasic)
        {
            RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Assert.Empty(service);
            Foobar cachable = RedisHelpers.GetCachableObject();

            string cachableKey = RedisHelpers.CachableKey;

            service.Cache(cachableKey, cachable);
            Assert.Single(service);
        }
コード例 #26
0
        public void LogExceptionWithObjectTest()
        {
            InvalidOperationException exception = new InvalidOperationException("test");
            LogLevel level   = LogLevel.Debug;
            string   message = "this is a test";
            Foobar   foobar  = new Foobar {
                Foo = 4, Bar = 3
            };
            Mock <ILoggingService> loggingService = new Mock <ILoggingService>(MockBehavior.Strict);

            loggingService.Setup(x => x.LogExceptionWithObject(exception, foobar, message, level));
            loggingService.Object.LogExceptionWithObject(exception, foobar, message, level);
        }
コード例 #27
0
        public void ContainsKey(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            string cachableKey = RedisHelpers.CachableKey;
            Foobar cachable    = RedisHelpers.GetCachableObject();

            service.Cache <Foobar>(cachableKey, cachable);
            Assert.Single(service);
            Assert.True(service.ContainsKey(cachableKey));
        }
コード例 #28
0
        public void DeserializeJson()
        {
            string originalString = "{\"Foo\":4, \"Bar\":3}";
            Foobar original       = new Foobar
            {
                Foo = 4
            };

            Assert.NotNull(originalString.DeserializeJson <Foobar>());
            Assert.NotEqual(original, originalString.DeserializeJson <Foobar>());
            Assert.Equal(original.Foo, originalString.DeserializeJson <Foobar>().Foo);
            Assert.Equal(original.Bar, originalString.DeserializeJson <Foobar>().Bar);
        }
コード例 #29
0
        public void Count()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);

            Assert.Empty(service);
            Foobar cachable = GetCachableObject();

            string cachableKey = this.cachableKey;

            service.Cache(cachableKey, cachable);
            Assert.Single(service);
        }
コード例 #30
0
        public void AddKvp()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            Foobar cachable    = GetCachableObject();
            string cachableKey = this.cachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

            service.Add(item);
            ICachedObject <Foobar> result = service.Retrieve <Foobar>(cachableKey);

            Assert.Equal(cachable, result.Value);
        }
コード例 #31
0
        static void Main(string[] args) //  entry point for all C# programs, The Main method states what the class does when executed.
        {
            //Foobar

            var fb = new Foobar();

            int num = Convert.ToInt32(Console.ReadLine());

            //fb.GetFoobar(num);



            Console.ReadLine();
        }