예제 #1
0
        public void ProducerActionTest()
        {
            var initial = new TestPerson()
            {
                FirstName = "John",
                LastName  = "Doe",
                IsAdult   = true,
            };

            var producer = ITestPerson.Producer(p =>
            {
                p.FirstName = "Jane";
                p.IsAdult   = false;
            });

            var person = producer(initial);

            Assert.NotSame(initial, person);
            Assert.NotEqual(initial.FirstName, person.FirstName);
            Assert.Equal(initial.LastName, person.LastName);
            Assert.NotEqual(initial.IsAdult, person.IsAdult);
        }
예제 #2
0
        public void ProducerActionWithArgumentTest()
        {
            var initial = new[]
            {
                new TestPerson
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    IsAdult   = true,
                },
                new TestPerson
                {
                    FirstName = "Jane",
                    LastName  = "Doe",
                    IsAdult   = false,
                },
            };

            var anonimizer = ITestPerson.Producer <int>((p, i) =>
            {
                p.LastName = $"Anonimized nr. {i + 1}";
            });

            var result = initial.Select((p, i) => anonimizer(p, i));

            int index = 0;

            Assert.All(initial.Zip(result, (first, second) => new { Expected = first, Actual = second, Index = ++index }), r =>
            {
                Assert.NotSame(r.Expected, r.Actual);
                Assert.Equal(r.Expected.FirstName, r.Actual.FirstName);
                Assert.NotEqual(r.Expected.LastName, r.Actual.LastName);
                Assert.Equal(r.Expected.IsAdult, r.Actual.IsAdult);
                Assert.Equal($"Anonimized nr. {r.Index}", r.Actual.LastName);
            });
        }