Beispiel #1
0
        //[InlineData(typeof(IDisposable))]
        //[Trait("LongRunning", "true")]
        //[MemberData(nameof(GetTargetTypes))]
        //[Theory]
        public void GenerateCode(params Type[] types)
        {
            var code = @"
using System;

namespace Avatars.UnitTests
{
    public class Test
    {
        public void Do()
        {
            var avatar = Avatar.Of<$$>();
            Console.WriteLine(avatar.ToString());
        }
    }
}".Replace("$$", string.Join(", ", types.Select(t =>
                                                t.GetFormattedName(TypeNameFormatOptions.Namespaces))));

            var(diagnostics, compilation) = GetGeneratedOutput(code);

            Assert.Empty(diagnostics);

            var assembly = Emit(compilation);

            var name   = AvatarNaming.GetFullName(types.First(), types.Skip(1).ToArray());
            var type   = assembly.GetType(name, true);
            var avatar = Activator.CreateInstance(type !);

            foreach (var t in types)
            {
                Assert.IsAssignableFrom(t, avatar);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Gets the runtime mock full name from its base type and implemented interfaces.
 /// </summary>
 public static string GetFullName(string rootNamespace, string suffix, Type baseType, params Type[] additionalInterfaces)
 => AvatarNaming.GetFullName(rootNamespace, suffix, baseType, additionalInterfaces);
Beispiel #3
0
        public void NamespaceForGlobalType()
        {
            var name = AvatarNaming.GetFullName(typeof(IGlobal));

            Assert.Equal($"{AvatarNaming.DefaultRootNamespace}.{nameof(IGlobal)}{AvatarNaming.DefaultSuffix}", name);
        }
Beispiel #4
0
        public void FullNameWithInterfaces()
        {
            var name = AvatarNaming.GetFullName(typeof(ICalculator), typeof(IDisposable), typeof(IServiceProvider));

            Assert.Equal($"{AvatarNaming.DefaultRootNamespace}.{typeof(ICalculator).Namespace}.ICalculatorIDisposableIServiceProvider{AvatarNaming.DefaultSuffix}", name);
        }
Beispiel #5
0
        public void FullNameWithNamespaceAndInterfaces()
        {
            var name = AvatarNaming.GetFullName("Test", typeof(ICalculator), typeof(IDisposable), typeof(IServiceProvider));

            Assert.Equal($"Test.{typeof(ICalculator).Namespace}.ICalculatorIDisposableIServiceProvider" + AvatarNaming.DefaultSuffix, name);
        }
Beispiel #6
0
        public void FullName()
        {
            var name = AvatarNaming.GetFullName(typeof(ICalculator));

            Assert.Equal($"{AvatarNaming.DefaultRootNamespace}.{typeof(ICalculator).Namespace}.{nameof(ICalculator)}{AvatarNaming.DefaultSuffix}", name);
        }