GitHub PullRequestReviewCommentEvent at 2014-02-13 18:35:35
Repository: Albedo
Actor: jwChung
Payload: {"comment":{"url":"https://api.github.com/repos/ploeh/Albedo/pulls/comments/9720819","id":9720819,"diff_hunk":"@@ -134,6 +133,604 @@ public void VisitEventInfoElementReturnsCorrectResult()\n             Assert.Same(expected, actual);\r\n         }\r\n \r\n+        [Fact]\r\n+        public void VisitNullAssemblyElementThrows()\r\n+        {\r\n+            var sut = new ReflectionVisitor();\r\n+\r\n+            var e = Assert.Throws<ArgumentNullException>(() => sut.Visit((AssemblyElement)null));\r\n+            Assert.Equal(\"assemblyElement\", e.ParamName);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitAssemblyRelaiesTypeElements()\r\n+        {\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var expected = new ReflectionVisitor();\r\n+            Assembly assembly = Assembly.GetExecutingAssembly();\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.Is<TypeElement[]>(\r\n+                    p => p.SequenceEqual(assembly.GetTypes().Select(t => t.ToElement())))))\r\n+                .Returns(expected);\r\n+\r\n+            var actual = sut.Visit(assembly.ToElement());\r\n+\r\n+            Assert.Equal(expected, actual);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitNullTypeElementsThrows()\r\n+        {\r\n+            var sut = new ReflectionVisitor();\r\n+\r\n+            var e = Assert.Throws<ArgumentNullException>(() => sut.Visit((TypeElement[])null));\r\n+            Assert.Equal(\"typeElements\", e.ParamName);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitEmptyTypeElementsReturnSUTItself()\r\n+        {\r\n+            var sut = new ReflectionVisitor();\r\n+\r\n+            var actual = sut.Visit(new TypeElement[0]);\r\n+\r\n+            Assert.Equal(sut, actual);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitTypeElementsRelaiesEachTypeElement()\r\n+        {\r\n+            // Fixture setup\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var visitor1 = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var visitor2 = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var expected = new ReflectionVisitor();\r\n+\r\n+            var typeElement1 = typeof(object).ToElement();\r\n+            var typeElement2 = typeof(int).ToElement();\r\n+            var typeElement3 = typeof(string).ToElement();\r\n+\r\n+            Mock.Get(sut).Setup(x => x.Visit(typeElement1)).Returns(visitor1).Verifiable();\r\n+            Mock.Get(visitor1).Setup(x => x.Visit(typeElement2)).Returns(visitor2).Verifiable();\r\n+            Mock.Get(visitor2).Setup(x => x.Visit(typeElement3)).Returns(expected).Verifiable();\r\n+\r\n+            // Exercise system\r\n+            var actual = sut.Visit(new[] { typeElement1, typeElement2, typeElement3});\r\n+\r\n+            // Verify outcome\r\n+            Assert.Equal(expected, actual);\r\n+            Mock.Get(sut).Verify();\r\n+            Mock.Get(visitor1).Verify();\r\n+            Mock.Get(visitor2).Verify();\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitTypeElementRelaiesFieldInfoElements()\r\n+        {\r\n+            // Fixture setup\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var expected = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var typeElement = typeof(TypeWithField).ToElement();\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.Is<FieldInfoElement[]>(\r\n+                    p => p.SequenceEqual(typeElement.Type.GetFields().Select(f => f.ToElement())))))\r\n+                .Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<ConstructorInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<PropertyInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<MethodInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<EventInfoElement[]>())).Returns(expected);\r\n+\r\n+            // Exercise system\r\n+            var actual = sut.Visit(typeElement);\r\n+\r\n+            // Verify outcome\r\n+            Assert.Equal(expected, actual);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitTypeElementRelaiesConstructorInfoElements()\r\n+        {\r\n+            // Fixture setup\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var expected = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var typeElement = typeof(TypeWithCtor).ToElement();\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<FieldInfoElement[]>())).Returns(sut);\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.Is<ConstructorInfoElement[]>(\r\n+                    p => p.SequenceEqual(typeElement.Type.GetConstructors().Select(c => c.ToElement())))))\r\n+                .Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<PropertyInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<MethodInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<EventInfoElement[]>())).Returns(expected);\r\n+\r\n+            // Exercise system\r\n+            var actual = sut.Visit(typeElement);\r\n+\r\n+            // Verify outcome\r\n+            Assert.Equal(expected, actual);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitTypeElementRelaiesPropertyInfoElements()\r\n+        {\r\n+            // Fixture setup\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var expected = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var typeElement = typeof(TypeWithProperty).ToElement();\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<FieldInfoElement[]>())).Returns(sut);\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<ConstructorInfoElement[]>())).Returns(sut);\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.Is<PropertyInfoElement[]>(\r\n+                    p => p.SequenceEqual(typeElement.Type.GetProperties().Select(pi => pi.ToElement())))))\r\n+                .Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<MethodInfoElement[]>())).Returns(expected);\r\n+            Mock.Get(expected).Setup(x => x.Visit(It.IsAny<EventInfoElement[]>())).Returns(expected);\r\n+\r\n+            // Exercise system\r\n+            var actual = sut.Visit(typeElement);\r\n+\r\n+            // Verify outcome\r\n+            Assert.Equal(expected, actual);\r\n+        }\r\n+\r\n+        [Fact]\r\n+        public void VisitTypeElementRelaiesMethodInfoElements()\r\n+        {\r\n+            // Fixture setup\r\n+            var sut = new Mock<ReflectionVisitor<T>> { CallBase = true }.Object;\r\n+            var expected = new Mock<ReflectionVisitor<T>>().Object;\r\n+            var typeElement = typeof(object).ToElement();\r\n+            var methodInfos = typeElement.Type.GetMethods()\r\n+                .Except(typeElement.Type.GetProperties().SelectMany(p => p.GetAccessors()));\r\n+\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<FieldInfoElement[]>())).Returns(sut);\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<ConstructorInfoElement[]>())).Returns(sut);\r\n+            Mock.Get(sut).Setup(x => x.Visit(It.IsAny<PropertyInfoElement[]>())).Returns(sut);\r","path":"Src/Albedo.UnitTests/ReflectionVisitorTests.cs","position":null,"original_position":162,"commit_id":"42f1c53d916200a101e7998a0fa78b5317b6fc57","original_commit_id":"8b532d55b8d167679ddbcab4ed1809bb8b5d17e8","user":{"login":"jwChung","id":3784448,"avatar_url":"https://gravatar.com/avatar/6b54b7199b7b7cba792be948a863a196?d=https%3A%2F%2Fidenticons.github.com%2Fed4b3335b4dbcf24bf720a482108d242.png&r=x","gravatar_id":"6b54b7199b7b7cba792be948a863a196","url":"https://api.github.com/users/jwChung","html_url":"https://github.com/jwChung","followers_url":"https://api.github.com/users/jwChung/followers","following_url":"https://api.github.com/users/jwChung/following{/other_user}","gists_url":"https://api.github.com/users/jwChung/gists{/gist_id}","starred_url":"https://api.github.com/users/jwChung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwChung/subscriptions","organizations_url":"https://api.github.com/users/jwChung/orgs","repos_url":"https://api.github.com/users/jwChung/repos","events_url":"https://api.github.com/users/jwChung/events{/privacy}","received_events_url":"https://api.github.com/users/jwChung/received_events","type":"User","site_admin":false},"body":"To resolve this, I introduced middle instances of `ReflectionVisitor<T>` type. (c9c47a9)","created_at":"2014-02-13T18:35:35Z","updated_at":"2014-02-13T18:35:35Z","html_url":"https://github.com/ploeh/Albedo/pull/61#discussion_r9720819","pull_request_url":"https://api.github.com/repos/ploeh/Albedo/pulls/61","_links":{"self":{"href":"https://api.github.com/repos/ploeh/Albedo/pulls/comments/9720819"},"html":{"href":"https://github.com/ploeh/Albedo/pull/61#discussion_r9720819"},"pull_request":{"href":"https://api.github.com/repos/ploeh/Albedo/pulls/61"}}}}