예제 #1
0
 public HaxeEmitterContext(HaxeEmitter emitter, PhaseType type)
 {
     Emitter                = emitter;
     CurrentType            = type;
     _writerStack           = new Stack <IWriter>();
     Writer                 = new InMemoryWriter();
     CurrentExceptionName   = new Stack <string>();
     CurrentForIncrementors = new Stack <IEnumerable <ExpressionSyntax> >();
 }
        public void CorrectlyTranslatesDemoTargetAssembly()
        {
            var completeConfiguration = new InTestConfigurationLoader().GetConfiguration("sample.debug.cfg.json");
            var expectedResult        = new TestFilesAccessor()
                                        .GetSampleFile("sample.debug.cfg.expected.result.txt")
                                        .UseAsArgFor(File.ReadAllText);

            using (var container = new ContainerBuilder().With(completeConfiguration).Validated().Build())
            {
                var translationRootTargetTypes = container
                                                 .GetInstance <ITargetTypesLocator>()
                                                 .LocateRootTargets()
                                                 .ToList();

                var translationContext = container.GetInstance <ITranslationContext>();

                container
                .GetInstance <TypeTranslationChain>()
                .BuildDefault()
                .ForEach(typeTranslationContext => translationContext.AddTypeTranslationContext(typeTranslationContext, false));

                var skipTypeRule = container.GetInstance <ISkipTypeRule>();
                var typeTranslationContextFactory = container.GetInstance <ITypeTranslationContextFactory>();
                // TODO Move to class
                foreach (var sourceType in translationRootTargetTypes)
                {
                    if (skipTypeRule.AppliesTo(sourceType) == false)
                    {
                        // TODO Reuse in other places!!!
                        // TODO Separate class?
                        var typeTranslationContext = sourceType.IsGenericType ?
                                                     typeTranslationContextFactory.GenericType(sourceType) :
                                                     typeTranslationContextFactory.Regular(sourceType);
                        translationContext.AddTypeTranslationContext(typeTranslationContext, true);
                    }
                }
                ITypeTranslationContext unprocessed;
                Func <ITypeTranslationContext, bool> withUnresolvedDependencies =
                    typeContext => typeContext.AreDependenciesResolved == false;
                while ((unprocessed = translationContext.FirstOrDefault(withUnresolvedDependencies)) != null)
                {
                    unprocessed.ResolveDependencies();
                }
                // IoC ^^^^^^^^^^^^^^^^^^^^^^^

                var nonemptyGenerationResults = translationContext
                                                .TranslateTargets()
                                                .Where(translationResult => string.IsNullOrWhiteSpace(translationResult.Definition) == false);

                var writer = new InMemoryWriter();
                writer.Write(nonemptyGenerationResults);
                Assert.Equal(Canonic(expectedResult), Canonic(writer.GeneratedText));
            }
        }
예제 #3
0
        /// <summary>
        /// Produce the message dump from a MailMessage.
        /// </summary>
        /// <param name="message">The message for which you'd like content.</param>
        /// <param name="escapeUnicode">Depending on the transport, the message may not require unicode encoding (by the use of "Q" Encoding).
        /// If you would like a less irritating dump, you may set this to false, and the dump will produce the UTF-8 string with the unicode
        /// characters unescaped.</param>
        /// <returns></returns>
        public static string MessageDump(this MailMessage message, bool escapeUnicode = true)
        {
            using (var ms = new MemoryStream())
            {
                var writer = new InMemoryWriter(ms, false);
                message.Send(writer, false, !escapeUnicode);

                var encoding = !escapeUnicode ? Encoding.UTF8 : Encoding.ASCII;

                var count = (int)ms.Position;
                ms.Position = 0;
                return(encoding.GetString(ms.GetBuffer(), 0, count));
            }
        }
예제 #4
0
        public async Task CreateWorkBook_ReadZippedXMindBookFromFileSystem_Success()
        {
            //Arrange
            var book = new XMindConfiguration()
                       .WithFileWriter(basePath: _customOutputFolderName, zip: true)
                       .CreateWorkBook(workbookName: "test.xmind");

            await book.Save();

            var writer = new InMemoryWriter()
                         .SetOutput(new InMemoryWriterOutputConfig(outputName: "root")) as InMemoryWriter;
            var book2 = new XMindConfiguration()
                        .WriteTo
                        .Writer(writer)
                        .LoadWorkBookFromLocation(Path.Combine(_customOutputFolderName, "test.xmind"));
            //Act
            await book2.Save();

            //Assert
            writer.DocumentStorage.Keys.Should().NotBeEmpty().And
            .HaveCount(3).And
            .BeEquivalentTo("manifest.xml", "meta.xml", "content.xml");
        }
예제 #5
0
 public void PushWriter()
 {
     _writerStack.Push(Writer);
     Writer = new InMemoryWriter();
 }