Exemple #1
0
        public void SurrogateAttribute()
        {
            var selector = new FudgeSurrogateSelector(context);

            var surrogate = selector.GetSurrogate(typeof(SurrogateTest), FudgeFieldNameConvention.Identity);

            Assert.IsType <SurrogateTest.SurrogateTestSurrogate>(surrogate);

            // SurrogateTest3 has a constructor on the surrogate which takes type
            surrogate = selector.GetSurrogate(typeof(SurrogateTest3), FudgeFieldNameConvention.Identity);
            Assert.IsType <SurrogateTest3.SurrogateTest3Surrogate>(surrogate);
            Assert.Equal(typeof(SurrogateTest3), ((SurrogateTest3.SurrogateTest3Surrogate)surrogate).Type);

            // SurrogateTest4 has a constructor on the surrogate which takes context and type
            surrogate = selector.GetSurrogate(typeof(SurrogateTest4), FudgeFieldNameConvention.Identity);
            Assert.IsType <SurrogateTest4.SurrogateTest4Surrogate>(surrogate);
            Assert.Equal(typeof(SurrogateTest4), ((SurrogateTest4.SurrogateTest4Surrogate)surrogate).Type);
            Assert.Same(context, ((SurrogateTest4.SurrogateTest4Surrogate)surrogate).Context);

            //ISurrogateTest is an interface

            surrogate = selector.GetSurrogate(typeof(ISurrogateTest), FudgeFieldNameConvention.Identity);
            Assert.IsType <InterfaceSurrogateTestSurrogate>(surrogate);
            Assert.Equal(typeof(ISurrogateTest), ((InterfaceSurrogateTestSurrogate)surrogate).Type);
            Assert.Same(context, ((InterfaceSurrogateTestSurrogate)surrogate).Context);

            //SurrogateEnumTest is an enum
            surrogate = selector.GetSurrogate(typeof(SurrogateEnumTest), FudgeFieldNameConvention.Identity);
            Assert.IsType <SurrogateEnumTestSurrogate>(surrogate);
            Assert.Equal(typeof(SurrogateEnumTest), ((SurrogateEnumTestSurrogate)surrogate).Type);
            Assert.Same(context, ((SurrogateEnumTestSurrogate)surrogate).Context);
        }
Exemple #2
0
        public void DirectSerializaton()
        {
            // Basic case
            var selector  = new FudgeSurrogateSelector(context);
            var surrogate = selector.GetSurrogate(typeof(DirectTest), FudgeFieldNameConvention.Identity);

            Assert.IsType <SerializableSurrogate>(surrogate);

            // Test exception thrown if no default constructor
            Assert.Throws <FudgeRuntimeException>(() => selector.GetSurrogate(typeof(DirectNoDefaultConstructorTest), FudgeFieldNameConvention.Identity));
        }