Example #1
0
        public void TestAssignEntities()
        {
            foreach (var seed in Enumerable.Range(0, 1000))
            {
                var random     = new Random(seed);
                var collection = new CollectionSubject <EquatableElement> {
                    AssignItem = (src, dst) => {
                        Console.WriteLine("assign item");
                        src.Value = dst.Value;
                    }
                };

                for (int i = 0; i < random.Next(1, 10); ++i)
                {
                    var postValues = collection.ToList();
                    var nextValues =
                        Enumerable.Range(
                            0, random.Next(0, 10)
                            ).Select(
                            _ => new EquatableElement(random.Next(10), random.Next(10).ToString())
                            ).ToArray();

                    collection.Assign(nextValues);

                    var postValuesStr = "[" + string.Join(", ", postValues.Select(x => $"{x.Id}-{x.Value}")) + "]";
                    var nextValuesStr = "[" + string.Join(", ", nextValues.Select(x => $"{x.Id}-{x.Value}")) + "]";
                    var actualStr     = "[" + string.Join(", ", collection.Select(x => $"{x.Id}-{x.Value}")) + "]";

                    CollectionAssert.AreEqual(nextValues.Select(x => x.Value).ToArray(), collection.Select(x => x.Value).ToArray(), $"{postValuesStr} => {nextValuesStr} = {actualStr}");
                }
            }
        }
Example #2
0
        public TestContext()
        {
            QueryCommand = new QueryCommand(this);

            Items = new CollectionSubject <Person>()
            {
                Dispatch = Dispatcher.CurrentDispatcher.Invoke
            };

            Query();
        }
Example #3
0
        public void TestAssignValueObjects()
        {
            foreach (var seed in Enumerable.Range(0, 1000))
            {
                var random     = new Random(seed);
                var collection = new CollectionSubject <EquatableElement>();
                for (int i = 0; i < random.Next(1, 10); ++i)
                {
                    var postValues = collection.ToList();
                    var nextValues = Enumerable.Range(0, random.Next(0, 10)).Select(_ => new EquatableElement(random.Next(10), random.Next(10).ToString())).ToArray();
                    collection.Assign(nextValues);

                    var postValuesStr = "[" + string.Join(", ", postValues.Select(x => x.Id)) + "]";
                    var nextValuesStr = "[" + string.Join(", ", nextValues.Select(x => x.Id)) + "]";
                    var actualStr     = "[" + string.Join(", ", collection.Select(x => x.Id)) + "]";

                    CollectionAssert.AreEqual(nextValues, collection, Comparer <EquatableElement> .Default, $"{postValuesStr} => {nextValuesStr} = {actualStr}");
                }
            }
        }
Example #4
0
        public void TestInitialState()
        {
            var collection = new CollectionSubject <EquatableElement>();

            CollectionAssert.AreEqual(new EquatableElement[0], collection);
        }