public void CanSerializeAndDeserializeGeneratedInterface() { //Assign Type type = typeof(IStubInterface); var glassConfig = Substitute.For <IGlassConfiguration>(); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext.RequestedType = typeof(IStubInterface); var configuration = Substitute.For <AbstractTypeConfiguration>(); configuration.Type = type; ObjectConstructionArgs args = new ObjectConstructionArgs(context, abstractTypeCreationContext, configuration, service); //Act _task.Execute(args); byte[] serialized = Serialize(args.Result); /*SerializationInfo info = new SerializationInfo(typeof(IStubInterface),); * StreamingContext context = new StreamingContext(); * ProxyObjectReference pr = new ProxyObjectReference(info, new StreamingContext() )*/ IStubInterface deserialized = Deserialize <IStubInterface>(serialized); //Assert Assert.IsNotNull(args.Result); Assert.IsTrue(args.IsAborted); Assert.IsTrue(args.Result is IStubInterface); Assert.IsFalse(args.Result.GetType() == typeof(IStubInterface)); }
public void CanSerializeAndDeserializeGeneratedInterface() { //Assign string path = "/sitecore/content/Target"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("Target") }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(IStubInterface))); var service = new SitecoreService(database.Database); //Act IStubInterface result = service.GetItem <IStubInterface>(path); // Console.Write(result.Path); byte[] serialized = Serialize(result); IStubInterface deserialized = Deserialize <IStubInterface>(serialized); //Assert Assert.IsNotNull(deserialized); Assert.AreNotEqual(result, deserialized); Assert.AreEqual(path, deserialized.Path); } }
public void CanSerializeAndDeserializeStandardProxy() { var builder = new PersistentProxyBuilder(); var generator = new ProxyGenerator(builder); object proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IStubInterface), new Type[] { }, new StandardInterceptor()); byte[] serialized = Serialize(proxy); IStubInterface deserialized = Deserialize <IStubInterface>(serialized); }
public void CanSerializeAndDeserializeGeneratedInterface() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); var db = Factory.GetDatabase("master"); var service = new SitecoreService(db); string path = "/sitecore/content/Tests/SitecoreService/GetItem/EmptyItem"; //Act IStubInterface result = service.GetItem <IStubInterface>(path); // Console.Write(result.Path); byte[] serialized = Serialize(result); IStubInterface deserialized = Deserialize <IStubInterface>(serialized); //Assert Assert.IsNotNull(deserialized); Assert.AreNotEqual(result, deserialized); Assert.AreEqual("/sitecore/content/Tests/SitecoreService/GetItem/EmptyItem", deserialized.Path); }