public void DoubleWritePortablePdbDeterministicPdbId() { const string resource = "PdbChecksumLib.dll"; string destination = Path.GetTempFileName(); using (var module = GetResourceModule(resource, new ReaderParameters { ReadSymbols = true })) { module.Write(destination, new WriterParameters { DeterministicMvid = true, WriteSymbols = true }); } byte [] pdbIdOne; using (var module = ModuleDefinition.ReadModule(destination, new ReaderParameters { ReadSymbols = true })) { string pdbPath = Mixin.GetPdbFileName(module.FileName); CalculatePdbChecksumAndId(pdbPath, out byte [] expectedChecksum, out pdbIdOne); } using (var module = GetResourceModule(resource, new ReaderParameters { ReadSymbols = true })) { module.Write(destination, new WriterParameters { DeterministicMvid = true, WriteSymbols = true }); } byte [] pdbIdTwo; using (var module = ModuleDefinition.ReadModule(destination, new ReaderParameters { ReadSymbols = true })) { string pdbPath = Mixin.GetPdbFileName(module.FileName); CalculatePdbChecksumAndId(pdbPath, out byte [] expectedChecksum, out pdbIdTwo); } CollectionAssert.AreEqual(pdbIdOne, pdbIdTwo); }
public void SavesMixedTypes() { AppDomainRunner.Run( delegate { using (MixinConfiguration.BuildNew() .ForClass <BaseType1>().AddMixins(typeof(BT1Mixin1)) .ForClass <Page> ().AddMixin(typeof(NullMixin)) .EnterScope()) { Mixer mixer = Mixer.Create("Assembly", _assemblyOutputDirectory, 1); mixer.PrepareOutputDirectory(); mixer.Execute(MixinConfiguration.ActiveConfiguration); Assembly theAssembly = Assembly.LoadFile(mixer.MixerPipelineFactory.GetModulePaths(_assemblyOutputDirectory).Single()); var types = theAssembly.GetTypes(); var concreteType = types.SingleOrDefault(t => t.BaseType == typeof(BaseType1)); Assert.NotNull(concreteType); Assert.That( MixinTypeUtility.GetClassContextForConcreteType(concreteType), Is.EqualTo(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType1)))); object instance = Activator.CreateInstance(concreteType); Assert.That(Mixin.Get <BT1Mixin1> (instance), Is.Not.Null); var concreteTypeFromSystemAssembly = types.SingleOrDefault(t => t.BaseType == typeof(Page)); Assert.That(concreteTypeFromSystemAssembly, Is.Not.Null); SafeServiceLocator.Current.GetInstance <IPipelineRegistry>().DefaultPipeline.CodeManager.LoadFlushedCode(theAssembly); Type concreteTypeFromFactory = TypeFactory.GetConcreteType(typeof(BaseType1)); Assert.That(concreteTypeFromFactory, Is.SameAs(concreteType)); Assert.That(theAssembly.IsDefined(typeof(NonApplicationAssemblyAttribute), false), Is.True); } }); }
public void GenericMixinsAreSpecialized() { BaseType3 bt3 = CreateMixedObject <BaseType3> (typeof(BT3Mixin3 <,>)); object mixin = Mixin.Get(typeof(BT3Mixin3 <,>), bt3); Assert.That(mixin, Is.Not.Null); PropertyInfo targetProperty = MixinReflector.GetTargetProperty(mixin.GetType()); Assert.That(targetProperty, Is.Not.Null); Assert.That(targetProperty.GetValue(mixin, null), Is.Not.Null); Assert.That(targetProperty.GetValue(mixin, null), Is.SameAs(bt3)); Assert.That(targetProperty.PropertyType, Is.EqualTo(typeof(BaseType3))); PropertyInfo nextProperty = MixinReflector.GetNextProperty(mixin.GetType()); Assert.That(nextProperty, Is.Not.Null); Assert.That(nextProperty.GetValue(mixin, null), Is.Not.Null); Assert.That(nextProperty.GetValue(mixin, null).GetType(), Is.SameAs(bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType)); Assert.That(nextProperty.PropertyType, Is.EqualTo(typeof(IBaseType33))); }
private void GetPdbChecksumData(ImageDebugHeader debugHeader, out string algorithmName, out byte [] checksum) { var entry = Mixin.GetPdbChecksumEntry(debugHeader); Assert.IsNotNull(entry); var length = Array.IndexOf(entry.Data, (byte)0, 0); var bytes = new byte [length]; Buffer.BlockCopy(entry.Data, 0, bytes, 0, length); algorithmName = Encoding.UTF8.GetString(bytes); int checksumSize = 0; switch (algorithmName) { case "SHA256": checksumSize = 32; break; case "SHA384": checksumSize = 48; break; case "SHA512": checksumSize = 64; break; } checksum = new byte [checksumSize]; Buffer.BlockCopy(entry.Data, length + 1, checksum, 0, checksumSize); }
public void MixedDerivedMixin_Serialization() { var instance = ObjectFactory.Create <ClassWithMixedDerivedMixin> (ParamList.Empty); var derivedMixin = Mixin.Get <MixinMixingClassRequiringToBeDerived> (instance); var mixinType = derivedMixin.GetType(); Assert.That(Pipeline.ReflectionService.IsAssembledType(mixinType), Is.True, "Mixed mixin."); var underlyingType = Pipeline.ReflectionService.GetRequestedType(mixinType); Assert.That(underlyingType, Is.Not.SameAs(typeof(MixinMixingClassRequiringToBeDerived)), "Derived mixin."); Assert.That(underlyingType.BaseType, Is.SameAs(typeof(MixinMixingClassRequiringToBeDerived))); var mixinMixin = Mixin.Get <MixinMixingDerivedMixin> (derivedMixin); Assert.That(mixinMixin, Is.Not.Null); var deserialized = Serializer.SerializeAndDeserialize(instance); Assert.That( deserialized.StringMethod(3), Is.EqualTo("MixinMixingDerivedMixin-MixinMixingClassRequiringToBeDerived-ClassWithMixedDerivedMixin.StringMethod (3)")); }
public void LoadFlushedCode_IncludesSerializationHelperTypes() { var mixedInstance = CreateMixedObject <ClassOverridingMixinMembers> (typeof(MixinWithAbstractMembers)); var mixin = Mixin.Get <MixinWithAbstractMembers> (mixedInstance); var serializedData = Serializer.Serialize(mixedInstance); //var identifier = GetConcreteMixinIdentifier(mixin); var assembly = FlushAndLoadAssemblyWithoutLocking(); //var pipelineForLoading = CreatePipeline(); //using (new ServiceLocatorScope()) //{ // SafeServiceLocator.Current.GetInstance<IPipelineRegistry>().SetDefaultPipeline (pipelineForLoading); // pipelineForLoading.CodeManager.LoadFlushedCode (assembly); // //var loadedMixinType = pipelineForLoading.ReflectionService.GetAdditionalType (identifier); // //Assert.That (loadedMixinType, Is.Not.Null); // //Assert.That (loadedMixinType.Assembly, Is.EqualTo (assembly)); // var mixedInstanceA = (ClassOverridingMixinMembers) Serializer.Deserialize (serializedData); // var mixinA = Mixin.Get<MixinWithAbstractMembers> (mixedInstanceA); // //Assert.That (mixin2, Is.TypeOf (loadedMixinType)); //} }
public void WithoutSetter() { IBusinessObject businessObject = Mixin.Get <BindableObjectMixin> (ObjectFactory.Create <SimpleBusinessObjectClass>(ParamList.Empty)); businessObject.SetProperty("StringWithoutSetter", null); }
public ParameterDefinition GetParameter(int index) { return(Mixin.GetParameter(body, index)); }
public static bool GetHasMarshalInfo( IMarshalInfoProvider self, ModuleDefinition module) { return(Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasMarshalInfo(provider))); }
public MasterWrapper(IMixinRequirements target) { this.Mixin = new DefaultMixinActivator() .CreateInstance < AbstractWrapper >(target); base.Initialize(target, Mixin, new List<IMixinInterceptor>()); }
public void DoubleMixinOverrides_CreateMixinInstance() { MixinMixingClass instance = ObjectFactory.Create <MixinMixingClass> (ParamList.Empty); Assert.That(Mixin.Get <MixinMixingMixin> (instance), Is.Not.Null); }
public ISymbolWriter GetSymbolWriter(ModuleDefinition module, Stream symbolStream) { Mixin.CheckModule(module); Mixin.CheckStream(symbolStream); return(GetSymbolWriter(module, Disposable.NotOwned(symbolStream))); }
public void CreateObjectReference_PreparesMixins() { var instance = _domainObjectCreator.CreateObjectReference(_targetClassForPersistentMixinInitializationContext, _transaction); Assert.That(Mixin.Get <MixinAddingPersistentProperties> (instance), Is.Not.Null); }
public CustomAttributeArgument(TypeReference type, object value) { Mixin.CheckType(type); this.type = type; this.value = value; }
public void DomainObjectsCanBeMixed() { var domainObject = TargetClassForBehavioralMixin.NewObject(); Assert.That(Mixin.Get <NullMixin> (domainObject), Is.Not.Null); }
public ModuleReference(string name) : this() { Mixin.CheckName(name); this.name = name; }
public VariableDefinition GetVariable(int index) { return(Mixin.GetVariable(body, index)); }
public void MixinStateIsRestored() { var instance = TargetClassForMixinWithState.NewObject(); Mixin.Get <MixinWithState> (instance).State = "Sto stas stat stamus statis stant"; var deserializedObjects = Serializer.SerializeAndDeserialize(Tuple.Create(ClientTransactionScope.CurrentTransaction, instance)); Assert.That(Mixin.Get <MixinWithState> (deserializedObjects.Item2), Is.Not.SameAs(Mixin.Get <MixinWithState> (instance))); Assert.That(Mixin.Get <MixinWithState> (deserializedObjects.Item2).State, Is.EqualTo("Sto stas stat stamus statis stant")); }
public void ThisCallToDuckInterface() { BaseTypeWithDuckTargetCallMixin duckTargetCall = ObjectFactory.Create <BaseTypeWithDuckTargetCallMixin> (ParamList.Empty); Assert.That(Mixin.Get <DuckTargetCallMixin> (duckTargetCall).CallMethodsOnThis(), Is.EqualTo("DuckTargetCallMixin.CallMethodsOnThis-DuckTargetCallMixin.MethodImplementedOnBase-BaseTypeWithDuckTargetCallMixin.ProtectedMethodImplementedOnBase")); }
public static string GetPdbFileName(string assemblyFileName) { return(Mixin.GetPdbFileName(assemblyFileName)); }
public void Initialize() { Assert.That(_serviceMixin, Is.Not.Null); Assert.That(_serviceMixin, Is.InstanceOf(typeof(IBusinessObjectServiceFactory))); Assert.That(Mixin.Get <BindableDomainObjectServiceFactoryMixin> (_serviceFactory), Is.Not.Null); }
public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream) { Mixin.CheckModule(module); Mixin.CheckStream(symbolStream); return(GetSymbolReader(module, Disposable.NotOwned(symbolStream), symbolStream.GetFileName())); }
public void Add(Mixin m) { count++; name = m.name; // we store by uniqueness of isInventoriable name data.Add(m); }
public void NestedDomainObjects_CanBeMixed() { DomainObject domainObject = NestedDomainObject.NewObject(); Assert.That(Mixin.Get <NullMixin> (domainObject), Is.Not.Null); }
public void Stack(Mixin m) { data.Add(m); }
protected EventReference(string name, TypeReference eventType) : base(name) { Mixin.CheckType(eventType, Mixin.Argument.eventType); event_type = eventType; }
public void MixinGet_ReturnsNullIfMixinNotFound() { var mixin = Mixin.Get <BT3Mixin2> (new object()); Assert.That(mixin, Is.Null); }
public TargetClassGettingMixinFromCtor() { MixinInstance = Mixin.Get <NullMixin> (this); }
public CustomAttributeNamedArgument(string name, CustomAttributeArgument argument) { Mixin.CheckName(name); this.name = name; this.argument = argument; }
public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream) { if (module.Image.HasDebugTables()) { return(null); } if (module.HasDebugHeader) { var header = module.GetDebugHeader(); var entry = header.GetEmbeddedPortablePdbEntry(); if (entry != null) { return(new EmbeddedPortablePdbReaderProvider().GetSymbolReader(module, "")); } } Mixin.CheckStream(symbolStream); Mixin.CheckReadSeek(symbolStream); var position = symbolStream.Position; const int portablePdbHeader = 0x424a5342; var reader = new BinaryStreamReader(symbolStream); var intHeader = reader.ReadInt32(); symbolStream.Position = position; if (intHeader == portablePdbHeader) { return(new PortablePdbReaderProvider().GetSymbolReader(module, symbolStream)); } const string nativePdbHeader = "Microsoft C/C++ MSF 7.00"; var bytesHeader = reader.ReadBytes(nativePdbHeader.Length); symbolStream.Position = position; var isNativePdb = true; for (var i = 0; i < bytesHeader.Length; i++) { if (bytesHeader [i] != (byte)nativePdbHeader [i]) { isNativePdb = false; break; } } if (isNativePdb) { try { return(SymbolProvider.GetReaderProvider(SymbolKind.NativePdb).GetSymbolReader(module, symbolStream)); } catch (Exception) { // We might not include support for native pdbs. } } const long mdbHeader = 0x45e82623fd7fa614; var longHeader = reader.ReadInt64(); symbolStream.Position = position; if (longHeader == mdbHeader) { try { return(SymbolProvider.GetReaderProvider(SymbolKind.Mdb).GetSymbolReader(module, symbolStream)); } catch (Exception) { // We might not include support for mdbs. } } if (throw_if_no_symbol) { throw new SymbolsNotFoundException(string.Format("No symbols found in stream")); } return(null); }
public void ResolveMandatoryPropertyAccessorData_Expression_Mixin_ViaMixin() { var cacheWithMixins = new PropertyAccessorDataCache(GetTypeDefinition(typeof(TargetClassForPersistentMixin))); var data = cacheWithMixins.ResolveMandatoryPropertyAccessorData((TargetClassForPersistentMixin t) => (Mixin.Get <MixinAddingPersistentProperties> (t).PersistentProperty)); Assert.That(data, Is.Not.Null); Assert.That(data, Is.EqualTo(cacheWithMixins.GetPropertyAccessorData(typeof(MixinAddingPersistentProperties).FullName + ".PersistentProperty"))); }