public void Execute_ProxyInterface_ProxyGetsCreated() { //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); //Assert Assert.IsNotNull(args.Result); Assert.IsTrue(args.IsAborted); Assert.IsTrue(args.Result is IStubInterface); Assert.IsFalse(args.Result.GetType() == typeof(IStubInterface)); }
public void Execute_ResultAlreadySet_DoesNoWork() { //Assign Type type = typeof(IStubInterface); var resolver = Substitute.For <IDependencyResolver>(); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(resolver); 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); args.Result = string.Empty; //Act _task.Execute(args); //Assert Assert.IsNotNull(args.Result); Assert.IsFalse(args.IsAborted); Assert.IsTrue(args.Result is string); }
public void Execute_ConcreteClass_ObjectNotCreated() { //Assign Type type = typeof(StubClass); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext.RequestedType = type; var configuration = Substitute.For <AbstractTypeConfiguration>(); configuration.Type = type; ObjectConstructionArgs args = new ObjectConstructionArgs(context, abstractTypeCreationContext, configuration, service); //Act _task.Execute(args); //Assert Assert.IsNull(args.Result); Assert.IsFalse(args.IsAborted); }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject(object obj, IAbstractService service, AbstractTypeCreationContext context) { try { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); foreach (var prop in Properties) { try { prop.Mapper.MapCmsToProperty(dataMappingContext); } catch (Exception e) { throw new MapperException( "Failed to map property {0} on {1}".Formatted(prop.PropertyInfo.Name, prop.PropertyInfo.DeclaringType.FullName), e); } } } catch (Exception ex) { throw new MapperException( "Failed to map properties on {0}.".Formatted(context.DataSummary()), ex); } }
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 Execute_LazyType_LazyTypeCreated() { //Assign Type type = typeof(StubClass); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext.RequestedType = typeof(StubClass); abstractTypeCreationContext.IsLazy = true; var configuration = Substitute.For <AbstractTypeConfiguration>(); configuration.Type = type; configuration.ConstructorMethods = Utilities.CreateConstructorDelegates(type); ObjectConstructionArgs args = new ObjectConstructionArgs(context, abstractTypeCreationContext, configuration, service); //Act _task.Execute(args); //Assert Assert.IsTrue(args.IsAborted); Assert.IsNotNull(args.Result); Assert.IsTrue(args.Result is StubClass); Assert.IsFalse(args.Result.GetType() == typeof(StubClass)); }
public void Execute_ResultAlreadySet_DoesNoWork() { //Assign Type type = typeof(StubClass); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext.RequestedType = typeof(StubClass); var configuration = Substitute.For <AbstractTypeConfiguration>(); configuration.ConstructorMethods = Utilities.CreateConstructorDelegates(type); configuration.Type = type; ObjectConstructionArgs args = new ObjectConstructionArgs(context, abstractTypeCreationContext, configuration, service, new ModelCounter()); args.Result = string.Empty; //Act _task.Execute(args); //Assert Assert.IsNotNull(args.Result); Assert.IsTrue(args.Result is string); }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject(object obj, IAbstractService service, AbstractTypeCreationContext context) { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); foreach (var prop in Properties) { prop.Mapper.MapCmsToProperty(dataMappingContext); } }
/// <summary> /// Initializes a new instance of the <see cref="ObjectConstructionArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> /// <param name="configuration">The configuration.</param> /// <param name="service">The service.</param> public ObjectConstructionArgs( Context context, AbstractTypeCreationContext abstractTypeCreationContext, AbstractTypeConfiguration configuration, IAbstractService service) : base(context) { AbstractTypeCreationContext = abstractTypeCreationContext; Configuration = configuration; Service = service; }
public void GetTypeConfiguration_TwoInterfacesWithTheSameNameUsingCastleProxy_ReturnsEachCorrectly() { //Arrange string contextName = "testContext"; bool isDefault = true; var type = typeof(NS1.ProxyTest1); var service = Substitute.For <IAbstractService>(); var task = new CreateInterfaceTask(); #region CreateTypes Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext1 = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext1.RequestedType = typeof(NS1.ProxyTest1); var configuration1 = Substitute.For <AbstractTypeConfiguration>(); configuration1.Type = typeof(NS1.ProxyTest1); ObjectConstructionArgs args1 = new ObjectConstructionArgs(context, abstractTypeCreationContext1, configuration1, service); AbstractTypeCreationContext abstractTypeCreationContext2 = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext2.RequestedType = typeof(NS2.ProxyTest1); var configuration2 = Substitute.For <AbstractTypeConfiguration>(); configuration2.Type = typeof(NS2.ProxyTest1); ObjectConstructionArgs args2 = new ObjectConstructionArgs(context, abstractTypeCreationContext2, configuration2, service); //Act task.Execute(args1); task.Execute(args2); #endregion context.GetTypeConfiguration <StubAbstractTypeConfiguration>(typeof(NS1.ProxyTest1)); context.GetTypeConfiguration <StubAbstractTypeConfiguration>(typeof(NS2.ProxyTest1)); //Act var config1 = context.GetTypeConfiguration <StubAbstractTypeConfiguration>(args1.Result.GetType()); var config2 = context.GetTypeConfiguration <StubAbstractTypeConfiguration>(args2.Result.GetType()); //Assert Assert.AreEqual(typeof(NS1.ProxyTest1), config1.Type); Assert.AreEqual(typeof(NS2.ProxyTest1), config2.Type); }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject(object obj, IAbstractService service, AbstractTypeCreationContext context) { try { if (_properties.Count != 0) { //create properties AbstractDataMappingContext dataMappingContext = context.CreateDataMappingContext(obj); foreach (var property in _properties.Values) { var prop = property; try { prop.Mapper.MapCmsToProperty(dataMappingContext); } catch (MapperStackException) { throw; } catch (Exception e) { throw new MapperException( "Failed to map property {0} on {1}".Formatted(prop.PropertyInfo.Name, prop.PropertyInfo.DeclaringType.FullName), e); } } } } catch (MapperStackException) { throw; } catch (Exception ex) { throw new MapperException( "Failed to map properties on {0}.".Formatted(context.DataSummary()), ex); } MapPrivatePropertiesToObject(obj, service, context); }
public void Execute_TwoClassesWithTheSameName_ProxyGetsCreated() { //Assign var glassConfig = Substitute.For <IGlassConfiguration>(); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext1 = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext1.RequestedType = typeof(NS1.ProxyTest1); var configuration1 = Substitute.For <AbstractTypeConfiguration>(); configuration1.Type = typeof(NS1.ProxyTest1); ObjectConstructionArgs args1 = new ObjectConstructionArgs(context, abstractTypeCreationContext1, configuration1, service); AbstractTypeCreationContext abstractTypeCreationContext2 = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext2.RequestedType = typeof(NS2.ProxyTest1); var configuration2 = Substitute.For <AbstractTypeConfiguration>(); configuration2.Type = typeof(NS2.ProxyTest1);; ObjectConstructionArgs args2 = new ObjectConstructionArgs(context, abstractTypeCreationContext2, configuration2, service); //Act _task.Execute(args1); _task.Execute(args2); //Assert Assert.IsNotNull(args1.Result); Assert.IsFalse(args1.IsAborted); Assert.IsTrue(args1.Result is NS1.ProxyTest1); Assert.IsFalse(args1.Result.GetType() == typeof(NS1.ProxyTest1)); Assert.IsNotNull(args2.Result); Assert.IsFalse(args2.IsAborted); Assert.IsTrue(args2.Result is NS2.ProxyTest1); Assert.IsFalse(args2.Result.GetType() == typeof(NS2.ProxyTest1)); }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject(object obj, IAbstractService service, AbstractTypeCreationContext context) { try { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); _propertMappingExpression(obj, dataMappingContext); //var tasks = Properties.Select(x => // { // var t = new Task(() => x.Mapper.MapCmsToProperty(dataMappingContext)); // t.Start(); // return t; // }); //Task.WaitAll(tasks.ToArray()); //for(int i = Properties.Length-1; i >= 0; i--) //{ // var prop = Properties[i]; // try // { // prop.Mapper.MapCmsToProperty(context); // } // catch (Exception e) // { // throw new MapperException( // "Failed to map property {0} on {1}".Formatted(prop.PropertyInfo.Name, // prop.PropertyInfo.DeclaringType.FullName), e); // } //} } catch (Exception ex) { throw new MapperException( "Failed to map properties on {0}.".Formatted(context.DataSummary()), ex); } }
public void Execute_TypeIsInterface_NoObjectCreated() { //Assign Type type = typeof(IStubInterface); var service = Substitute.For <IAbstractService>(); Context context = Context.Create(Substitute.For <IDependencyResolver>()); AbstractTypeCreationContext abstractTypeCreationContext = Substitute.For <AbstractTypeCreationContext>(); abstractTypeCreationContext.RequestedType = type; var configuration = Substitute.For <AbstractTypeConfiguration>(); configuration.Type = type; ObjectConstructionArgs args = new ObjectConstructionArgs(context, abstractTypeCreationContext, configuration, service, new ModelCounter()); //Act _task.Execute(args); //Assert Assert.IsNull(args.Result); }
AbstractDataMappingContext ISitecoreService.CreateDataMappingContext(AbstractTypeCreationContext abstractTypeCreationContext, object obj) { return(Service.CreateDataMappingContext(abstractTypeCreationContext, obj)); }
public object InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) { return(Service.InstantiateObject(abstractTypeCreationContext)); }
public override AbstractDataMappingContext CreateDataMappingContext(AbstractTypeCreationContext creationContext, object obj) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationResolverArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> public ConfigurationResolverArgs(Context context, AbstractTypeCreationContext abstractTypeCreationContext) : base(context) { AbstractTypeCreationContext = abstractTypeCreationContext; }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject( object obj, IAbstractService service, AbstractTypeCreationContext context) { try { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); foreach (var prop in Properties) { try { prop.Mapper.MapCmsToProperty(dataMappingContext); } catch (Exception e) { throw new MapperException( "Failed to map property {0} on {1}".Formatted(prop.PropertyInfo.Name, prop.PropertyInfo.DeclaringType.FullName), e); } } } catch (Exception ex) { throw new MapperException( "Failed to map properties on {0}.".Formatted(context.DataSummary()), ex); } }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationResolverArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> public ConfigurationResolverArgs(Context context, AbstractTypeCreationContext abstractTypeCreationContext, Type requestedType, IAbstractService service) : base(context) { Service = service; AbstractTypeCreationContext = abstractTypeCreationContext; RequestedType = requestedType; }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationResolverArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> public ConfigurationResolverArgs(Context context, AbstractTypeCreationContext abstractTypeCreationContext) :base(context) { AbstractTypeCreationContext = abstractTypeCreationContext; }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject( object obj, IAbstractService service, AbstractTypeCreationContext context) { try { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); _propertMappingExpression(obj, dataMappingContext); //var tasks = Properties.Select(x => // { // var t = new Task(() => x.Mapper.MapCmsToProperty(dataMappingContext)); // t.Start(); // return t; // }); //Task.WaitAll(tasks.ToArray()); //for(int i = Properties.Length-1; i >= 0; i--) //{ // var prop = Properties[i]; // try // { // prop.Mapper.MapCmsToProperty(context); // } // catch (Exception e) // { // throw new MapperException( // "Failed to map property {0} on {1}".Formatted(prop.PropertyInfo.Name, // prop.PropertyInfo.DeclaringType.FullName), e); // } //} } catch (Exception ex) { throw new MapperException( "Failed to map properties on {0}.".Formatted(context.DataSummary()), ex); } }
/// <summary> /// Maps the properties to object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="service">The service.</param> /// <param name="context">The context.</param> public void MapPropertiesToObject( object obj, IAbstractService service, AbstractTypeCreationContext context) { //create properties AbstractDataMappingContext dataMappingContext = service.CreateDataMappingContext(context, obj); foreach (var prop in Properties) { prop.Mapper.MapCmsToProperty(dataMappingContext); } }
AbstractDataMappingContext IAbstractService.CreateDataMappingContext(AbstractTypeCreationContext creationContext, object obj) { return(((IAbstractService)Service).CreateDataMappingContext(creationContext, obj)); }
public ConfigurationResolverArgs RunConfigurationPipeline(AbstractTypeCreationContext abstractTypeCreationContext) { return(Service.RunConfigurationPipeline(abstractTypeCreationContext)); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationResolverArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> public ConfigurationResolverArgs(Context context, AbstractTypeCreationContext abstractTypeCreationContext, IAbstractService service) : base(context) { Service = service; AbstractTypeCreationContext = abstractTypeCreationContext; }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationResolverArgs"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> public ConfigurationResolverArgs(Context context, AbstractTypeCreationContext abstractTypeCreationContext, Type requestedType, IAbstractService service) :base(context) { Service = service; AbstractTypeCreationContext = abstractTypeCreationContext; RequestedType = requestedType; }
/// <summary> /// Creates the data mapping context. /// </summary> /// <param name="abstractTypeCreationContext">The abstract type creation context.</param> /// <param name="obj">The obj.</param> /// <returns></returns> public override AbstractDataMappingContext CreateDataMappingContext(AbstractTypeCreationContext abstractTypeCreationContext, Object obj) { var umbTypeContext = abstractTypeCreationContext as UmbracoTypeCreationContext; return(new UmbracoDataMappingContext(obj, umbTypeContext.Content, this)); }