public void WithIncorrectTObjectType_ShouldThrowException() { var data = Guid.NewGuid().ToString(); var dataAsString = JsonConvert.SerializeObject(data); var dataAsByteArray = Encoding.Default.GetBytes(dataAsString); Assert.ThrowsAny <Exception>(() => JSonHelper.Desirialize <int[]>(dataAsByteArray)); }
public void WithData_ShouldDeserializeData() { var data = Guid.NewGuid().ToString(); var dataAsString = JsonConvert.SerializeObject(data); var dataAsByteArray = Encoding.Default.GetBytes(dataAsString); var result = JSonHelper.Desirialize <string>(dataAsByteArray); Assert.Equal(data, result); }
public async Task <TResult> GetOrDefaultAsync <TResult>(string cacheKey) where TResult : class { this.ValidateCacheKey(cacheKey); var cachedResultAsBytes = await this.cache.GetAsync(cacheKey); if (cachedResultAsBytes == null) { return(null); } var result = JSonHelper.Desirialize <TResult>(cachedResultAsBytes); return(result); }