Example #1
0
        public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeAttribute()
        {
            MockAttribute testAttribute = new MockAttribute("TestAttribute");
            MockMethod    mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);

            Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
        }
Example #2
0
        public void IsTestMethodReturnsTrueWhenMethodHasFullyQualifiedNUnitTestAttribute()
        {
            MockAttribute testAttribute = new MockAttribute("MbUnit.Framework.TestAttribute");
            MockMethod    mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);

            Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
        }
Example #3
0
        public void IsTestClassReturnsTrueHasClassHasFullyQualifiedNUnitTestFixtureAttribute()
        {
            MockAttribute testFixtureAttribute = new MockAttribute("NUnit.Framework.TestFixtureAttribute");
            MockClass     mockClass            = MockClass.CreateMockClassWithAttribute(testFixtureAttribute);

            Assert.IsTrue(testFramework.IsTestClass(mockClass));
        }
Example #4
0
        public void IsTestClassReturnsTrueHasClassHasTestFixtureAttributeMissingAttributePart()
        {
            MockAttribute testAttribute = new MockAttribute("TestFixture");
            MockClass     mockClass     = MockClass.CreateMockClassWithAttribute(testAttribute);

            Assert.IsTrue(testFramework.IsTestClass(mockClass));
        }
Example #5
0
        public void IsTestClassReturnsFalseWhenClassHasTestFixtureAttributeAndIsAbstract()
        {
            MockAttribute testAttribute = new MockAttribute("TestFixture");
            MockClass     mockClass     = MockClass.CreateMockClassWithAttribute(testAttribute);

            mockClass.Modifiers = mockClass.Modifiers | ModifierEnum.Abstract;
            Assert.IsFalse(testFramework.IsTestClass(mockClass));
        }
Example #6
0
        public void IsTestMember_MethodHasFullyQualifiedNUnitTestAttribute_ReturnsTrue()
        {
            CreateTestFramework();
            MockAttribute testAttribute = new MockAttribute("NUnit.Framework.TestAttribute");
            MockMethod    mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);

            bool result = testFramework.IsTestMember(mockMethod);

            Assert.IsTrue(result);
        }
		public void Init()
		{
			firstAttribute = new MockAttribute("first");
			secondAttribute = new MockAttribute("second");
			List<MockAttribute> attributes = new List<MockAttribute>();
			attributes.Add(firstAttribute);
			attributes.Add(secondAttribute);
			
			mockClass = MockClass.CreateMockClassWithAttributes(attributes);
		}
Example #8
0
        public void IsTestMethodReturnsTrueWhenProjectIsNull()
        {
            MockAttribute      testAttribute      = new MockAttribute("Test");
            MockMethod         mockMethod         = MockMethod.CreateMockMethodWithAttribute(testAttribute);
            MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent;

            mockProjectContent.Project = null;

            Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
        }
Example #9
0
        public void IsTestMethodReturnsFalseWhenMethodHasHasParameters()
        {
            MockAttribute testAttribute = new MockAttribute("Test");
            MockMethod    mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);
            MockParameter mockParameter = new MockParameter();

            mockMethod.Parameters.Add(mockParameter);

            Assert.IsFalse(testFramework.IsTestMethod(mockMethod));
        }
Example #10
0
        public void IsTestMember_MethodHasTestAttributeWithoutAttributePart_ReturnsTrue()
        {
            CreateTestFramework();
            MockAttribute testAttribute = new MockAttribute("Test");
            MockMethod    mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);

            bool result = testFramework.IsTestMember(mockMethod);

            Assert.IsTrue(result);
        }
Example #11
0
        public void Init()
        {
            firstAttribute  = new MockAttribute("first");
            secondAttribute = new MockAttribute("second");
            List <MockAttribute> attributes = new List <MockAttribute>();

            attributes.Add(firstAttribute);
            attributes.Add(secondAttribute);

            mockClass = MockClass.CreateMockClassWithAttributes(attributes);
        }
Example #12
0
        public void Init()
        {
            MockAttribute testAttribute = new MockAttribute("Test");

            methodWithTestAttribute = MockMethod.CreateMockMethodWithAttribute(testAttribute);
            memberNodeForMethodWithTestAttribute = new MockMemberNode(methodWithTestAttribute);

            testFrameworks = new MockRegisteredTestFrameworks();
            testFrameworks.AddTestMethod(methodWithTestAttribute);

            testableCondition = new TestableCondition(testFrameworks);
        }
Example #13
0
        public void IsTestMember_MethodHasParameters_ReturnsFalse()
        {
            CreateTestFramework();
            var        testAttribute = new MockAttribute("Test");
            MockMethod mockMethod    = MockMethod.CreateMockMethodWithAttribute(testAttribute);
            var        mockParameter = new MockParameter();

            mockMethod.Parameters.Add(mockParameter);

            bool result = testFramework.IsTestMember(mockMethod);

            Assert.IsFalse(result);
        }
Example #14
0
        public void IsTestMember_ProjectIsNull_ReturnsTrue()
        {
            CreateTestFramework();
            var                testAttribute      = new MockAttribute("Test");
            MockMethod         mockMethod         = MockMethod.CreateMockMethodWithAttribute(testAttribute);
            MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent;

            mockProjectContent.Project = null;

            bool result = testFramework.IsTestMember(mockMethod);

            Assert.IsTrue(result);
        }
Example #15
0
        public void IsTestMember_FieldHasOneAttribute_ReturnsFalseAndDoesNotThrowInvalidCastException()
        {
            CreateTestFramework();
            MockClass mockClass     = MockClass.CreateMockClassWithoutAnyAttributes();
            var       field         = new DefaultField(mockClass, "MyField");
            var       testAttribute = new MockAttribute("Test");

            field.Attributes.Add(testAttribute);

            bool result = testFramework.IsTestMember(field);

            Assert.IsFalse(result);
        }
Example #16
0
        public void Init()
        {
            MockAttribute testAttribute = new MockAttribute("Test");

            classWithTestAttribute = MockClass.CreateMockClassWithAttribute(testAttribute);
            IProject project = classWithTestAttribute.MockProjectContent.ProjectAsIProject;

            classNodeForClassWithTestAttribute = new ClassNode(project, classWithTestAttribute);

            testFrameworks = new MockRegisteredTestFrameworks();
            testFrameworks.AddTestClass(classWithTestAttribute);

            testableCondition = new TestableCondition(testFrameworks);
        }
        public override void OnPreInvoke(IInterceptorContext context)
        {
            MockAttribute mockAttr = context.Method.DeclaringType.GetCustomAttribute <MockAttribute>();

            if (mockAttr == null)
            {
                return;
            }

            Object     mockObject = context.ServiceProvider.GetService(mockAttr.Type);
            MethodInfo method     = mockObject.GetType().GetMethod(context.Method.Name, context.Method.GetParameters().Select(x => x.ParameterType).ToArray());

            context.Result = method.Invoke(mockObject, context.Arguments);
        }
Example #18
0
        /// <summary>
        /// 添加一个客户端
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public HttpProxyBuilder AddClientType(Type type)
        {
            services.AddTransient(type, sp =>
            {
                IHttpProxyFactory factory = sp.GetService <IHttpProxyFactory>();
                MethodInfo method         = factory.GetType().GetMethod("Create").MakeGenericMethod(type);
                return(method.Invoke(factory, null));
            });
            MockAttribute mockAttr = type.GetCustomAttribute <MockAttribute>();

            if (mockAttr != null)
            {
                services.AddSingleton(mockAttr.Type);
            }
            return(this);
        }
        public void AttributeProvider_ProcessInheritance()
        {
            //Arrange
            var attribute         = new MockAttribute();
            var objectDefinitions = this.ContainerFixture.Container.Resolve <IObjectDefinitions <Type> >();

            //Act
            var result = this.ContainerFixture.AttributeProvider.Process(this.ContainerFixture.AttributeProvider.GetFromSource(attribute), objectDefinitions, attribute);

            //Assert
            result.Should().NotBeNull();
            result.Name.Should().Be(nameof(MockAttribute));
            result.Parameters.Should().NotBeNull();
            result.Parameters.Count.Should().Be(8);

            //Parameters Assertion
            result.Parameters.Select(x => x.Name).Contains("PrivateAttr").Should().BeFalse();
            result.Parameters.Select(x => x.Name).Contains("PrivateAttr2").Should().BeFalse();
            result.Parameters.Select(x => x.Name).Contains("ProtectedAttr").Should().BeFalse();
            result.Parameters.Select(x => x.Name).Contains("ProtectedAttr2").Should().BeFalse();
        }
		public void Init()
		{
			firstAttribute = new MockAttribute("first");
			mockClass = MockClass.CreateMockClassWithAttribute(firstAttribute);
		}
Example #21
0
 public void Init()
 {
     firstAttribute = new MockAttribute("first");
     mockClass      = MockClass.CreateMockClassWithAttribute(firstAttribute);
 }
 public void Init()
 {
     firstAttribute = new MockAttribute("first");
     mockMethod     = MockMethod.CreateMockMethodWithAttribute(firstAttribute);
 }
		public void Init()
		{
			firstAttribute = new MockAttribute("first");
			mockMethod = MockMethod.CreateMockMethodWithAttribute(firstAttribute);
		}