private IList<FacebookPost> ParseFeed(string json) { DefaultJsonConverter converter = new DefaultJsonConverter(); dynamic parsed = converter.Deserialize(json); List<FacebookPost> posts = new List<FacebookPost>(); bool isPage = _part.FeedType.ToUpper().Equals("PAGE"); foreach (dynamic item in parsed.data) { FacebookUser poster = new FacebookUser() { Id = item.from.id, Name = item.from.name }; posts.Add(new FacebookPost() { PageId = poster.Id, PostId = ParsePostId(_part.PageId, item.id.Value), PostedBy = poster, Story = ParseStory(item.story, poster.Name), Message = item.message ?? string.Empty, Created = item.created_time, Photo = new FacebookImage() { ImagePage = isPage ? item.link : string.Empty, ImageSource = item.picture ?? string.Empty } }); } return posts; }
public void ShouldConvertWellKnownTypeToJSon() { var converter = new DefaultJsonConverter(); string result = converter.Serialize(new Animal { Age = 12, Name = "Milou" }); var o = converter.Deserialize<Animal>(result); Assert.That(o.Age, Is.EqualTo(12)); Assert.That(o.Name, Is.EqualTo("Milou")); }
public void ShouldConvertPrimitiveTypesToJSon() { var converter = new DefaultJsonConverter(); Assert.That(converter.Serialize(12), Is.EqualTo("12")); Assert.That(converter.Serialize(true), Is.EqualTo("true")); Assert.That(converter.Serialize(12.345), Is.EqualTo("12.345")); Assert.That(converter.Serialize("string"), Is.EqualTo("\"string\"")); Assert.That(converter.Serialize(new DateTime(2013, 1, 31, 0, 0, 0, DateTimeKind.Utc)), Is.EqualTo("\"2013-01-31T00:00:00Z\"")); }
public void ShouldConvertPrimitiveTypesToJSon() { var converter = new DefaultJsonConverter(); Assert.Equal(converter.Serialize(12), "12"); Assert.Equal(converter.Serialize(true), "true"); Assert.Equal(converter.Serialize(12.345), "12.345"); Assert.Equal(converter.Serialize("string"), "\"string\""); Assert.Equal(converter.Serialize(new DateTime(2013, 1, 31, 0, 0, 0, DateTimeKind.Utc)), "\"2013-01-31T00:00:00Z\""); }
public void ShouldConvertWellKnownTypeToJSon() { var converter = new DefaultJsonConverter(); string result = converter.Serialize(new Animal { Age = 12, Name = "Milou" }); var o = converter.Deserialize <Animal>(result); Assert.Equal(o.Age, 12); Assert.Equal(o.Name, "Milou"); }
public void Setup() { mOutputCacheStorageProvider = new Mock <IOutputCacheStorageProvider>(); mClock = new Mock <IClock>(); _tagCache = new Mock <ITagCache>(); // Some tests create their own collection of providers, so only create a new instance if this is not the case if (mCompositeCacheKeyProviders == null) { mCompositeCacheKeyProviders = new List <ICompositeCacheKeyProvider>(); } mCachedItems = new Dictionary <string, CacheItem>(); mShellSettings = new ShellSettings { Name = "UnitTest" }; mJsonConvertor = new DefaultJsonConverter(); mOutputCacheStorageProvider.Setup(p => p.GetCacheItem("miss")).Returns(null as CacheItem); mOutputCacheStorageProvider.Setup(p => p.GetCacheItem("hit")).Returns(new CacheItem { Output = Encoding.UTF8.GetBytes(mJsonConvertor.Serialize(new ItemLevelCacheItem("html"))) }); mOutputCacheStorageProvider.Setup(p => p.GetCacheItem("ItemLevelCache; 42; AlwaysHit; ")).Returns(new CacheItem()); mOutputCacheStorageProvider.Setup(p => p.GetCacheItem("ItemLevelCache; 42; AlwaysMiss; ")).Returns(null as CacheItem); mOutputCacheStorageProvider.Setup(p => p.Set(It.IsAny <string>(), It.IsAny <CacheItem>())).Callback <string, CacheItem>((key, item) => mCachedItems[key] = item); mClock.Setup(c => c.UtcNow).Returns(new DateTime(2016, 10, 26)); mSut = new DefaultItemLevelCacheService(mOutputCacheStorageProvider.Object, mClock.Object, mShellSettings, _tagCache.Object, mCompositeCacheKeyProviders, new StubHttpContextAccessor(new DonutCacheStubHttpContext()), mJsonConvertor); }