Exemple #1
0
        public void CompileProgram_Padding_FillsROM()
        {
            byte padding = 255;
            var  rom     = new Sharp_LR35902_Assembler.Assembler().CompileProgram(new string[0], null, padding);

            ListEqual(IEnumerableExtensions.ListOf(padding, rom.Length), rom);
        }
Exemple #2
0
        public static string StringValue(object o, string language)
        {
            var(isLiteral, repr) = TryRenderLiteral(o, language);
            if (!isLiteral)
            {
                var hasDeclaredToString = o.GetType().GetMethods().Any(x =>
                {
                    if (x.Name != "ToString")
                    {
                        return(false);
                    }
                    if (IEnumerableExtensions.Any(x.GetParameters()))
                    {
                        return(false);
                    }
                    if (x.DeclaringType == typeof(object))
                    {
                        return(false);
                    }
                    if (x.DeclaringType.InheritsFromOrImplements <EnumerableQuery>())
                    {
                        return(false);
                    }
                    return(true);
                });

                if (hasDeclaredToString)
                {
                    return(o.ToString());
                }
            }

            return(repr);
        }
Exemple #3
0
        public Terminal GetTerminal(string ip)
        {
            Terminal result;
            int      num;

            while (true)
            {
                DataTable dataTable = SqlHelper.ExecuteDataset(this.constr, CommandType.Text, "select * from Terminal where ip=@ip", new SqlParameter[]
                {
                    new SqlParameter("ip", ip)
                }).Tables[0];
                Terminal terminal = IEnumerableExtensions.ToList <Terminal>(dataTable).FirstOrDefault <Terminal>();
                result = terminal;
                num    = 9079;
                int arg_5E_0 = num;
                num = 9079;
                switch ((arg_5E_0 == num) ? 1 : 0)
                {
                case 0:
                case 2:
                    continue;
                }
                break;
            }
            num = 1;
            if (num != 0)
            {
            }
            num = 0;
            if (num != 0)
            {
            }
            num = 0;
            return(result);
        }
Exemple #4
0
        static void Postfix(OcPl __instance)
        {
            if (!Settings.isUseVRM(__instance))
            {
                return;
            }

            string playername = Settings.getPlayerName(__instance);

            if (!Settings.ReadBool(playername, "UseEquipAdjustment", false))
            {
                return;
            }

            var plEquipCtrl = __instance.EquipCtrl;
            var plCommon    = __instance.PlCommon;
            var plEquips    = GetPlEquips(plEquipCtrl);

            plEquips.RemoveWhere(plEquip => plEquip == null); // Destroyされていたら null チェックが True になる

            if (originalParentTransform.ContainsKey(plEquipCtrl) == false && plEquips.Any())
            {
                originalParentTransform.Add(plEquipCtrl, IEnumerableExtensions.First(plEquips).transform.parent);
            }

            foreach (var plEquip in plEquips)
            {
                AdjustEquipPos(plEquip, playername);
            }

            AdjustQuiverPos(__instance, __instance.PlCommon);
        }
Exemple #5
0
        public void WithoutIgnoredObjects_ListHasNoIgnorableObjects_ShouldReturnSameList()
        {
            // Arrange
            var list = new List <AnnoObject>
            {
                new AnnoObject
                {
                    Template = "Dummy"
                },
                new AnnoObject
                {
                    Template = "AnotherDummy"
                }
            };

            // Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(list);

            // Assert
            Assert.Equal(list.Count(), result.Count());
            Assert.All(result, x =>
            {
                Assert.Contains(x, list);
            });
        }
Exemple #6
0
 public void TestMaxBy__EnumerableNull()
 {
     Assert.Throws <ArgumentNullException>(delegate
     {
         IEnumerableExtensions.MaxBy <TestContainer, int>(null, x => x.value);
     });
 }
Exemple #7
0
        public void Batch_ReturnsGroupsOfN()
        {
            var numbers = Enumerable.Range(1, 100);
            var groups  = IEnumerableExtensions.Batch(numbers, 10);

            Assert.IsTrue(groups.All(g => g.Count() == 10));
        }
Exemple #8
0
 public DnsResourceDataNamingAuthorityPointer(ushort order, ushort preference, DataSegment flags, DataSegment services, DataSegment regularExpression, DnsDomainName replacement)
 {
     if (flags == null)
     {
         throw new ArgumentNullException("flags");
     }
     if (!DnsResourceDataNamingAuthorityPointer.IsLegalFlags(flags))
     {
         throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Flags ({0}) contain a non [a-zA-Z0-9] character.", new object[1]
         {
             (object)Encoding.ASCII.GetString(flags.Buffer, flags.StartOffset, flags.Length)
         }), "flags");
     }
     this.Order      = order;
     this.Preference = preference;
     this.Flags      = !Enumerable.All <byte>((IEnumerable <byte>)flags, (Func <byte, bool>)(flag =>
     {
         if ((int)flag >= 97)
         {
             return((int)flag > 122);
         }
         return(true);
     })) || !IEnumerableExtensions.IsStrictOrdered <byte>((IEnumerable <byte>)flags) ? new DataSegment(Enumerable.ToArray <byte>((IEnumerable <byte>)Enumerable.OrderBy <byte, byte>(Enumerable.Distinct <byte>(Enumerable.Select <byte, byte>((IEnumerable <byte>)flags, (Func <byte, byte>)(flag =>
     {
         if ((int)flag < 97 || (int)flag > 122)
         {
             return(flag);
         }
         return((byte)((int)flag + 65 - 97));
     }))), (Func <byte, byte>)(flag => flag)))) : flags;
     this.Services          = services;
     this.RegularExpression = regularExpression;
     this.Replacement       = replacement;
 }
Exemple #9
0
        public void CreateTreeProperly()
        {
            var first = new ClassWithRecursion();

            first.Name = "First";
            var second = new ClassWithRecursion();

            second.Name = "Second";

            first.Subclass = second;

            var sourceTree = new ObjectTreeItem(first);

            sourceTree.CreateTree();
            Trace.WriteLine(sourceTree.ToFormattedString());
            Assert.IsNull(sourceTree.Parent);
            Assert.IsNotNull(sourceTree.Childs);

            Assert.IsTrue(IEnumerableExtensions.Any(sourceTree.Childs));
            Assert.AreEqual(2, sourceTree.Childs.Count);

            Assert.AreEqual(first, sourceTree.Item);
            Assert.IsTrue(sourceTree.Childs.Any(item => item.Item == second));

            foreach (var objectTreeItem in sourceTree.Childs)
            {
                Assert.AreEqual(sourceTree, objectTreeItem.Parent);
            }
        }
Exemple #10
0
        public void WithoutIgnoredObjects_ListHasNoIgnorableObjects_ShouldReturnSameList()
        {
            // Arrange
            var list = new List <LayoutObject>
            {
                new LayoutObject(
                    new AnnoObject
                {
                    Template = "Dummy"
                }, mockedCoordinateHelper, mockedBrushCache, mockedPenCache),
                new LayoutObject(
                    new AnnoObject
                {
                    Template = "AnotherDummy"
                }, mockedCoordinateHelper, mockedBrushCache, mockedPenCache),
            };

            // Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(list);

            // Assert
            Assert.Equal(list.Count(), result.Count());
            Assert.All(result, x =>
            {
                Assert.Contains(x, list);
            });
        }
Exemple #11
0
        public void WithoutIgnoredObjects_ListHasIgnorableObjects_ShouldReturnFilteredList()
        {
            // Arrange
            var list = new List <LayoutObject>
            {
                new LayoutObject(
                    new AnnoObject
                {
                    Template = "Blocker"
                }, mockedCoordinateHelper, mockedBrushCache, mockedPenCache),
                new LayoutObject(
                    new AnnoObject
                {
                    Template = "Dummy"
                }, mockedCoordinateHelper, mockedBrushCache, mockedPenCache),
                new LayoutObject(
                    new AnnoObject
                {
                    Template = "AnotherDummy"
                }, mockedCoordinateHelper, mockedBrushCache, mockedPenCache),
            };

            // Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(list);

            // Assert
            Assert.NotEqual(list.Count(), result.Count());
            Assert.All(result, x =>
            {
                Assert.NotEqual("Blocker", x.WrappedAnnoObject.Template, StringComparer.OrdinalIgnoreCase);
            });
        }
 public HttpParser FieldValue(out IEnumerable <byte> fieldValue)
 {
     if (!this.Success)
     {
         fieldValue = (IEnumerable <byte>)null;
         return(this);
     }
     this.SkipLws();
     this.FieldContent(out fieldValue);
     if (!Enumerable.Any <byte>(fieldValue))
     {
         return(this);
     }
     while (this.Success)
     {
         this.SkipLws();
         IEnumerable <byte> fieldContent;
         this.FieldContent(out fieldContent);
         if (Enumerable.Any <byte>(fieldContent))
         {
             fieldValue = Enumerable.Concat <byte>(IEnumerableExtensions.Concat <byte>(fieldValue, (byte)32), fieldContent);
         }
         else
         {
             break;
         }
     }
     return(this);
 }
Exemple #13
0
        public void WithoutIgnoredObjects_ListHasIgnorableObjects_ShouldReturnFilteredList()
        {
            // Arrange
            var list = new List <AnnoObject>
            {
                new AnnoObject
                {
                    Template = "Blocker"
                },
                new AnnoObject
                {
                    Template = "Dummy"
                },
                new AnnoObject
                {
                    Template = "AnotherDummy"
                }
            };

            // Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(list);

            // Assert
            Assert.NotEqual(list.Count(), result.Count());
            Assert.All(result, x =>
            {
                Assert.NotEqual("Blocker", x.Template, StringComparer.OrdinalIgnoreCase);
            });
        }
Exemple #14
0
        public void WithoutIgnoredObjects_ListIsEmpty_ShouldReturnEmptyList()
        {
            // Arrange/Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(new List <LayoutObject>());

            // Assert
            Assert.Empty(result);
        }
Exemple #15
0
        public void WithoutIgnoredObjects_ListIsNull_ShouldReturnNull()
        {
            // Arrange/Act
            var result = IEnumerableExtensions.WithoutIgnoredObjects(null);

            // Assert
            Assert.Null(result);
        }
Exemple #16
0
 /// <summary>
 /// Sets the property value
 /// </summary>
 /// <param name="propertyName">Property name</param>
 /// <param name="value">Value</param>
 public void SetPropertyValue(string propertyName, dynamic value)
 {
     IEnumerableExtensions.SetValue(valueDict, propertyName, value);
     if (loadedIdentityValue && EntityManager.IsPrimaryKey(entityType, propertyName))
     {
         loadedIdentityValue = false;
     }
 }
Exemple #17
0
 public override string ToString()
 {
     if (this._utf8 == null)
     {
         this._utf8 = IEnumerableExtensions.SequenceToString <string>(Enumerable.Select <DataSegment, string>((IEnumerable <DataSegment>) this._labels, (Func <DataSegment, string>)(label => label.Decode(Encoding.UTF8))), '.') + ".";
     }
     return(this._utf8);
 }
        /// <summary>
        /// Filters the entity types that this convention applies to based on a
        /// predicate.
        /// </summary>
        /// <param name="predicate"> A function to test each entity type for a condition. </param>
        /// <returns>
        /// An <see cref="TypeConventionConfiguration{T}" /> instance so that multiple calls can be chained.
        /// </returns>
        public TypeConventionConfiguration <T> Where(Func <Type, bool> predicate)
        {
            Check.NotNull(predicate, "predicate");

            return(new TypeConventionConfiguration <T>(
                       _conventionsConfiguration,
                       IEnumerableExtensions.Append(_predicates, predicate)));
        }
Exemple #19
0
        public void Empty_IEnumerable_Returns_Zero()
        {
            var events = new List <Event>();

            var version = IEnumerableExtensions.Version(events);

            Assert.AreEqual(0, version);
        }
Exemple #20
0
        public void EmptyIfNull_ReturnsOriginalEnumerationIfNotNull()
        {
            var ints   = Enumerable.Range(1, 100);
            var result = IEnumerableExtensions.EmptyIfNull(ints);

            Assert.IsNotNull(result);
            Assert.AreEqual(result, ints);
        }
Exemple #21
0
 private static IList <T> EndOptions(IList <T> options, T end)
 {
     if (options.Count == 0 || (Enumerable.Last <T>((IEnumerable <T>)options).Equivalent((Option)end) || Options <T> .SumBytesLength((IEnumerable <T>)options) % 4 == 0))
     {
         return(options);
     }
     return((IList <T>) new List <T>(IEnumerableExtensions.Concat <T>((IEnumerable <T>)options, end)));
 }
Exemple #22
0
        public void EmptyIfNull_ReturnsEmptyEnumerationIfNull()
        {
            var nullInts = (IEnumerable <int>)null;
            var result   = IEnumerableExtensions.EmptyIfNull(nullInts);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 0);
        }
Exemple #23
0
        /// <summary>
        /// Deletes the items from the database.
        /// </summary>
        /// <param name="serviceProvider">The application service provider.</param>
        /// <param name="token">The cancellation token for the task.</param>
        public async Task DeleteAsync(IServiceProvider serviceProvider, CancellationToken token)
        {
            // Check if there weren't any valid items found.
            if (Items == null)
            {
                // Throw an exception.
                throw new TaskException("No valid items could be found with the provided data.");
            }
            // Get the total number of batches.
            var count = Math.Ceiling((double)Items.Count() / ApplicationDbContext.BatchSize);

            // Go over each batch.
            for (var index = 0; index < count; index++)
            {
                // Check if the cancellation was requested.
                if (token.IsCancellationRequested)
                {
                    // Break.
                    break;
                }
                // Get the items in the current batch.
                var batchItems = Items
                                 .Skip(index * ApplicationDbContext.BatchSize)
                                 .Take(ApplicationDbContext.BatchSize);
                // Get the IDs of the items in the current batch.
                var batchIds = batchItems.Select(item => item.Id);
                // Define the list of items to get.
                var paths = new List <Path>();
                // Use a new scope.
                using (var scope = serviceProvider.CreateScope())
                {
                    // Use a new context instance.
                    using var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                    // Get the items with the provided IDs.
                    var items = context.Paths
                                .Where(item => batchIds.Contains(item.Id));
                    // Check if there were no items found.
                    if (items == null || !items.Any())
                    {
                        // Continue.
                        continue;
                    }
                    // Get the items found.
                    paths = items
                            .ToList();
                }
                // Get the IDs of the items.
                var pathIds = paths
                              .Select(item => item.Id);
                // Delete the related entities.
                await PathExtensions.DeleteRelatedEntitiesAsync <PathNode>(pathIds, serviceProvider, token);

                await PathExtensions.DeleteRelatedEntitiesAsync <PathEdge>(pathIds, serviceProvider, token);

                // Delete the items.
                await IEnumerableExtensions.DeleteAsync(paths, serviceProvider, token);
            }
        }
Exemple #24
0
 public void IsNullOrEmpty_Given_Predicate_When_Null_Returns_True()
 {
     IEnumerableExtensions                        // Arrange
     .IsNullOrEmpty <string>(                     // Act
         source: null,
         predicate: e => true
         )
     .ShouldBeTrue();                             // Assert
 }
        public void DistinctBy_throws_ArgumentNullException()
        {
            IEnumerable <object> enumeration = new[] { "a", "b", "c" };

            object action(object value) => value;

            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.DistinctBy((IEnumerable <object>)null, action).Iterate());
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.DistinctBy(enumeration, (Func <object, object>)null).Iterate());
        }
        public void SequenceEqual_equalitycomparer_throws_ArgumentNullException()
        {
            IEnumerable enumeration = new[] { "a", "b", "c" };
            var         comparer    = new StringComparer();

            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual(null, enumeration, comparer));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual(enumeration, null, comparer));
            IEnumerableExtensions.SequenceEqual(enumeration, enumeration, (IEqualityComparer)null);
        }
        public void SequenceEqual_generic_action_throws_ArgumentNullException()
        {
            IEnumerable <string> enumeration = new[] { "a", "b", "c" };

            bool comparer(string f, string s) => f == s;

            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual <string, string>((IEnumerable <string>)null, enumeration, comparer));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual <string, string>(enumeration, (IEnumerable <string>)null, comparer));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual <string, string>(enumeration, enumeration, (Func <string, string, bool>)null));
        }
        public void SequenceEqual_action_throws_ArgumentNullException()
        {
            IEnumerable enumeration = new[] { "a", "b", "c" };

            bool comparer(object f, object s) => (string)f == (string)s;

            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual(null, enumeration, comparer));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual(enumeration, null, comparer));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.SequenceEqual(enumeration, enumeration, (Func <object, object, bool>)null));
        }
        public void ConvertToReadonly()
        {
            IEnumerable <Color> myList = new List <Color>()
            {
                Color.Blue, Color.White
            };
            IReadOnlyCollection <Color> myReadOnly = IEnumerableExtensions.ToReadOnlyCollection(myList);

            Assert.AreEqual(((List <Color>)myList).Count, myReadOnly.Count);
        }
        /// <summary>
        /// Filters the entity types that this convention applies to based on a
        /// predicate.
        /// </summary>
        /// <param name="predicate"> A function to test each entity type for a condition. </param>
        /// <returns>
        /// An <see cref="TypeConventionConfiguration" /> instance so that multiple calls can be chained.
        /// </returns>
        public TypeConventionConfiguration Where(Func <Type, bool> predicate)
        {
            Check.NotNull(predicate, "predicate");

#if NETSTANDARD
            return(new TypeConventionConfiguration(_conventionsConfiguration, IEnumerableExtensions.Append(_predicates, predicate)));
#else
            return(new TypeConventionConfiguration(_conventionsConfiguration, _predicates.Append(predicate)));
#endif
        }