public async Task ErrorsFBUnitTest()
        {
            ConnectorTask taskInfo = new ConnectorTask();

            taskInfo.StartTime = DateTime.Parse("2018-01-09");
            taskInfo.EndTime   = DateTime.Parse("2018-01-11");
            taskInfo.JobId     = "job1";
            taskInfo.TaskId    = "task1";
            taskInfo.TenantId  = "tenant1";

            var mockDownloader = new Mock <IDownloader>();

            mockDownloader.Setup(x => x.GetWebContent <PostListFB, ErrorsFB>(It.IsAny <string>(), It.IsAny <AuthenticationHeaderValue>()))
            .Throws(new ClientException <ErrorsFB>(JsonConvert.DeserializeObject <ErrorsFB>(File.ReadAllText(@"FakeData\FakeError.json"))));

            FakeUploader   uploader = new FakeUploader();
            JobProcessorFB job      = new JobProcessorFB(mockDownloader.Object, uploader);

            string sourceInfo = "{\"PageId\":\"123\",\"AccessToken\":\"Fake\",\"PageName\":\"Fake123\"}";

            try
            {
                await job.FetchData(taskInfo, sourceInfo);
            }
            catch (ClientException <ErrorsFB> error)
            {
                Assert.AreEqual(error.error.Error.ErrorMessage, "Message describing the error");
                Assert.AreEqual(error.error.Error.ErrorType, "OAuthException");
            }

            Assert.AreEqual(uploader.fakeStorage.Count, 0);
        }
        public async Task FetchUpdatedPostsUnitTest()
        {
            ConnectorTask taskInfo = new ConnectorTask();

            taskInfo.StartTime     = DateTime.Parse("2018-01-09");
            taskInfo.EndTime       = DateTime.Parse("2018-01-11");
            taskInfo.JobId         = "job1";
            taskInfo.TaskId        = "task1";
            taskInfo.TenantId      = "tenant1";
            taskInfo.DirtyEntities = new List <string>()
            {
                "a",
                "b"
            };

            var mockDownloader = new Mock <IDownloader>();

            mockDownloader.SetupSequence(x => x.GetWebContent <PostListFB, ErrorsFB>(It.IsAny <string>(), It.IsAny <AuthenticationHeaderValue>()))
            .ReturnsAsync(JsonConvert.DeserializeObject <PostListFB>("{\"data\": []}"));

            mockDownloader.SetupSequence(x => x.GetWebContent <Dictionary <string, PostFB>, ErrorsFB>(It.IsAny <string>(), It.IsAny <AuthenticationHeaderValue>()))
            .ReturnsAsync(JsonConvert.DeserializeObject <Dictionary <string, PostFB> >(File.ReadAllText(@"FakeData\FakeDirtyPosts.json")));

            FakeUploader   uploader = new FakeUploader();
            JobProcessorFB job      = new JobProcessorFB(mockDownloader.Object, uploader);

            string sourceInfo = "{\"PageId\":\"123\",\"AccessToken\":\"Fake\",\"PageName\":\"Fake123\"}";

            await job.FetchData(taskInfo, sourceInfo);

            Assert.AreEqual(uploader.fakeStorage.Count, 2);
        }
        public async Task DownloadDataAndTransformUnitTest()
        {
            ConnectorTask taskInfo = new ConnectorTask();

            taskInfo.StartTime = DateTime.Parse("2018-01-09");
            taskInfo.EndTime   = DateTime.Parse("2018-01-11");
            taskInfo.JobId     = "job1";
            taskInfo.TaskId    = "task1";
            taskInfo.TenantId  = "tenant1";

            var mockDownloader = new Mock <IDownloader>();

            mockDownloader.SetupSequence(x => x.GetWebContent <PostListFB, ErrorsFB>(It.IsAny <string>(), It.IsAny <AuthenticationHeaderValue>()))
            .ReturnsAsync(JsonConvert.DeserializeObject <PostListFB>(File.ReadAllText(@"FakeData\FakeData.json")))
            .ReturnsAsync(JsonConvert.DeserializeObject <PostListFB>("{\"data\": []}"));

            mockDownloader.Setup(x => x.DownloadFileAsBase64EncodedString(It.IsAny <string>()))
            .ReturnsAsync(Convert.ToBase64String(File.ReadAllBytes(@"FakeData\FakeImage.jpg")));

            FakeUploader   uploader = new FakeUploader();
            JobProcessorFB job      = new JobProcessorFB(mockDownloader.Object, uploader);

            string sourceInfo = "{\"PageId\":\"123\",\"AccessToken\":\"Fake\",\"PageName\":\"Fake123\"}";

            await job.FetchData(taskInfo, sourceInfo);

            // Assert 1 item of each type - post, comment, reply
            int assertItemsCount = 0;

            foreach (var entry in uploader.fakeStorage)
            {
                if (File.Exists($@"FakeData\{entry.Key}.json"))
                {
                    assertItemsCount++;
                    string expectedJson = File.ReadAllText($@"FakeData\{entry.Key}.json");
                    Item   expectedItem = JsonConvert.DeserializeObject <Item>(expectedJson);
                    AssertItemsAreEqual(expectedItem, entry.Value);
                }
            }
            Assert.AreEqual(assertItemsCount, 3);
        }
        public async Task NoPostsFetchedUnitTest()
        {
            ConnectorTask taskInfo = new ConnectorTask();

            taskInfo.StartTime = DateTime.Parse("2018-01-09");
            taskInfo.EndTime   = DateTime.Parse("2018-01-11");
            taskInfo.JobId     = "job1";
            taskInfo.TaskId    = "task1";
            taskInfo.TenantId  = "tenant1";

            var mockDownloader = new Mock <IDownloader>();

            mockDownloader.Setup(x => x.GetWebContent <PostListFB, ErrorsFB>(It.IsAny <string>(), It.IsAny <AuthenticationHeaderValue>()))
            .ReturnsAsync(JsonConvert.DeserializeObject <PostListFB>("{\"data\": []}"));

            FakeUploader   uploader = new FakeUploader();
            JobProcessorFB job      = new JobProcessorFB(mockDownloader.Object, uploader);

            string sourceInfo = "{\"PageId\":\"123\",\"AccessToken\":\"Fake\",\"PageName\":\"Fake123\"}";

            await job.FetchData(taskInfo, sourceInfo);

            Assert.AreEqual(uploader.fakeStorage.Count, 0);
        }