public void GenerateXml_InterfaceDynamicallyImplemented() { var targetType = new InvolvedType (typeof (TargetClass3)); var mixinConfiguration = MixinConfiguration.BuildNew ().ForClass<TargetClass3> ().AddMixin<Mixin4> ().BuildConfiguration (); targetType.ClassContext = new ReflectedObject (mixinConfiguration.ClassContexts.First ()); targetType.TargetClassDefinition = new ReflectedObject (TargetClassDefinitionUtility.GetConfiguration (targetType.Type, mixinConfiguration)); var mixinContext = targetType.ClassContext.GetProperty ("Mixins").First (); var mixinDefinition = targetType.TargetClassDefinition.CallMethod ("GetMixinByConfiguredType", mixinContext.GetProperty ("MixinType").To<Type> ()); var assemblyIdentifierGenerator = new IdentifierGenerator<Assembly> (); var output = new TargetCallDependenciesReportGenerator (mixinDefinition, assemblyIdentifierGenerator, _remotionReflector, _outputFormatter).GenerateXml (); var expectedOutput = new XElement ("TargetCallDependencies", new XElement ("Dependency", new XAttribute ("assembly-ref", "0"), new XAttribute ("namespace", "System"), new XAttribute ("name", "IDisposable"), new XAttribute ("is-interface", true), new XAttribute ("is-implemented-by-target", false), new XAttribute ("is-added-by-mixin", false), new XAttribute ("is-implemented-dynamically", true))); XElementComparisonHelper.Compare (output, expectedOutput); }
public void GenerateXml_WithAttributes() { // Mixin2 has Serializable attribute var involvedType = new InvolvedType (typeof (Mixin2)); var attributeIdentifier = new IdentifierGenerator<Type>(); attributeIdentifier.GetIdentifier (typeof (SerializableAttribute)); var reportGenerator = CreateReportGenerator (attributeIdentifier, involvedType); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement ( "Attributes", new XElement ( "Attribute", new XAttribute ("id", "0"), new XAttribute ("assembly-ref", "0"), new XAttribute ("namespace", "System"), new XAttribute ("name", "SerializableAttribute"), new XElement ( "AppliedTo", new XElement ( "InvolvedType-Reference", new XAttribute ("ref", "0") ) ) ) ); Assert.That (output.ToString(), Is.EqualTo (expectedOutput.ToString())); }
public void GenerateXml_WithIntroducedInterfaces() { var interfaceIdentifierGenerator = new IdentifierGenerator<Type>(); var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass<TargetClass2>().AddMixin<Mixin3>() .BuildConfiguration(); var type1 = new InvolvedType (typeof (TargetClass2)); type1.ClassContext = new ReflectedObject (mixinConfiguration.ClassContexts.First()); // TargetClass2 does not implement any interface // Mixin3 introduces interface IDisposable var interfaceIntroductions = GetInterfaceIntroductions (type1, typeof (Mixin3), mixinConfiguration); var reportGenerator = new InterfaceIntroductionReportGenerator (interfaceIntroductions, interfaceIdentifierGenerator); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement ( "InterfaceIntroductions", new XElement ( "IntroducedInterface", new XAttribute ("ref", "0") )); Assert.That (output.ToString(), Is.EqualTo (expectedOutput.ToString())); }
public void GenerateXml_WithIntroducedAttributes() { var attributeIdentifierGenerator = new IdentifierGenerator<Type>(); var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass<UselessObject>().AddMixin<ObjectWithInheritableAttribute>() .BuildConfiguration(); var type1 = new InvolvedType (typeof (UselessObject)); type1.ClassContext = new ReflectedObject (mixinConfiguration.ClassContexts.First()); var attributeIntroductions = GetAttributeIntroductions (type1, typeof (ObjectWithInheritableAttribute), mixinConfiguration); var reportGenerator = new AttributeIntroductionReportGenerator ( attributeIntroductions, attributeIdentifierGenerator, Helpers.RemotionReflectorFactory.GetRemotionReflection ()); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement ( "AttributeIntroductions", new XElement ( "IntroducedAttribute", new XAttribute ("ref", "0") )); Assert.That (output.ToString(), Is.EqualTo (expectedOutput.ToString())); }
public void GetIdentifier2_ForNonExistingValue() { var identifierGenerator = new IdentifierGenerator<string>(); var output = identifierGenerator.GetIdentifier ("test-value", "default value if not present"); Assert.That (output, Is.EqualTo ("default value if not present")); }
public void TestDictionaryNonIdentifiableItemsDeserialization() { ShadowObject.Enable = true; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(YamlDictionaryNonIdentifiable); writer.Flush(); stream.Position = 0; var instance = AssetYamlSerializer.Default.Deserialize(stream); Assert.NotNull(instance); Assert.Equal(typeof(ContainerNonIdentifiableDictionary), instance.GetType()); var obj = (ContainerNonIdentifiableDictionary)instance; Assert.Equal("Root", obj.Name); Assert.Equal(2, obj.Objects.Count); Assert.Equal("aaa", obj.Objects["AAA"].Name); Assert.Equal(2, obj.Objects["AAA"].Strings.Count); Assert.Equal("bbb", obj.Objects["AAA"].Strings[0]); Assert.Equal("ccc", obj.Objects["AAA"].Strings[1]); Assert.Equal("ddd", obj.Objects["BBB"].Name); Assert.Equal(2, obj.Objects["BBB"].Strings.Count); Assert.Equal("eee", obj.Objects["BBB"].Strings[0]); Assert.Equal("fff", obj.Objects["BBB"].Strings[1]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.Equal(IdentifierGenerator.Get(2), objectIds["AAA"]); Assert.Equal(IdentifierGenerator.Get(1), objectIds["BBB"]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["AAA"].Strings); Assert.Equal(IdentifierGenerator.Get(5), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(6), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["BBB"].Strings); Assert.Equal(IdentifierGenerator.Get(7), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(8), objectIds[1]); Assert.Equal(2, obj.NonIdentifiableObjects.Count); Assert.Equal("ggg", obj.NonIdentifiableObjects["CCC"].Name); Assert.Equal(2, obj.NonIdentifiableObjects["CCC"].Strings.Count); Assert.Equal("hhh", obj.NonIdentifiableObjects["CCC"].Strings[0]); Assert.Equal("iii", obj.NonIdentifiableObjects["CCC"].Strings[1]); Assert.Equal("jjj", obj.NonIdentifiableObjects["DDD"].Name); Assert.Equal(2, obj.NonIdentifiableObjects["DDD"].Strings.Count); Assert.Equal("kkk", obj.NonIdentifiableObjects["DDD"].Strings[0]); Assert.Equal("lll", obj.NonIdentifiableObjects["DDD"].Strings[1]); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj.NonIdentifiableObjects, out objectIds)); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects); Assert.Equal(0, objectIds.KeyCount); Assert.Equal(0, objectIds.DeletedCount); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["CCC"].Strings); Assert.Equal(IdentifierGenerator.Get(9), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(10), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["DDD"].Strings); Assert.Equal(IdentifierGenerator.Get(11), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(12), objectIds[1]); }
public void TestCollectionMismatchId() { const string baseYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset2,SiliconStudio.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] Struct: MyStrings: {} MyStrings: 0a0000000a0000000a0000000a000000: String1 14000000140000001400000014000000: String2 "; const string derivedYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset2,SiliconStudio.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] Struct: MyStrings: {} MyStrings: 1a0000001a0000001a0000001a000000: String1 14000000140000001400000014000000: String2 "; var context = DeriveAssetTest <Types.MyAsset2> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyStrings); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyStrings); Assert.AreEqual(2, context.BaseAsset.MyStrings.Count); Assert.AreEqual("String1", context.BaseAsset.MyStrings[0]); Assert.AreEqual("String2", context.BaseAsset.MyStrings[1]); Assert.AreEqual(2, context.DerivedAsset.MyStrings.Count); Assert.AreEqual("String1", context.DerivedAsset.MyStrings[0]); Assert.AreEqual("String2", context.DerivedAsset.MyStrings[1]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds[0]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds[1]); Assert.AreEqual(2, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(26), derivedIds[0]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds[1]); context.DerivedGraph.ReconcileWithBase(); Assert.AreEqual(2, context.BaseAsset.MyStrings.Count); Assert.AreEqual("String1", context.BaseAsset.MyStrings[0]); Assert.AreEqual("String2", context.BaseAsset.MyStrings[1]); Assert.AreEqual(2, context.DerivedAsset.MyStrings.Count); Assert.AreEqual("String1", context.DerivedAsset.MyStrings[0]); Assert.AreEqual("String2", context.DerivedAsset.MyStrings[1]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds[0]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds[1]); Assert.AreEqual(2, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), derivedIds[0]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds[1]); }
private AttributeReportGenerator CreateReportGenerator(IdentifierGenerator <Type> attributeIdentifier, params InvolvedType[] involvedTypes) { return(new AttributeReportGenerator( involvedTypes, new IdentifierGenerator <Assembly>(), new IdentifierGenerator <Type>(), attributeIdentifier, Helpers.RemotionReflectorFactory.GetRemotionReflection(), new OutputFormatter())); }
public void GetIdentifier2_ForExistingValue() { var identifierGenerator = new IdentifierGenerator<string>(); var expectedOuput = identifierGenerator.GetIdentifier ("test-value"); var output = identifierGenerator.GetIdentifier ("test-value", "does not matter"); Assert.That (output, Is.EqualTo (expectedOuput)); }
public void GetIdentifier_NonExistingItem() { var identifierGenerator = new IdentifierGenerator <string>(); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator <string>(identifierGenerator, "dummy-value"); var output = readonlyIdentifierGenerator.GetIdentifier("key-1"); Assert.That(output, Is.EqualTo("dummy-value")); }
public void GetIdentifier2_NonExistingItem() { var identifierGenerator = new IdentifierGenerator <string>(); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator <string>(identifierGenerator, "does not matter EITHER"); var output = readonlyIdentifierGenerator.GetIdentifier("key-1", "default value"); Assert.That(output, Is.EqualTo("default value")); }
public void GetIdentifier_NonExistingItem() { var identifierGenerator = new IdentifierGenerator<string>(); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator<string>(identifierGenerator, "dummy-value"); var output = readonlyIdentifierGenerator.GetIdentifier ("key-1"); Assert.That (output, Is.EqualTo ("dummy-value")); }
public void GetIdentifier2_ForExistingValue() { var identifierGenerator = new IdentifierGenerator <string>(); var expectedOuput = identifierGenerator.GetIdentifier("test-value"); var output = identifierGenerator.GetIdentifier("test-value", "does not matter"); Assert.That(output, Is.EqualTo(expectedOuput)); }
public void GetIdentifier2_NonExistingItem() { var identifierGenerator = new IdentifierGenerator<string>(); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator<string>(identifierGenerator, "does not matter EITHER"); var output = readonlyIdentifierGenerator.GetIdentifier("key-1", "default value"); Assert.That(output, Is.EqualTo("default value")); }
public void SetDefaultProvider() { var provider = new Provider { Name = "provider", Ukprn = long.Parse(IdentifierGenerator.GenerateIdentifier(8, false)) }; Providers = new[] { provider }; }
public void GenerateId_AssessmentSectionNull_ThrowsArgumentNullException() { // Call void Call() => IdentifierGenerator.GeneratedId(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("assessmentSection", exception.ParamName); }
public void TestDictionaryRemovedItemFromBase() { const string baseYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset3,SiliconStudio.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 14000000140000001400000014000000~Key3: String3 "; const string derivedYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset3,SiliconStudio.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 24000000240000002400000024000000~Key2: String2 14000000140000001400000014000000~Key3: String3 "; var context = DeriveAssetTest <Types.MyAsset3> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); Assert.AreEqual(2, context.BaseAsset.MyDictionary.Count); Assert.AreEqual("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.BaseAsset.MyDictionary["Key3"]); Assert.AreEqual(3, context.DerivedAsset.MyDictionary.Count); Assert.AreEqual("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.AreEqual("String2", context.DerivedAsset.MyDictionary["Key2"]); Assert.AreEqual("String3", context.DerivedAsset.MyDictionary["Key3"]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds["Key3"]); Assert.AreEqual(3, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(36), derivedIds["Key2"]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds["Key3"]); context.DerivedGraph.ReconcileWithBase(); Assert.AreEqual(2, context.BaseAsset.MyDictionary.Count); Assert.AreEqual("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.BaseAsset.MyDictionary["Key3"]); Assert.AreEqual(2, context.DerivedAsset.MyDictionary.Count); Assert.AreEqual("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.DerivedAsset.MyDictionary["Key3"]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds["Key3"]); Assert.AreEqual(2, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds["Key3"]); }
/// <summary> /// Creates an instance of <see cref="SerializableAssessmentSection"/> /// based on <paramref name="assessmentSection"/>. /// </summary> /// <param name="assessmentSection">The <see cref="ExportableAssessmentSection"/> /// to create a <see cref="SerializableAssessmentSection"/> for.</param> /// <returns>A <see cref="SerializableAssessmentSection"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static SerializableAssessmentSection Create(ExportableAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } return(new SerializableAssessmentSection(IdentifierGenerator.GeneratedId(assessmentSection), assessmentSection.Name, assessmentSection.Geometry)); }
/// <summary> /// Creates an instance of <see cref="SerializableAssessmentProcess"/> /// based on its input parameters. /// </summary> /// <param name="idGenerator">The generator to generate an id for the /// <see cref="SerializableAssessmentProcess"/>.</param> /// <param name="assessmentSection">The <see cref="SerializableAssessmentSection"/> /// this process belongs to.</param> /// <returns>A <see cref="SerializableAssessmentProcess"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static SerializableAssessmentProcess Create(IdentifierGenerator idGenerator, SerializableAssessmentSection assessmentSection) { if (idGenerator == null) { throw new ArgumentNullException(nameof(idGenerator)); } return(new SerializableAssessmentProcess(idGenerator.GetNewId(Resources.SerializableAssessmentProcess_IdPrefix), assessmentSection)); }
public void Create_WithValidArguments_ReturnsAggregatedSerializableFailureMechanism() { // Setup var random = new Random(21); var failureMechanism = new ExportableFailureMechanism( ExportableFailureMechanismAssemblyResultTestFactory.CreateResult(), new[] { ExportableFailureMechanismSectionAssemblyResultTestFactory.CreateWithProbability( ExportableFailureMechanismSectionTestFactory.CreateExportableFailureMechanismSection(random.Next()), random.Next()), ExportableFailureMechanismSectionAssemblyResultTestFactory.CreateWithProbability( ExportableFailureMechanismSectionTestFactory.CreateExportableFailureMechanismSection(random.Next()), random.Next()) }, random.NextEnumValue <ExportableFailureMechanismType>(), "code", "name"); var idGenerator = new IdentifierGenerator(); const string totalAssemblyId = "totalAssemblyId"; var serializableTotalAssembly = new SerializableTotalAssemblyResult(totalAssemblyId, new SerializableAssessmentProcess(), random.NextEnumValue <SerializableAssemblyMethod>(), random.NextEnumValue <SerializableAssemblyMethod>(), random.NextEnumValue <SerializableAssessmentSectionAssemblyGroup>(), random.NextDouble()); // Call AggregatedSerializableFailureMechanism aggregatedFailureMechanism = AggregatedSerializableFailureMechanismCreator.Create(idGenerator, serializableTotalAssembly, failureMechanism); // Assert SerializableFailureMechanism serializableFailureMechanism = aggregatedFailureMechanism.FailureMechanism; Assert.AreEqual("Fm.0", serializableFailureMechanism.Id); Assert.AreEqual(serializableTotalAssembly.Id, serializableFailureMechanism.TotalAssemblyResultId); Assert.AreEqual(SerializableFailureMechanismTypeCreator.Create(failureMechanism.FailureMechanismType), serializableFailureMechanism.FailureMechanismType); Assert.AreEqual(failureMechanism.Code, serializableFailureMechanism.GenericFailureMechanismCode); SerializableFailureMechanismAssemblyResultTestHelper.AssertSerializableFailureMechanismAssemblyResult(failureMechanism.FailureMechanismAssembly, serializableFailureMechanism.FailureMechanismAssemblyResult); SerializableFailureMechanismSectionCollection serializableFailureMechanismSectionCollection = aggregatedFailureMechanism.FailureMechanismSectionCollection; Assert.AreEqual("Vi.0", serializableFailureMechanismSectionCollection.Id); AssertFailureMechanismSectionAssemblies(failureMechanism, serializableFailureMechanismSectionCollection, serializableFailureMechanism, aggregatedFailureMechanism.FailureMechanismSections, aggregatedFailureMechanism.FailureMechanismSectionAssemblyResults); }
public void GetNewId_WithPrefix_ReturnsExpectedValue() { // Setup const string prefix = "prefix"; var generator = new IdentifierGenerator(); // Call string id = generator.GetNewId(prefix); // Assert Assert.AreEqual($"{prefix}.0", id); }
public void TestDictionaryKeyCollision() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset3,Stride.Core.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 14000000140000001400000014000000~Key2: String2 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset3,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 15000000150000001500000015000000*~Key2: String3 "; var context = DeriveAssetTest <Types.MyAsset3, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); Assert.Equal(2, context.BaseAsset.MyDictionary.Count); Assert.Equal("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.Equal("String2", context.BaseAsset.MyDictionary["Key2"]); Assert.Equal(2, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.Equal("String3", context.DerivedAsset.MyDictionary["Key2"]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(20), baseIds["Key2"]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(0, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(21), derivedIds["Key2"]); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(2, context.BaseAsset.MyDictionary.Count); Assert.Equal("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.Equal("String2", context.BaseAsset.MyDictionary["Key2"]); Assert.Equal(2, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.Equal("String3", context.DerivedAsset.MyDictionary["Key2"]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(20), baseIds["Key2"]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(1, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(21), derivedIds["Key2"]); Assert.Equal(IdentifierGenerator.Get(20), derivedIds.DeletedItems.Single()); }
public void GenerateId_WithAssessmentSection_GeneratesId() { // Setup const string assessmentSectionId = "AssessmentSectionId"; ExportableAssessmentSection assessmentSection = CreateAssessmentSection(assessmentSectionId); // Call string generatedId = IdentifierGenerator.GeneratedId(assessmentSection); // Assert Assert.AreEqual($"Wks.{assessmentSection.Id}", generatedId); }
public void GetIdentifier2_ForExistingItem() { var identifierGenerator = new IdentifierGenerator <string>(); var expectedOutput = identifierGenerator.GetIdentifier("value-1"); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator <string>(identifierGenerator, "does not matter"); var output = readonlyIdentifierGenerator.GetIdentifier("value-1", "does not matter EITHER"); Assert.That(output, Is.EqualTo(expectedOutput)); }
public void TestUniqueObjects() { IdentifierGenerator idGen = IdentifierGenerator.CStyle.Clone(); object o1 = new object(), o2 = new object(), o3 = new object(); CheckUniqueIdentifier(idGen, o1, "my_id", "my_id"); CheckUniqueIdentifier(idGen, o2, "my_id", "my_id_1"); CheckUniqueIdentifier(idGen, o3, "my_id", "my_id_2"); CheckUniqueIdentifier(idGen, o1, "xxx", "my_id"); CheckUniqueIdentifier(idGen, o2, "xxx", "my_id_1"); CheckUniqueIdentifier(idGen, o3, "xxx", "my_id_2"); }
public void SetDefaultEmployer(Dictionary <string, decimal> monthlyBalance) { var employer = new Employer { Name = "employer", AccountId = long.Parse(IdentifierGenerator.GenerateIdentifier(8, false)), LearnersType = LearnerType.ProgrammeOnlyDas, MonthlyAccountBalance = monthlyBalance }; Employers = new[] { employer }; }
public void GetIdentifier_ForExistingItem() { var identifierGenerator = new IdentifierGenerator<string>(); var expectedOutput = identifierGenerator.GetIdentifier("value-1"); var readonlyIdentifierGenerator = new ReadonlyIdentifierGenerator<string>(identifierGenerator, "does not matter"); var output = readonlyIdentifierGenerator.GetIdentifier ("value-1"); Assert.That (output, Is.EqualTo (expectedOutput)); }
internal static ChatMessage Create(Message message) { var chatMessage = new ChatMessage { Id = IdentifierGenerator.Generate() , Body = message.Body?.Value , EstimatedDownloadSize = 0 , From = message.From , IsAutoReply = false , IsForwardingDisabled = false , IsIncoming = true , IsRead = false , IsReceivedDuringQuietHours = false , IsReplyDisabled = false , IsSeen = false , LocalTimestamp = DateTimeOffset.Now , MessageKind = ChatMessageKind.Standard , NetworkTimestamp = DateTimeOffset.Now , RecipientsDeliveryInfos = new List <ChatRecipientDeliveryInfo> { new ChatRecipientDeliveryInfo { Id = IdentifierGenerator.Generate() , DeliveryTime = null , IsErrorPermanent = false , ReadTime = DateTimeOffset.UtcNow , Status = ChatMessageStatus.Received , TransportAddress = message.To , TransportErrorCode = 0 , TransportErrorCodeCategory = XmppTransportErrorCodeCategory.None , TransportInterpretedErrorCode = XmppTransportInterpretedErrorCode.None } } , RemoteId = message.Id , ShouldSuppressNotification = false , Status = ChatMessageStatus.Received , Subject = message.Subject?.Value , ThreadingInfo = new ChatConversationThreadingInfo { Id = IdentifierGenerator.Generate() , ContactId = message.To , ConversationId = message.Thread?.Value , Custom = null , Kind = ChatConversationThreadingKind.ContactId } }; chatMessage.ThreadingInfo.Participants.Add(message.To); chatMessage.ThreadingInfo.Participants.Add(message.From); return(chatMessage); }
public void GetNewId_InvalidPrefix_ThrowsArgumentException(string invalidPrefix) { // Setup var generator = new IdentifierGenerator(); // Call void Call() => generator.GetNewId(invalidPrefix); // Assert const string expectedMessage = "'prefix' is null, empty or consists of whitespace."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(Call, expectedMessage); }
public void GenerateXml() { var type = typeof(MemberOverrideTestClass.Target); var mixinConfiguration = MixinConfiguration.BuildNew().ForClass <MemberOverrideTestClass.Target> ().AddMixin <MemberOverrideTestClass.Mixin1> ().BuildConfiguration(); var targetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(type, mixinConfiguration)); var involvedType = new InvolvedType(type); involvedType.TargetClassDefinition = targetClassDefinition; var memberIdentifierGenerator = new IdentifierGenerator <MemberInfo> (); var reportGenerator = new MemberReportGenerator(type, involvedType, new IdentifierGenerator <Type> (), memberIdentifierGenerator, _outputFormatter); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement( "Members", new XElement( "Member", new XAttribute("id", "0"), new XAttribute("type", MemberTypes.Constructor), new XAttribute("name", ".ctor"), new XAttribute("is-declared-by-this-class", true), _outputFormatter.CreateModifierMarkup("", "public"), _outputFormatter.CreateConstructorMarkup("Target", new ParameterInfo[0]) ), new XElement( "Member", new XAttribute("id", "1"), new XAttribute("type", MemberTypes.Method), new XAttribute("name", "OverriddenMethod"), new XAttribute("is-declared-by-this-class", true), _outputFormatter.CreateModifierMarkup("", "public virtual"), _outputFormatter.CreateMethodMarkup("OverriddenMethod", typeof(void), new ParameterInfo[0]), GenerateOverrides("Mixin-Reference", "0", "MemberOverrideTestClass+Mixin1") ), new XElement( "Member", new XAttribute("id", "3"), new XAttribute("type", MemberTypes.Method), new XAttribute("name", "TemplateMethod"), new XAttribute("is-declared-by-this-class", true), _outputFormatter.CreateModifierMarkup("OverrideMixin ", "public"), _outputFormatter.CreateMethodMarkup("TemplateMethod", typeof(void), new ParameterInfo[0]), GenerateOverriddenMember("2", "TemplateMethod", "Void TemplateMethod()") ) ); XElementComparisonHelper.Compare(output, expectedOutput); }
public void GivenTheEmployerHasALevyBalanceGreaterThanAgreedPrice(string employerName) { var employer = new Employer { Name = employerName, AccountId = long.Parse(IdentifierGenerator.GenerateIdentifier(8, false)), LearnersType = LearnerType.ProgrammeOnlyDas, MonthlyAccountBalance = new Dictionary <string, decimal> { { "All", int.MaxValue } } }; ReferenceDataContext.AddEmployer(employer); }
public void TestAbstractReferenceableListDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableListYaml); Assert.NotNull(obj.AbstractRefList); Assert.Equal(2, obj.AbstractRefList.Count); Assert.Equal(obj.AbstractRefList[0], obj.AbstractRefList[1]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefList); Assert.Equal(IdentifierGenerator.Get(1), ids[0]); Assert.Equal(IdentifierGenerator.Get(2), ids[1]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefList[0].Id); Assert.Equal("Test", obj.AbstractRefList[0].Value); }
public void TestAbstractReferenceableDictionaryDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableDictionaryYaml); Assert.NotNull(obj.AbstractRefDictionary); Assert.Equal(2, obj.AbstractRefDictionary.Count); Assert.Equal(obj.AbstractRefDictionary["Item1"], obj.AbstractRefDictionary["Item2"]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefDictionary); Assert.Equal(IdentifierGenerator.Get(1), ids["Item1"]); Assert.Equal(IdentifierGenerator.Get(2), ids["Item2"]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefDictionary["Item1"].Id); Assert.Equal("Test", obj.AbstractRefDictionary["Item1"].Value); }
public void GenerateXml_ForGenericTypeDefinition() { var targetType = new InvolvedType(typeof(GenericTarget <,>)); var mixinConfiguration = MixinConfiguration.BuildNew() .ForClass(typeof(GenericTarget <,>)).AddMixin <ClassWithBookAttribute> ().AddMixin <Mixin3> () .BuildConfiguration(); targetType.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First()); var interfaceIdentifierGenerator = new IdentifierGenerator <Type> (); var attributeIdentifierGenerator = new IdentifierGenerator <Type> (); var assemblyIdentifierGenerator = new IdentifierGenerator <Assembly> (); var reportGenerator = new MixinReferenceReportGenerator( targetType, assemblyIdentifierGenerator, // generic target class new IdentifierGenerator <Type> (), interfaceIdentifierGenerator, attributeIdentifierGenerator, _remotionReflector, _outputFormatter); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement( "Mixins", new XElement( "Mixin", new XAttribute("ref", "0"), new XAttribute("index", "n/a"), new XAttribute("relation", "Extends"), new XAttribute("instance-name", "ClassWithBookAttribute"), new XAttribute("introduced-member-visibility", "private"), // has no dependencies new XElement("AdditionalDependencies") ), new XElement( "Mixin", new XAttribute("ref", "1"), new XAttribute("index", "n/a"), new XAttribute("relation", "Extends"), new XAttribute("instance-name", "Mixin3"), new XAttribute("introduced-member-visibility", "private"), // has no dependencies new XElement("AdditionalDependencies") ) ); Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString())); }
public void GenerateXml_WithMixins() { var targetType = new InvolvedType(typeof(TargetClass1)); var mixinConfiguration = MixinConfiguration.BuildNew().ForClass <TargetClass1> ().AddMixin <Mixin1> ().BuildConfiguration(); targetType.ClassContext = new ReflectedObject(mixinConfiguration.ClassContexts.First()); targetType.TargetClassDefinition = new ReflectedObject(TargetClassDefinitionUtility.GetConfiguration(targetType.Type, mixinConfiguration)); var interfaceIdentifierGenerator = new IdentifierGenerator <Type> (); var attributeIdentifierGenerator = new IdentifierGenerator <Type> (); var assemblyIdentifierGenerator = new IdentifierGenerator <Assembly> (); var reportGenerator = new MixinReferenceReportGenerator( targetType, assemblyIdentifierGenerator, new IdentifierGenerator <Type> (), interfaceIdentifierGenerator, attributeIdentifierGenerator, _remotionReflector, _outputFormatter ); var output = reportGenerator.GenerateXml(); var targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration(targetType.Type, mixinConfiguration); var mixinDefinition = targetClassDefinition.GetMixinByConfiguredType(typeof(Mixin1)); var expectedOutput = new XElement( "Mixins", new XElement( "Mixin", new XAttribute("ref", "0"), new XAttribute("index", "0"), new XAttribute("relation", "Extends"), new XAttribute("instance-name", "Mixin1"), new XAttribute("introduced-member-visibility", "private"), // has no dependencies new XElement("AdditionalDependencies"), new InterfaceIntroductionReportGenerator(new ReflectedObject(mixinDefinition.InterfaceIntroductions), interfaceIdentifierGenerator). GenerateXml(), new AttributeIntroductionReportGenerator( new ReflectedObject(mixinDefinition.AttributeIntroductions), attributeIdentifierGenerator, Helpers.RemotionReflectorFactory.GetRemotionReflection()). GenerateXml(), new MemberOverrideReportGenerator(new ReflectedObject(mixinDefinition.GetAllOverrides())).GenerateXml(), new TargetCallDependenciesReportGenerator(new ReflectedObject(mixinDefinition), assemblyIdentifierGenerator, _remotionReflector, _outputFormatter).GenerateXml() )); Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString())); }
public void GenerateXml_ForGenericTypeDefinition() { var targetType = new InvolvedType (typeof (GenericTarget<,>)); var mixinConfiguration = MixinConfiguration.BuildNew () .ForClass (typeof (GenericTarget<,>)).AddMixin<ClassWithBookAttribute> ().AddMixin<Mixin3> () .BuildConfiguration (); targetType.ClassContext = new ReflectedObject (mixinConfiguration.ClassContexts.First ()); var interfaceIdentifierGenerator = new IdentifierGenerator<Type> (); var attributeIdentifierGenerator = new IdentifierGenerator<Type> (); var assemblyIdentifierGenerator = new IdentifierGenerator<Assembly> (); var reportGenerator = new MixinReferenceReportGenerator ( targetType, assemblyIdentifierGenerator, // generic target class new IdentifierGenerator<Type> (), interfaceIdentifierGenerator, attributeIdentifierGenerator, _remotionReflector, _outputFormatter); var output = reportGenerator.GenerateXml (); var expectedOutput = new XElement ( "Mixins", new XElement ( "Mixin", new XAttribute ("ref", "0"), new XAttribute ("index", "n/a"), new XAttribute ("relation", "Extends"), new XAttribute ("instance-name", "ClassWithBookAttribute"), new XAttribute ("introduced-member-visibility", "private"), // has no dependencies new XElement ("AdditionalDependencies") ), new XElement ( "Mixin", new XAttribute ("ref", "1"), new XAttribute ("index", "n/a"), new XAttribute ("relation", "Extends"), new XAttribute ("instance-name", "Mixin3"), new XAttribute ("introduced-member-visibility", "private"), // has no dependencies new XElement ("AdditionalDependencies") ) ); Assert.That (output.ToString (), Is.EqualTo (expectedOutput.ToString ())); }
protected void AddLearnerCommitmentsForPeriod(DateTime date, long ukprn, Learner learner, string provider) { var learnerCommitments = StepDefinitionsContext.ReferenceDataContext.Commitments.Where(c => c.Learner == learner.Name && c.Provider == provider); foreach (var commitment in learnerCommitments) { if (commitment.StartDate > date) { continue; } if (commitment.EffectiveFrom.HasValue && commitment.EffectiveFrom.Value > date) { continue; } var employer = StepDefinitionsContext.ReferenceDataContext.Employers?.SingleOrDefault(e => e.Name == commitment.Employer); var accountId = employer?.AccountId ?? long.Parse(IdentifierGenerator.GenerateIdentifier(8, false)); var commitmentStartDate = commitment.StartDate ?? learner.LearningDelivery.StartDate; var commitmentEffectiveFromDate = commitment.EffectiveFrom ?? commitmentStartDate; var commitmentEndDate = commitment.EndDate ?? learner.LearningDelivery.PlannedEndDate; var priceEpisode = learner.LearningDelivery.PriceEpisodes.Where(pe => pe.StartDate >= commitmentStartDate && pe.StartDate <= commitmentEndDate).OrderBy(pe => pe.StartDate).FirstOrDefault(); CommitmentDataHelper.CreateCommitment( new CommitmentEntity { CommitmentId = commitment.Id, Ukprn = ukprn, Uln = learner.Uln, AccountId = accountId.ToString(), StartDate = commitmentStartDate, EndDate = commitment.EndDate ?? learner.LearningDelivery.PlannedEndDate, AgreedCost = commitment.AgreedPrice ?? priceEpisode.TotalPrice, StandardCode = commitment.StandardCode, FrameworkCode = commitment.FrameworkCode, ProgrammeType = commitment.ProgrammeType, PathwayCode = commitment.PathwayCode, Priority = commitment.Priority, VersionId = commitment.VersionId, PaymentStatus = (int)commitment.Status, PaymentStatusDescription = commitment.Status.ToString(), EffectiveFrom = commitmentEffectiveFromDate, EffectiveTo = commitment.EffectiveTo }, EnvironmentVariables); } }
private void AddDefaultResource() { var defaultResource = new XmppAddress(this.address.UserName , this.Address.DomainName , IdentifierGenerator.Generate()); var defaultPresence = new Presence { Show = ShowType.Offline , ShowSpecified = true , Priority = -127 , PrioritySpecified = true }; this.resources.Add(new ContactResource(defaultResource, defaultPresence, true)); }
private void SetDefaultCommitment() { var commitment = new Commitment { Employer = "employer", Id = long.Parse(IdentifierGenerator.GenerateIdentifier(6, false)), VersionId = 1, Learner = string.Empty, Priority = 1, Provider = "provider", StandardCode = IlrBuilder.Defaults.StandardCode, Status = CommitmentPaymentStatus.Active }; Commitments = new[] { commitment }; }
public void GetReadonlyIdentifierGenerator() { var testStrings = new[] { "test-value-1", "test-value-2" }; var identifierGenerator = new IdentifierGenerator<string>(); identifierGenerator.GetIdentifier (testStrings[0]); identifierGenerator.GetIdentifier (testStrings[1]); var expectedOutput = identifierGenerator.GetReadonlyIdentiferGenerator ("default-value"); var output = new IdentifierPopulator<string>(testStrings).GetReadonlyIdentifierGenerator("default-value"); Assert.That (output.GetIdentifier (testStrings[0]), Is.EqualTo (expectedOutput.GetIdentifier (testStrings[0]))); Assert.That (output.GetIdentifier (testStrings[1]), Is.EqualTo (expectedOutput.GetIdentifier (testStrings[1]))); Assert.That (output.GetIdentifier ("not-present!"), Is.EqualTo (expectedOutput.GetIdentifier ("not-present!"))); }
public void GetNewId_PrefixAlreadyUsed_ReturnsExpectedValue() { // Setup const string prefix = "prefix"; var generator = new IdentifierGenerator(); string currentId = generator.GetNewId(prefix); // Precondition Assert.AreEqual($"{prefix}.0", currentId); // Call string generatedId = generator.GetNewId(prefix); // Assert Assert.AreEqual($"{prefix}.1", generatedId); }
public void GenerateXml_WithMixins() { var targetType = new InvolvedType (typeof (TargetClass1)); var mixinConfiguration = MixinConfiguration.BuildNew ().ForClass<TargetClass1> ().AddMixin<Mixin1> ().BuildConfiguration (); targetType.ClassContext = new ReflectedObject (mixinConfiguration.ClassContexts.First ()); targetType.TargetClassDefinition = new ReflectedObject (TargetClassDefinitionUtility.GetConfiguration (targetType.Type, mixinConfiguration)); var interfaceIdentifierGenerator = new IdentifierGenerator<Type> (); var attributeIdentifierGenerator = new IdentifierGenerator<Type> (); var assemblyIdentifierGenerator = new IdentifierGenerator<Assembly> (); var reportGenerator = new MixinReferenceReportGenerator ( targetType, assemblyIdentifierGenerator, new IdentifierGenerator<Type> (), interfaceIdentifierGenerator, attributeIdentifierGenerator, _remotionReflector, _outputFormatter ); var output = reportGenerator.GenerateXml (); var targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration (targetType.Type, mixinConfiguration); var mixinDefinition = targetClassDefinition.GetMixinByConfiguredType (typeof (Mixin1)); var expectedOutput = new XElement ( "Mixins", new XElement ( "Mixin", new XAttribute ("ref", "0"), new XAttribute ("index", "0"), new XAttribute ("relation", "Extends"), new XAttribute ("instance-name", "Mixin1"), new XAttribute ("introduced-member-visibility", "private"), // has no dependencies new XElement ("AdditionalDependencies"), new InterfaceIntroductionReportGenerator (new ReflectedObject (mixinDefinition.InterfaceIntroductions), interfaceIdentifierGenerator). GenerateXml (), new AttributeIntroductionReportGenerator ( new ReflectedObject (mixinDefinition.AttributeIntroductions), attributeIdentifierGenerator, Helpers.RemotionReflectorFactory.GetRemotionReflection ()). GenerateXml (), new MemberOverrideReportGenerator (new ReflectedObject (mixinDefinition.GetAllOverrides ())).GenerateXml (), new TargetCallDependenciesReportGenerator (new ReflectedObject (mixinDefinition), assemblyIdentifierGenerator, _remotionReflector, _outputFormatter).GenerateXml () )); Assert.That (output.ToString (), Is.EqualTo (expectedOutput.ToString ())); }
/// <summary> /// Mutate the components. /// </summary> private void MutateComponents() { IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component"); if (TemplateType.Module == this.templateType) { identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; } foreach (Wix.Component component in this.components) { if (null == component.Id) { string firstFileId = string.Empty; // attempt to create a possible identifier from the first file identifier in the component foreach (Wix.File file in component[typeof(Wix.File)]) { firstFileId = file.Id; break; } if (string.IsNullOrEmpty(firstFileId)) { firstFileId = GetGuid(); } component.Id = identifierGenerator.GetIdentifier(firstFileId); } if (null == component.Guid) { if (this.AutogenerateGuids) { component.Guid = "*"; } else { component.Guid = this.GetGuid(); } } if (this.createFragments && component.ParentElement is Wix.Directory) { Wix.Directory directory = (Wix.Directory)component.ParentElement; // parent directory must have an identifier to create a reference to it if (null == directory.Id) { break; } if (this.rootElement is Wix.Module) { // add a ComponentRef for the Component Wix.ComponentRef componentRef = new Wix.ComponentRef(); componentRef.Id = component.Id; this.rootElement.AddChild(componentRef); } // create a new Fragment Wix.Fragment fragment = new Wix.Fragment(); this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment); // create a new DirectoryRef Wix.DirectoryRef directoryRef = new Wix.DirectoryRef(); directoryRef.Id = directory.Id; fragment.AddChild(directoryRef); // move the Component from the the Directory to the DirectoryRef directory.RemoveChild(component); directoryRef.AddChild(component); } } }
/// <summary> /// Mutate the directories. /// </summary> private void MutateDirectories() { if (!this.setUniqueIdentifiers) { // assign all identifiers before fragmenting (because fragmenting requires them all to be present) IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory"); if (TemplateType.Module == this.templateType) { identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; } foreach (Wix.Directory directory in this.directories) { if (null == directory.Id) { directory.Id = identifierGenerator.GetIdentifier(directory.Name); } } } if (this.createFragments) { foreach (Wix.Directory directory in this.directories) { if (directory.ParentElement is Wix.Directory) { Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement; // parent directory must have an identifier to create a reference to it if (null == parentDirectory.Id) { return; } // create a new Fragment Wix.Fragment fragment = new Wix.Fragment(); this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); // create a new DirectoryRef Wix.DirectoryRef directoryRef = new Wix.DirectoryRef(); directoryRef.Id = parentDirectory.Id; fragment.AddChild(directoryRef); // move the Directory from the parent Directory to DirectoryRef parentDirectory.RemoveChild(directory); directoryRef.AddChild(directory); } else if (directory.ParentElement is Wix.Fragment) { // When creating fragments, remove any top-level Directory elements; // the fragments should be pulled in by their DirectoryRefs instead. Wix.Fragment parent = (Wix.Fragment)directory.ParentElement; parent.RemoveChild(directory); // Remove the fragment if it is empty. if (parent.Children.GetEnumerator().Current == null && parent.ParentElement != null) { ((Wix.IParentElement)parent.ParentElement).RemoveChild(parent); } } else if (directory.ParentElement == this.rootElement) { // create a new Fragment Wix.Fragment fragment = new Wix.Fragment(); this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); // move the Directory from the root element to the Fragment this.rootElement.RemoveChild(directory); fragment.AddChild(directory); } } } }
private CompositeReportGenerator CreateCompositeReportGenerator() { var assemblyIdentifierGenerator = new IdentifierGenerator<Assembly>(); var readOnlyassemblyIdentifierGenerator = assemblyIdentifierGenerator.GetReadonlyIdentiferGenerator ("none"); var readonlyInvolvedTypeIdentiferGenerator = new IdentifierPopulator<Type> (_involvedTypes.Select (it => it.Type)).GetReadonlyIdentifierGenerator ("none"); var memberIdentifierGenerator = new IdentifierGenerator<MemberInfo> (); var interfaceIdentiferGenerator = new IdentifierGenerator<Type>(); var attributeIdentiferGenerator = new IdentifierGenerator<Type>(); var involvedReport = new InvolvedTypeReportGenerator ( _involvedTypes, assemblyIdentifierGenerator, readonlyInvolvedTypeIdentiferGenerator, memberIdentifierGenerator, interfaceIdentiferGenerator, attributeIdentiferGenerator, _remotionReflector, _outputFormatter); var interfaceReport = new InterfaceReportGenerator ( _involvedTypes, assemblyIdentifierGenerator, readonlyInvolvedTypeIdentiferGenerator, memberIdentifierGenerator, interfaceIdentiferGenerator, _remotionReflector, _outputFormatter); var attributeReport = new AttributeReportGenerator ( _involvedTypes, assemblyIdentifierGenerator, readonlyInvolvedTypeIdentiferGenerator, attributeIdentiferGenerator, _remotionReflector, _outputFormatter); var assemblyReport = new AssemblyReportGenerator (_involvedTypes, readOnlyassemblyIdentifierGenerator, readonlyInvolvedTypeIdentiferGenerator); var configurationErrorReport = new ConfigurationErrorReportGenerator (_configurationErrors); var validationErrorReport = new ValidationErrorReportGenerator (_validationErrors, _remotionReflector); return new CompositeReportGenerator ( involvedReport, interfaceReport, attributeReport, assemblyReport, configurationErrorReport, validationErrorReport); }
/// <summary> /// Mutate the files. /// </summary> private void MutateFiles() { IdentifierGenerator identifierGenerator = new IdentifierGenerator("File"); if (TemplateType.Module == this.templateType) { identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; } foreach (Wix.File file in this.files) { if (null == file.Id) { file.Id = identifierGenerator.GetIdentifier(Path.GetFileName(file.Source)); } } }
/// <summary> /// Mutate the WebDirProperties elements. /// </summary> private void MutateWebDirProperties() { if (this.setUniqueIdentifiers) { IdentifierGenerator identifierGenerator = new IdentifierGenerator("WebDirProperties"); // index all the existing identifiers and names foreach (IIs.WebDirProperties webDirProperties in this.webDirProperties) { if (null != webDirProperties.Id) { identifierGenerator.IndexExistingIdentifier(webDirProperties.Id); } } foreach (IIs.WebDirProperties webDirProperties in this.webDirProperties) { if (null == webDirProperties.Id) { webDirProperties.Id = identifierGenerator.GetIdentifier(String.Empty); } } } }
/// <summary> /// Mutate the Component elements. /// </summary> private void MutateComponents() { if (this.setUniqueIdentifiers) { IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component"); // index all the existing identifiers foreach (Wix.Component component in this.components) { if (null != component.Id) { identifierGenerator.IndexExistingIdentifier(component.Id); } } // index all the web site identifiers foreach (IIs.WebSite webSite in this.webSites) { if (webSite.ParentElement is Wix.Component) { identifierGenerator.IndexName(webSite.Id); } } // create an identifier for each component based on its child web site identifier foreach (IIs.WebSite webSite in this.webSites) { Wix.Component component = webSite.ParentElement as Wix.Component; if (null != component) { component.Id = identifierGenerator.GetIdentifier(webSite.Id); } } } }
/// <summary> /// Mutate the WebVirtualDir elements. /// </summary> private void MutateWebVirtualDirs() { IdentifierGenerator identifierGenerator = null; if (this.setUniqueIdentifiers) { identifierGenerator = new IdentifierGenerator("WebVirtualDir"); // index all the existing identifiers and names foreach (IIs.WebVirtualDir webVirtualDir in this.webVirtualDirs) { if (null != webVirtualDir.Id) { identifierGenerator.IndexExistingIdentifier(webVirtualDir.Id); } else { identifierGenerator.IndexName(webVirtualDir.Alias); } } } foreach (IIs.WebVirtualDir webVirtualDir in this.webVirtualDirs) { if (this.setUniqueIdentifiers && null == webVirtualDir.Id) { webVirtualDir.Id = identifierGenerator.GetIdentifier(webVirtualDir.Alias); } // harvest the directory for this WebVirtualDir this.HarvestUniqueDirectory(webVirtualDir.Directory, true); } }
private AttributeReportGenerator CreateReportGenerator(IdentifierGenerator<Type> attributeIdentifier, params InvolvedType[] involvedTypes) { return new AttributeReportGenerator ( involvedTypes, new IdentifierGenerator<Assembly>(), new IdentifierGenerator<Type>(), attributeIdentifier, Helpers.RemotionReflectorFactory.GetRemotionReflection (), new OutputFormatter()); }
/// <summary> /// Mutate the WebAddress elements. /// </summary> private void MutateWebAddresses() { if (this.setUniqueIdentifiers) { IdentifierGenerator identifierGenerator = new IdentifierGenerator("WebAddress"); // index all the existing identifiers and names foreach (IIs.WebAddress webAddress in this.webAddresses) { if (null != webAddress.Id) { identifierGenerator.IndexExistingIdentifier(webAddress.Id); } else { identifierGenerator.IndexName(String.Concat(webAddress.IP, "_", webAddress.Port)); } } foreach (IIs.WebAddress webAddress in this.webAddresses) { if (null == webAddress.Id) { webAddress.Id = identifierGenerator.GetIdentifier(String.Concat(webAddress.IP, "_", webAddress.Port)); } } } }
/// <summary> /// Mutate the WebFilter elements. /// </summary> private void MutateWebFilters() { IdentifierGenerator identifierGenerator = null; if (this.setUniqueIdentifiers) { identifierGenerator = new IdentifierGenerator("WebFilter"); // index all the existing identifiers and names foreach (IIs.WebFilter webFilter in this.webFilters) { if (null != webFilter.Id) { identifierGenerator.IndexExistingIdentifier(webFilter.Id); } else { identifierGenerator.IndexName(webFilter.Name); } } } foreach (IIs.WebFilter webFilter in this.webFilters) { if (this.setUniqueIdentifiers && null == webFilter.Id) { webFilter.Id = identifierGenerator.GetIdentifier(webFilter.Name); } // harvest the file for this WebFilter Wix.Directory directory = this.HarvestUniqueDirectory(Path.GetDirectoryName(webFilter.Path), false); Wix.Component component = new Wix.Component(); directory.AddChild(component); Wix.File file = this.fileHarvester.HarvestFile(webFilter.Path); component.AddChild(file); } }
/// <summary> /// Mutate the WebDir elements. /// </summary> private void MutateWebDirs() { if (this.setUniqueIdentifiers) { IdentifierGenerator identifierGenerator = new IdentifierGenerator("WebDir"); // index all the existing identifiers and names foreach (IIs.WebDir webDir in this.webDirs) { if (null != webDir.Id) { identifierGenerator.IndexExistingIdentifier(webDir.Id); } else { identifierGenerator.IndexName(webDir.Path); } } foreach (IIs.WebDir webDir in this.webDirs) { if (null == webDir.Id) { webDir.Id = identifierGenerator.GetIdentifier(webDir.Path); } } } }
public void GenerateXml_WithNestedAttribute() { // ClassWithNestedAttribute has 'ClassWithNestedAttribute.NestedAttribute' applied var involvedType = new InvolvedType (typeof (ClassWithNestedAttribute)); var attributeIdentifier = new IdentifierGenerator<Type>(); attributeIdentifier.GetIdentifier (typeof (ClassWithNestedAttribute.NestedAttribute)); var reportGenerator = CreateReportGenerator (attributeIdentifier, involvedType); var output = reportGenerator.GenerateXml(); var expectedOutput = new XElement ( "Attributes", new XElement ( "Attribute", new XAttribute ("id", "0"), new XAttribute ("assembly-ref", "0"), new XAttribute ("namespace", "MixinXRef.UnitTests.TestDomain"), new XAttribute ("name", "ClassWithNestedAttribute+NestedAttribute"), new XElement ( "AppliedTo", new XElement ( "InvolvedType-Reference", new XAttribute ("ref", "0") ) ) ) ); Assert.That (output.ToString(), Is.EqualTo (expectedOutput.ToString())); }
/// <summary> /// Mutate the WebSite elements. /// </summary> private void MutateWebSites() { if (this.setUniqueIdentifiers) { IdentifierGenerator identifierGenerator = new IdentifierGenerator("WebSite"); // index all the existing identifiers and names foreach (IIs.WebSite webSite in this.webSites) { if (null != webSite.Id) { identifierGenerator.IndexExistingIdentifier(webSite.Id); } else { identifierGenerator.IndexName(webSite.Description); } } foreach (IIs.WebSite webSite in this.webSites) { if (null == webSite.Id) { webSite.Id = identifierGenerator.GetIdentifier(webSite.Description); } } } }