public void DoStuff() { var c = new ThirdPartyYoutube(); c.GetVideoInfo(100); c.GetVideoInfo(100); c.DownloadVideo(100); c.DownloadVideo(100); c.ListVideos(); CollectionAssert.AreEqual(new[] { "Get video 100", "Get video 100", // nackdel: inget cache'as "Download video 100", "Download video 100", // nackdel: inget cache'as "List all videos" }, c.Events.ToArray()); // Fördel: ingen extra kod }
public Video GetVideoInfo(int id) { if (_cached.ContainsKey(id)) { _events.Enqueue($"Get video {id} from cache"); return(_cached[id]); } var video = _thirdPartyYoutube.GetVideoInfo(id); _cached.Add(id, video); _events.Enqueue($"Get video {id}"); return(video); }