Example #1
0
        public void AssemblyElementWithNoAliasInfersSimpleName()
        {
            var resxWithEmbeddedBitmap = MSBuildResXReader.GetResourcesFromString(
                ResXHelper.SurroundWithBoilerplate(
                    @"  <assembly name=""System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"" />
    <data name=""Color1"" type=""System.Drawing.Color, System.Drawing""><value>Blue</value></data>
"));

            resxWithEmbeddedBitmap.ShouldHaveSingleItem();
            resxWithEmbeddedBitmap[0].ShouldBeOfType(typeof(TypeConverterStringResource));

            var resource = (TypeConverterStringResource)resxWithEmbeddedBitmap[0];

            resource.Name.ShouldBe("Color1");
            resource.TypeAssemblyQualifiedName.ShouldBe("System.Drawing.Color, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            resource.StringRepresentation.ShouldBe("Blue");
        }
        public void ResXFileRefToBitmap()
        {
            string bitmapPath = Build.UnitTests.GenerateResource_Tests.Utilities.CreateWorldsSmallestBitmap();

            var resxWithLinkedBitmap = MSBuildResXReader.GetResourcesFromString(
                ResXHelper.SurroundWithBoilerplate(
                    $@"  <data name='Image1' type='System.Resources.ResXFileRef, System.Windows.Forms'>
    <value>{bitmapPath};System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>
"));

            resxWithLinkedBitmap.ShouldHaveSingleItem();
            resxWithLinkedBitmap[0].ShouldBeOfType(typeof(FileStreamResource));

            var resource = (FileStreamResource)resxWithLinkedBitmap[0];

            resource.Name.ShouldBe("Image1");
            resource.TypeAssemblyQualifiedName.ShouldBe("System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
        }
        public void LoadsMultipleStringsPreservingOrder()
        {
            var resxWithTwoStrings = MSBuildResXReader.GetResourcesFromString(
                ResXHelper.SurroundWithBoilerplate(
                    @"<data name=""StringResource"" xml:space=""preserve"">
    <value>StringValue</value>
    <comment>Comment</comment>
  </data>
  <data name=""2StringResource2"" xml:space=""preserve"">
    <value>2StringValue2</value>
  </data>"));

            resxWithTwoStrings.Count.ShouldBe(2);

            resxWithTwoStrings[0].Name.ShouldBe("StringResource");
            resxWithTwoStrings[0].ShouldBeOfType <StringResource>()
            .Value.ShouldBe("StringValue");

            resxWithTwoStrings[1].Name.ShouldBe("2StringResource2");
            resxWithTwoStrings[1].ShouldBeOfType <StringResource>()
            .Value.ShouldBe("2StringValue2");
        }