Exemplo n.º 1
0
        public void SpoolWriterToSpoolWriter()
        {
            TextWriter writer1 = new SpoolWriter();
            TextWriter writer2 = new SpoolWriter();

            for (int index = 0; index != 5000; ++index)
            {
                writer1.Write(index);
            }
            writer2.Write("before");
            writer1.WriteTo(writer2);
            writer2.Write("after");
            Assert.AreEqual("before" + _FiveThousandNumbers + "after", writer2.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finalizes state change and creates memento
        /// </summary>
        /// <returns>memento holding the details of the resulting state delta</returns>
        public CacheMemento EndMemento()
        {
            var memento = new CacheMemento();

            // for capturing subject.Output directly, replay what was spooled, and save it
            // in the memento
            if (_priorOutput != null)
            {
                _spoolOutput.WriteTo(_priorOutput);
                _state.Output       = _priorOutput;
                memento.SpoolOutput = _spoolOutput;
            }

            // save any deltas on named content that have expanded
            foreach (var content in _priorContent)
            {
                var textMemento = content.Value.EndMemento();
                if (textMemento.Written.Any(part => string.IsNullOrEmpty(part) == false))
                {
                    memento.Content.Add(content.Key, textMemento);
                }
            }

            // also save any named content in it's entirety that added created after BeginMemento was called
            foreach (var content in _state.Content.Where(kv => _priorContent.ContainsKey(kv.Key) == false))
            {
                var originator = TextWriterOriginator.Create(content.Value);
                memento.Content.Add(content.Key, originator.CreateMemento());
            }

            // capture anything from the oncetable that was added after BeginMemento was called
            var newItems = _state.OnceTable.Where(once => _priorOnceTable.ContainsKey(once.Key) == false);

            memento.OnceTable = newItems.ToDictionary(once => once.Key, once => once.Value);
            return(memento);
        }
Exemplo n.º 3
0
 public void SpoolWriterToStringWriter()
 {
     TextWriter writer1 = new SpoolWriter();
     TextWriter writer2 = new StringWriter();
     for (int index = 0; index != 5000; ++index)
     {
         writer1.Write(index);
     }
     writer2.Write("before");
     writer1.WriteTo(writer2);
     writer2.Write("after");
     Assert.AreEqual("before" + _FiveThousandNumbers + "after", writer2.ToString());
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     _resourceRegistry.RegisterInlineBlock(writer => _blockWriter.WriteTo(writer));
     _sparkView.Output = _previousWriter;
 }