Exemple #1
0
        public void SetNullResourceFactoryCreator_MustThrowException()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();

            Assert.ThrowsException <ArgumentNullException>(() => visit.ResourceFactoryCreator = null);
            visit.Dispose();
        }
Exemple #2
0
        public async Task GivenProvider_Load_LoadingAndLoadedEventMustFired()
        {
            var    visit   = ComicVisitingHelper.CreateResrouceVisitor();
            object sender1 = null;
            string addr1   = null;

            visit.Loading += (o, e) =>
            {
                sender1 = o;
                addr1   = e;
            };
            object      sender2 = null;
            ComicEntity entity  = null;

            visit.Loaded += (o, e) =>
            {
                sender2 = o;
                entity  = e;
            };
            var res = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            Assert.AreEqual(visit, sender1);
            Assert.AreEqual(ComicVisitingHelper.AnyUri.AbsoluteUri, addr1);

            Assert.AreEqual(visit, sender2);
            Assert.AreEqual(visit.Entity, entity);
            visit.Dispose();
        }
Exemple #3
0
        public void GivenValueInit_PropertyValueMustEqualGiven()
        {
            var page  = new ChapterWithPage(null, null);
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var mgr   = new ComicChapterManager <Stream>(page, visit);

            Assert.AreEqual(page, mgr.ChapterWithPage);
            Assert.AreEqual(visit, mgr.ComicVisiting);
        }
Exemple #4
0
        public async Task GetChapterTwice_InnerObjectMustEqual()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            var chp1 = await visit.GetChapterManagerAsync(0);

            var chp2 = await visit.GetChapterManagerAsync(0);

            Assert.AreEqual(chp1.ChapterWithPage, chp2.ChapterWithPage);
            visit.Dispose();
        }
Exemple #5
0
        public async Task GetChapter_MustReturnTheChapter_AndLoaded()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            var chp = await visit.GetChapterManagerAsync(0);

            Assert.IsNotNull(chp);
            Assert.IsNotNull(chp.ChapterWithPage);
            Assert.AreEqual(visit.ChapterWithPages[0], chp.ChapterWithPage);
            visit.Dispose();
        }
Exemple #6
0
        public async Task GivenProvider_Load_MustLoadSucceed()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var prov  = visit.Host.GetRequiredService <ResourceComicProvider>();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            Assert.IsTrue(res);
            Assert.IsNotNull(visit.Entity);
            Assert.IsNotNull(visit.ChapterWithPages);
            Assert.AreEqual(ComicVisitingHelper.AnyUri.AbsoluteUri, visit.Address);
            Assert.IsNotNull(visit.SourceProvider);
            visit.Dispose();
        }
Exemple #7
0
        public async Task LoadOutOufRangeChapter_MustThrowException()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.LoadChapterAsync(-1));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.LoadChapterAsync(visit.ChapterWithPages.Count));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.LoadChapterAsync(20));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.LoadChapterAsync(int.MaxValue));
        }
Exemple #8
0
        public async Task LoadChapter_IfAnyIntercept_TheMethodWasCalled()
        {
            var intercept = new NullComicVisitingInterceptor <Stream>();
            var visit     = ComicVisitingHelper.CreateResrouceVisitor();

            visit.VisitingInterceptor = intercept;
            var res = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            var chp1 = await visit.GetChapterManagerAsync(0);

            Assert.IsTrue(intercept.IsGotChapterManagerAsync);
            Assert.IsTrue(intercept.IsLoadingChapterAsync);
            Assert.IsTrue(intercept.IsLoadedChapterAsync);
        }
Exemple #9
0
        public async Task LoadChapter_EraseIt_ChapterMustBeErased()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            var chp1 = await visit.GetChapterManagerAsync(0);

            visit.EraseChapter(0);
            Assert.IsNull(visit.ChapterWithPages[0]);
            chp1 = await visit.GetChapterManagerAsync(0);

            Assert.IsNotNull(chp1);
            Assert.AreEqual(visit.ChapterWithPages[0], chp1.ChapterWithPage);
        }
Exemple #10
0
        public async Task GetChapterWhenNotLoad_OrOutOfRange_MustThrowException()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => visit.GetChapterManagerAsync(0));

            var res = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.GetChapterManagerAsync(-1));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.GetChapterManagerAsync(visit.ChapterWithPages.Count));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.GetChapterManagerAsync(99));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => visit.GetChapterManagerAsync(int.MaxValue));

            visit.Dispose();
        }
Exemple #11
0
        public async Task AsyncLoadChapter_MustOnlyOneLoad(int size)
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            var insts = new object[size];
            var tasks = Enumerable.Range(0, size)
                        .Select(x => visit.GetChapterManagerAsync(0).ContinueWith(y => insts[x] = y.Result.ChapterWithPage))
                        .ToArray();
            await Task.WhenAll(tasks);

            Assert.IsNotNull(visit.ChapterWithPages[0]);
            for (int i = 0; i < insts.Length; i++)
            {
                var val = insts[i];
                Assert.AreEqual(visit.ChapterWithPages[0], val, i.ToString());
            }
        }
Exemple #12
0
        public async Task GetChapter_EventLoadingAndLoadedChapterMustBeFired()
        {
            var visit = ComicVisitingHelper.CreateResrouceVisitor();
            var res   = await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            object sender1 = null;
            int    index1  = -1;

            visit.LoadingChapter += (o, e) =>
            {
                sender1 = o;
                index1  = e;
            };
            object          sender2 = null;
            ChapterWithPage cwp     = null;

            visit.LoadedChapter += (o, e) =>
            {
                sender2 = o;
                cwp     = e;
            };
            var chp1 = await visit.GetChapterManagerAsync(0);

            Assert.AreEqual(visit, sender1);
            Assert.AreEqual(0, index1);

            Assert.AreEqual(visit, sender2);
            Assert.AreEqual(visit.ChapterWithPages[0], cwp);

            sender1 = sender2 = null;
            index1  = -1;
            cwp     = null;

            chp1 = await visit.GetChapterManagerAsync(0);

            Assert.IsNull(sender1);
            Assert.IsNull(sender2);
            Assert.AreEqual(-1, index1);
            Assert.IsNull(cwp);
            visit.Dispose();
        }
Exemple #13
0
        public async Task GivenValueInit_GetVisitPage_MustCallIntercepts()
        {
            var visit     = ComicVisitingHelper.CreateResrouceVisitor();
            var intercept = new NullComicVisitingInterceptor <Stream>();

            visit.VisitingInterceptor = intercept;
            await visit.LoadAsync(ComicVisitingHelper.AnyUri.AbsoluteUri);

            await visit.LoadChapterAsync(0);

            var mgr = new ComicChapterManager <Stream>(visit.ChapterWithPages[0], visit);
            var pg  = await mgr.GetVisitPageAsync(0);

            Assert.IsNotNull(pg);
            Assert.IsNotNull(pg.Page);
            Assert.IsNotNull(pg.Resource);


            Assert.IsTrue(intercept.IsGettingPageAsync);
            Assert.IsTrue(intercept.IsGotPageAsync);
        }
Exemple #14
0
 public async Task GivenValueInit_ButNullResourceFactory_GetVisitPage_MustThrowException()
 {
     var visit = ComicVisitingHelper.CreateResrouceVisitor();
     await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => new ComicChapterManager <Stream>(new ChapterWithPage(null, null), visit).GetVisitPageAsync(0));
 }
Exemple #15
0
 public void GivenNullInit_MustThrowException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => new ComicChapterManager <Stream>(null, null));
     Assert.ThrowsException <ArgumentNullException>(() => new ComicChapterManager <Stream>(new ChapterWithPage(null, null), null));
     Assert.ThrowsException <ArgumentNullException>(() => new ComicChapterManager <Stream>(null, ComicVisitingHelper.CreateResrouceVisitor()));
 }