private static void ValidateIndexer(params bool[] dynamicFlags)
        {
            if (dynamicFlags == null)
            {
                Assert.False(DynamicFlagsCustomTypeInfo.GetFlag(null, 0));
            }
            else
            {
                var builder = ArrayBuilder <bool> .GetInstance(dynamicFlags.Length);

                builder.AddRange(dynamicFlags);
                var customTypeInfo = DynamicFlagsCustomTypeInfo.ToBytes(builder);
                builder.Free();

                AssertEx.All(
                    dynamicFlags.Select(
                        (f, i) => f == DynamicFlagsCustomTypeInfo.GetFlag(customTypeInfo, i)
                        ),
                    x => x
                    );
                Assert.False(
                    DynamicFlagsCustomTypeInfo.GetFlag(customTypeInfo, dynamicFlags.Length)
                    );
            }
        }
        public void TestExternAliasInName()
        {
            var libSource =
                @"
public interface I
{
    void M();
    int P { get; set; }
    event System.Action E;
}
";

            var source =
                @"
extern alias Q;

class C : Q::I
{
    void Q::I.M() { }
    int Q::I.P { get { return 0; } set { } }
    event System.Action Q::I.E { add { } remove { } }
}
";

            var libComp = CreateCompilation(libSource);

            libComp.VerifyDiagnostics();

            var comp = CreateCompilation(
                source,
                new[]
            {
                new CSharpCompilationReference(libComp, aliases: ImmutableArray.Create("Q"))
            }
                );

            comp.VerifyDiagnostics();

            var classC        = comp.GlobalNamespace.GetMember <NamedTypeSymbol>("C");
            var classCMembers = classC.GetMembers();

            // The alias is preserved, in case a similar interface is implemented from another aliased assembly.
            AssertEx.All(
                classCMembers.Select(m => m.Name),
                name =>
                name == WellKnownMemberNames.InstanceConstructorName ||
                name.StartsWith("Q::I.", StringComparison.Ordinal)
                );
            AssertEx.All(
                classCMembers.Select(m => m.MetadataName),
                metadataName =>
                metadataName == WellKnownMemberNames.InstanceConstructorName ||
                metadataName.StartsWith("Q::I.", StringComparison.Ordinal)
                );
            AssertEx.None(classCMembers.Select(m => m.ToString()), id => id.Contains("Q"));
            AssertEx.None(
                classCMembers.Select(m => m.GetDocumentationCommentId()),
                id => id.Contains("Q")
                );
        }
Esempio n. 3
0
 /// <summary>
 /// Verify all type parameters from the method
 /// are from that method or containing types.
 /// </summary>
 internal static void VerifyTypeParameters(MethodSymbol method)
 {
     Assert.True(method.IsContainingSymbolOfAllTypeParameters(method.ReturnType));
     AssertEx.All(method.TypeParameters, typeParameter => method.IsContainingSymbolOfAllTypeParameters(typeParameter));
     AssertEx.All(method.TypeArguments, typeArgument => method.IsContainingSymbolOfAllTypeParameters(typeArgument));
     AssertEx.All(method.Parameters, parameter => method.IsContainingSymbolOfAllTypeParameters(parameter.Type));
     VerifyTypeParameters(method.ContainingType);
 }
Esempio n. 4
0
        /// <summary>
        /// Verify all type parameters from the type
        /// are from that type or containing types.
        /// </summary>
        internal static void VerifyTypeParameters(NamedTypeSymbol type)
        {
            AssertEx.All(type.TypeParameters, typeParameter => type.IsContainingSymbolOfAllTypeParameters(typeParameter));
            AssertEx.All(type.TypeArguments, typeArgument => type.IsContainingSymbolOfAllTypeParameters(typeArgument));
            var container = type.ContainingType;

            if ((object)container != null)
            {
                VerifyTypeParameters(container);
            }
        }
        private static void ValidateIndexer(params bool[] flags)
        {
            var customTypeInfo = DynamicFlagsCustomTypeInfo.Create(flags);

            if (flags == null)
            {
                Assert.False(customTypeInfo[0]);
            }
            else
            {
                AssertEx.All(flags.Select((f, i) => f == customTypeInfo[i]), x => x);
                Assert.False(customTypeInfo[flags.Length]);
            }
        }
Esempio n. 6
0
        public void TestForgetOriginalBuffers()
        {
            var entries = new[] { "1", "2", "3" };

            AddEntries(entries);

            Assert.Equal(entries, HistoryEntries);
            AssertEx.All(_history.Items, e => e.OriginalSpan.HasValue);

            _history.ForgetOriginalBuffers();

            Assert.Equal(entries, HistoryEntries);
            AssertEx.None(_history.Items, e => e.OriginalSpan.HasValue);
        }
        public void ExecuteTransformsEachFrame()
        {
            var operation = new ResizeOperation("Test.gif", _directory, Settings());

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(2, image.Frames.Count);
                AssertEx.All(image.Frames, frame => Assert.Equal(96, frame.PixelWidth));
            });
        }
        private static void ValidateBytes(DynamicFlagsCustomTypeInfo dynamicFlags, params byte[] expectedBytes)
        {
            Assert.NotNull(expectedBytes);

            var dkmClrCustomTypeInfo = dynamicFlags.GetCustomTypeInfo();

            if (dynamicFlags.Any())
            {
                Assert.NotNull(dkmClrCustomTypeInfo);
                var actualBytes = dkmClrCustomTypeInfo.Payload;
                Assert.Equal(expectedBytes, actualBytes);
            }
            else
            {
                AssertEx.All(expectedBytes, b => b == 0);
                Assert.Null(dkmClrCustomTypeInfo);
            }
        }
Esempio n. 9
0
        public void AssociatedField_DuplicateEvents()
        {
            var ilSource = @"
.class public auto ansi beforefieldinit C
       extends [mscorlib]System.Object
{
  .field private class [mscorlib]System.Action E

  .method public hidebysig specialname instance void 
          add_E(class [mscorlib]System.Action 'value') cil managed
  {
    ldnull
    throw
  }

  .method public hidebysig specialname instance void 
          remove_E(class [mscorlib]System.Action 'value') cil managed
  {
    ldnull
    throw
  }

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    ldarg.0
    call       instance void [mscorlib]System.Object::.ctor()
    ret
  }

  .event [mscorlib]System.Action E
  {
    .addon instance void C::add_E(class [mscorlib]System.Action)
    .removeon instance void C::remove_E(class [mscorlib]System.Action)
  } // end of event C::E

  .event [mscorlib]System.Action E
  {
    .addon instance void C::add_E(class [mscorlib]System.Action)
    .removeon instance void C::remove_E(class [mscorlib]System.Action)
  } // end of event C::E
} // end of class C
";
            var ilRef    = CompileIL(ilSource);
            var comp     = CreateCompilation("", new[] { ilRef }, TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All));

            comp.VerifyDiagnostics();

            var type   = comp.GlobalNamespace.GetMember <NamedTypeSymbol>("C");
            var events = type.GetMembers().OfType <PEEventSymbol>();

            Assert.Equal(2, events.Count());
            AssertEx.All(events, e => e.HasAssociatedField);

            var field = events.First().AssociatedField;

            Assert.NotNull(field);
            AssertEx.All(events, e => e.AssociatedField == field);

            Assert.Contains(field.AssociatedSymbol, events);
        }