Exemple #1
0
        public void GivenAnyCondition_ActiveByIndex_MustBeActived()
        {
            var prov = new NullIProposalProvider();
            var f    = new ValueServiceScopeFactory
            {
                Factory = new Dictionary <Type, Func <object> >
                {
                    [typeof(NullIProposalProvider)] = () => prov
                }
            };
            var eng = new ProposalEngine(f);

            eng.Add(new NullProposalDescription
            {
                DescritionUri = new Uri("http://localhost:4200"),
                Name          = "any",
                ProviderType  = typeof(NullIProposalProvider)
            });
            Assert.AreEqual(1, eng.Count);
            var obj = eng.Active(0);

            Assert.IsNotNull(obj.Provider);
            Assert.AreEqual(prov, obj.Provider);
            obj.Dispose();
        }
Exemple #2
0
        public void ActiveNoImplement_IProposalProvider_Type_MustThrowException()
        {
            var prov = new object();
            var f    = new ValueServiceScopeFactory
            {
                Factory = new Dictionary <Type, Func <object> >
                {
                    [typeof(object)] = () => prov
                }
            };
            var eng = new ProposalEngine(f);

            Assert.ThrowsException <InvalidCastException>(() => eng.Active(typeof(object)));
        }
Exemple #3
0
        public void ActiveType_TypeMustActived()
        {
            var prov = new NullIProposalProvider();
            var f    = new ValueServiceScopeFactory
            {
                Factory = new Dictionary <Type, Func <object> >
                {
                    [typeof(NullIProposalProvider)] = () => prov
                }
            };
            var eng = new ProposalEngine(f);

            Assert.AreEqual(f, eng.ServiceScopeFactory);
            var obj = eng.Active(typeof(NullIProposalProvider));

            Assert.IsNotNull(obj.Provider);
            Assert.IsNotNull(obj.Scope);
            Assert.AreEqual(prov, obj.Provider);
            obj.Dispose();
        }
Exemple #4
0
        public void GivenAnyCondition_ActiveOutOfRang_MustThrowException(int count, int index)
        {
            var prov = new NullIProposalProvider();
            var f    = new ValueServiceScopeFactory
            {
                Factory = new Dictionary <Type, Func <object> >
                {
                    [typeof(NullIProposalProvider)] = () => prov
                }
            };
            var eng = new ProposalEngine(f);

            for (int i = 0; i < count; i++)
            {
                eng.Add(new NullProposalDescription
                {
                    DescritionUri = new Uri("http://localhost:420" + i),
                    Name          = "any" + i,
                    ProviderType  = typeof(NullIProposalProvider)
                });
            }
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => eng.Active(index));
        }
Exemple #5
0
        private SearchEngine CreateEng()
        {
            var factory = new ValueServiceScopeFactory();

            factory.Factory = new Dictionary <Type, Func <object> >
            {
                [typeof(DataSearchProvider)] = () => new DataSearchProvider
                {
                    Datas = new Dictionary <string, SearchComicResult>
                    {
                        ["aaa"] = new SearchComicResult
                        {
                            Snapshots = new ComicSnapshot[]
                            {
                                new ComicSnapshot
                                {
                                    Name     = "aaa",
                                    Author   = "aa",
                                    Descript = "aaaaa",
                                    ImageUri = "aaaaaaaaa",
                                    Sources  = new ComicSource[]
                                    {
                                        new ComicSource {
                                            Name = "ss1", TargetUrl = "ssurl"
                                        },
                                        new ComicSource(),
                                    },
                                    TargetUrl = "aaaaaaaaaa"
                                },
                                new ComicSnapshot()
                            },
                            Support = true,
                            Total   = 2
                        }
                    }
                },
                [typeof(DataSearchProvider2)] = () => new DataSearchProvider
                {
                    Datas = new Dictionary <string, SearchComicResult>
                    {
                        ["bbb"] = new SearchComicResult
                        {
                            Snapshots = new ComicSnapshot[]
                            {
                                new ComicSnapshot
                                {
                                    Name     = "bbb",
                                    Author   = "bb",
                                    Descript = "aaabbbaa",
                                    ImageUri = "bb",
                                    Sources  = new ComicSource[]
                                    {
                                        new ComicSource {
                                            Name = "ss1", TargetUrl = "ssurl"
                                        },
                                        new ComicSource(),
                                    },
                                    TargetUrl = "bbbbbbb"
                                },
                                new ComicSnapshot()
                            },
                            Support = true,
                            Total   = 11
                        }
                    }
                }
            };
            var eng = new SearchEngine(factory);

            eng.Add(typeof(DataSearchProvider));
            eng.Add(typeof(DataSearchProvider2));
            return(eng);
        }