Ejemplo n.º 1
0
        /// <summary>
        /// Transforms the changeset into a different type using the specified transform function.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TDestination">The type of the destination.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="transformer">The transformer.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// source
        /// or
        /// transformer
        /// </exception>
        public static IChangeSet <TDestination> Transform <TSource, TDestination>([NotNull] this IChangeSet <TSource> source,
                                                                                  [NotNull] Func <TSource, TDestination> transformer)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            var changes = source.Select(change =>
            {
                if (change.Type == ChangeType.Item)
                {
                    return(new Change <TDestination>(change.Reason,
                                                     transformer(change.Item.Current),
                                                     OptionExtensions.Convert(change.Item.Previous, transformer),
                                                     change.Item.CurrentIndex,
                                                     change.Item.PreviousIndex));
                }
                return(new Change <TDestination>(change.Reason, change.Range.Select(transformer), change.Range.Index));
            });

            return(new ChangeSet <TDestination>(changes));
        }
Ejemplo n.º 2
0
        public void WhatIsObjectNone1()
        {
            var objNull = OptionExtensions.SomeNotNull <SomeClass>(null);
            var none    = Option.None <SomeClass>();

            objNull.Should().Be(none);
        }
Ejemplo n.º 3
0
        public void WhatIsNone5()
        {
            var empty1 = OptionExtensions.SomeNotNull <string>(null);
            var empty2 = OptionExtensions.SomeNotNull <string>(null);

            empty1.Should().Be(empty2);
        }
Ejemplo n.º 4
0
        public void WhatIsNone2()
        {
            var stringNull = OptionExtensions.SomeNotNull <string>(null);
            var none       = Option.Some <string>("");

            stringNull.Should().NotBe(none);
        }
Ejemplo n.º 5
0
        public void ShouldThrowIfKeyIsNull()
        {
            Action setNullOptions = () => OptionExtensions.SetHeaders(new SendOptions(), null, "value");

            setNullOptions.ShouldThrow <ArgumentException>();
        }
Ejemplo n.º 6
0
        public void ShouldThrowIfOptionsAreNull()
        {
            Action setNullOptions = () => OptionExtensions.SetHeaders(null, "code", "value");

            setNullOptions.ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 7
0
 public IObservable <IChangeSet <TDestination, TKey> > Run()
 {
     return(_source.Select(changes =>
     {
         var transformed = Enumerable.Select <Change <TSource, TKey>, Change <TDestination, TKey> >(changes, change => new Change <TDestination, TKey>(change.Reason,
                                                                                                                                                       change.Key,
                                                                                                                                                       _converter(change.Current),
                                                                                                                                                       OptionExtensions.Convert(change.Previous, _converter),
                                                                                                                                                       change.CurrentIndex,
                                                                                                                                                       change.PreviousIndex));
         return new ChangeSet <TDestination, TKey>(transformed);
     }));
 }