コード例 #1
0
        public void Example_Scenario_Passing_Test()
        {
            var dataParent = new DataParent()
            {
                Id       = "123",
                Value    = "new",
                Children = new List <DataChild>()
                {
                    new DataChild()
                    {
                        Id    = "1234",
                        Value = "new"
                    }
                }
            };

            var domainParent = dataParent.MapToDomainParentCorrectly();

            var child = domainParent.Children.FirstOrDefault();

            child.Value = "updated";

            Assert.Equal("updated", child.Value);                              // True
            Assert.Equal("updated", domainParent.Children.ElementAt(0).Value); // True
        }
コード例 #2
0
        public static DomainParent ToDomainParent(this DataParent dataParent)
        {
            var children = dataParent.Children.Select(x => new DomainChild
            {
                Id    = x.Id,
                Value = x.Value
            });

            return(new DomainParent
            {
                Id = dataParent.Id,
                Value = dataParent.Value,
                Children = children
            });
        }
コード例 #3
0
        public static DomainParent MapToDomainParentCorrectly(this DataParent dataParent)
        {
            var children = dataParent.Children.Select(x => new DomainChild
            {
                Id    = x.Id,
                Value = x.Value
            });

            return(new DomainParent
            {
                Id = dataParent.Id,
                Value = dataParent.Value,
                Children = children.ToList()
            });
        }
コード例 #4
0
        public void Call_First_Or_Default_More_Than_Once_Objects_Shoule_Be_The_Same_Failing()
        {
            var dataParent = new DataParent()
            {
                Id       = "123",
                Value    = "new",
                Children = new List <DataChild>()
                {
                    new DataChild()
                    {
                        Id    = "1234",
                        Value = "new"
                    }
                }
            };

            var domainParent = dataParent.ToDomainParent();

            var child  = domainParent.Children.FirstOrDefault();
            var child2 = domainParent.Children.FirstOrDefault();

            Assert.True(child.Equals(child2));
        }