Esempio n. 1
0
        public void NiProviderConverterTest()
        {
            NiProviderConverter conv = new NiProviderConverter();

            NI.Common.Providers.ConstObjectProvider niPrv = new NI.Common.Providers.ConstObjectProvider("aa");
            ConstProvider prv = new ConstProvider("zz");

            Assert.AreEqual(true, conv.CanConvert(niPrv.GetType(), typeof(IProvider <object, object>)));
            Assert.AreEqual(true, conv.CanConvert(niPrv.GetType(), typeof(IProvider <object, string>)));
            Assert.AreEqual(true, conv.Convert(prv, typeof(NI.Common.Providers.IObjectProvider)) is NI.Common.Providers.IObjectProvider);
            Assert.AreEqual("aa", ((IProvider <object, object>)conv.Convert(niPrv, typeof(IProvider <object, object>))).Provide(null));
            Assert.AreEqual("aa", ((IProvider <object, string>)conv.Convert(niPrv, typeof(IProvider <object, string>))).Provide(null));
            Assert.AreEqual("zz", ((NI.Common.Providers.IObjectProvider)conv.Convert(prv, typeof(NI.Common.Providers.IObjectProvider))).GetObject(null));
        }
Esempio n. 2
0
        public void GenericProviderConverterTest()
        {
            ProviderConverter gPrvCnv             = new ProviderConverter();
            ConstProvider     prv                 = new ConstProvider("aa");
            ConstProvider <Object, string> strPrv = new ConstProvider <object, string>("zz");

            Assert.AreEqual(true, gPrvCnv.CanConvert(strPrv.GetType(), typeof(IProvider <object, object>)));
            Assert.AreEqual(true, gPrvCnv.Convert(strPrv, typeof(IProvider <object, object>)) is IProvider <object, object>);
            Assert.AreEqual("zz", ((IProvider <object, object>)gPrvCnv.Convert(strPrv, typeof(IProvider <object, object>))).Provide(null));

            Assert.AreEqual(true, gPrvCnv.CanConvert(prv.GetType(), typeof(IProvider <string, string>)));
            Assert.AreEqual(true, gPrvCnv.Convert(prv, typeof(IProvider <string, string>)) is IProvider <string, string>);
            Assert.AreEqual("aa", ((IProvider <string, string>)gPrvCnv.Convert(prv, typeof(IProvider <string, string>))).Provide(null));

            // generic to generic
            Assert.AreEqual(true, gPrvCnv.CanConvert(typeof(IProvider <Context, NameValueContext>), typeof(IProvider <NameValueContext, Context>)));
            Assert.AreEqual(true, gPrvCnv.CanConvert(typeof(IProvider <Context, NameValueContext>), typeof(IProvider <object, Context>)));
            Assert.AreEqual(true, gPrvCnv.CanConvert(typeof(IProvider <Context, Context>), typeof(IProvider <Context, object>)));
            IProvider <Context, string> strByContextPrv = (IProvider <Context, string>)gPrvCnv.Convert(strPrv, typeof(IProvider <Context, string>));

            Assert.AreEqual("zz", strByContextPrv.Provide(Context.Empty));
        }