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); }
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)); }
public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = base.Validate(validationContext).ToList(); result.AddRange(Foobar.Validate(validationContext)); return(result); }
public TResult Interact <TResult> (Func <Foobar, TResult> lambdaCode) { var x = new Foobar(); Initialize(x); //or whatever return(lambdaCode(x)); }
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)); }
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)); }
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 }
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)); }
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)); }
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); }
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)); }
public void GetGreeting_ReturnsHelloWorld() { var foobar = new Foobar(); string greeting = foobar.GetGreeting(); Assert.AreEqual("Hello World!", greeting); }
public Foobar Foobar1(string param1 = "foo", string param2 = "bar") { Foobar f = new Foobar(); f.Foo = param1; f.Bar = param2; return(f); }
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); }
internal static Foobar GetCachableObject() { Foobar cachable = new Foobar { Foo = Random.Next(-1000, 1000), Bar = Random.Next(-1000, 1000) }; return(cachable); }
private Foobar GetCachableObject() { Foobar cachable = new Foobar { Foo = _random.Next(-1000, 1000), Bar = _random.Next(-1000, 1000) }; return(cachable); }
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>()); }
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)); }
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)); }
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); }
public TextBoxes() { SuggestionsViewModel = new SuggestionsViewModel(new SerialTaskScheduler(), new UiDispatcher(Dispatcher.CurrentDispatcher)); InitializeComponent(); Dispatcher.BeginInvoke(new Action(() => { Foobar.Focus(); })); }
public void Update(Foobar instance) { if (instance == null) { throw new ArgumentNullException("instance", "null"); } instance.UpdateDate = DateTime.Now; this._Repository.Update(instance); this._Repository.SaveChanges(); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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(); }