Esempio n. 1
0
        Xunit2Discoverer(ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            appDomain = new RemoteAppDomainManager(assemblyFileName ?? xunitExecutionAssemblyPath, configFileName, shadowCopy, shadowCopyFolder);

            var testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
                assemblyInfo = appDomain.CreateObject<IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);

            framework = appDomain.CreateObject<ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkProxy"/> class.
        /// </summary>
        /// <param name="testAssemblyObject">The test assembly (expected to implement <see cref="IAssemblyInfo"/>).</param>
        /// <param name="sourceInformationProviderObject">The source information provider (expected to implement <see cref="ISourceInformationProvider"/>).</param>
        public TestFrameworkProxy(object testAssemblyObject, object sourceInformationProviderObject)
        {
            var testAssembly = (IAssemblyInfo)testAssemblyObject;
            var sourceInformationProvider = (ISourceInformationProvider)sourceInformationProviderObject;

            Type testFrameworkType = typeof(XunitTestFramework);

            try
            {
                var attr = testAssembly.GetCustomAttributes(typeof(TestFrameworkAttribute)).FirstOrDefault();
                if (attr != null)
                {
                    var ctorArgs = attr.GetConstructorArguments().Cast<string>().ToArray();
                    testFrameworkType = Reflector.GetType(ctorArgs[1], ctorArgs[0]);
                }
            }
            catch
            {
                // TODO: Log environmental error
            }

            try
            {
                testFramework = (ITestFramework)Activator.CreateInstance(testFrameworkType);
            }
            catch
            {
                // TODO: Log environmental error
                testFramework = new XunitTestFramework();
            }

            SourceInformationProvider = sourceInformationProvider;
        }
Esempio n. 3
0
        Xunit2Discoverer(ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
#if !ANDROID
            Guard.ArgumentValid("xunitExecutionAssemblyPath", "File not found: " + xunitExecutionAssemblyPath, File.Exists(xunitExecutionAssemblyPath));
#endif
            appDomain = new RemoteAppDomainManager(assemblyFileName ?? xunitExecutionAssemblyPath, configFileName, shadowCopy, shadowCopyFolder);

#if !ANDROID
            var name = AssemblyName.GetAssemblyName(xunitExecutionAssemblyPath);
            var testFrameworkAssemblyName = name.FullName;
#else
            var name = Assembly.Load(xunitExecutionAssemblyPath);
            var testFrameworkAssemblyName = name.FullName;
#endif

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
                assemblyInfo = appDomain.CreateObject<IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);

            framework = appDomain.CreateObject<ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
		MockCSharpProject CreateCSharpProjectSupportedByTestFramework()
		{
			MockCSharpProject project = CreateCSharpProjectNotSupportedByTestFramework();
			fakeTestFramework = MockRepository.GenerateStrictMock<ITestFramework>();
			fakeTestFramework.Stub(f => f.IsTestProject(project)).Return(true);
			return project;
		}
		MockCSharpProject CreateCSharpProjectNotSupportedByTestFramework()
		{
			var project = new MockCSharpProject();
			project.FileName = FileName.Create(@"d:\projects\MyProject\MyProject.csproj");
			fakeTestFramework = MockRepository.GenerateStrictMock<ITestFramework>();
			fakeTestFramework.Stub(f => f.IsTestProject(project)).Return(false);
			return project;
		}
        public static void Throw(string message)
        {
            if (testFramework == null)
            {
                testFramework = DetectFramework();
            }

            testFramework.Throw(message);
        }
        public static void Throw(string message)
        {
            if (testFramework == null)
            {
                testFramework = FindStrategy();
            }

            testFramework.Throw(message);
        }
Esempio n. 8
0
        /// <inheritdoc/>
        public void Assert(ITestFramework testFramework, object value, string messagePrefix)
        {
            if (value == null)
            {
                value = string.Empty;
            }
            testFramework.IsInstanceOfType(value, typeof(string), $"{messagePrefix} is not a valid String object");

            testFramework.AreEqual(ExpectedLength, ((string)value)?.Length ?? 0, $"{messagePrefix} has an unexpected length");
        }
 public void TearDown()
 {
   if (harness != null)
   {
     harness.Dispose();
     harness = null;
     framework = null;
     sampleAssembly = null;
   }
 }
        public bool IsBuildNeededBeforeTestRunForProject(IProject project)
        {
            ITestFramework testFramework = GetTestFrameworkForProject(project);

            if (testFramework != null)
            {
                return(testFramework.IsBuildNeededBeforeTestRun);
            }
            return(true);
        }
    public void SetUp()
    {
      sampleAssembly = GetSampleAssembly();

      harness = new DefaultTestHarness(TestContextTrackerAccessor.GetInstance(),
        RuntimeAccessor.Instance.Resolve<ILoader>());

      framework = CreateFramework();
      harness.AddTestFramework(framework);
    }
        public ITestRunner CreateTestDebugger(IProject project)
        {
            ITestFramework testFramework = GetTestFrameworkForProject(project);

            if (testFramework != null)
            {
                return(testFramework.CreateTestDebugger());
            }
            return(null);
        }
Esempio n. 13
0
        public void GetTestFrameworkForProject_MbUnitTestFrameworkRegisteredForUseWithProjectsWithVBNetProjectFileExtension_ReturnsMBUnitTestFramework()
        {
            MockCSharpProject project = new MockCSharpProject();

            project.FileName = @"d:\projects\test\MyProj.vbproj";
            mbUnitTestFramework.AddTestProject(project);

            ITestFramework testFramework = testFrameworks.GetTestFrameworkForProject(project);

            Assert.AreEqual(mbUnitTestFramework, testFramework);
        }
Esempio n. 14
0
 public TestConfiguration(
     ITestFramework testFramework,
     string applicationProjectBaseNamespace,
     string testProjectBaseNamespace,
     string testProjectBasePath)
 {
     TestFramework = testFramework;
     ApplicationProjectBaseNamespace = applicationProjectBaseNamespace;
     TestProjectBaseNamespace        = testProjectBaseNamespace;
     TestProjectBasePath             = testProjectBasePath;
 }
        private static ITestFramework FindStrategy()
        {
            ITestFramework detectedFramework = null;
            detectedFramework = AttemptToDetectUsingAssemblyScanning();

            if (detectedFramework == null)
            {
                FailWithIncorrectConfiguration();
            }

            return detectedFramework;
        }
Esempio n. 16
0
        public FrameworkSet(ITestFramework testFramework, IMockingFramework mockingFramework, IGenerationContext context, string testTypeNaming)
        {
            if (string.IsNullOrWhiteSpace(testTypeNaming))
            {
                throw new ArgumentNullException(nameof(testTypeNaming));
            }

            TestFramework    = testFramework ?? throw new ArgumentNullException(nameof(testFramework));
            MockingFramework = mockingFramework ?? throw new ArgumentNullException(nameof(mockingFramework));
            Context          = context ?? throw new ArgumentNullException(nameof(context));
            TestTypeNaming   = testTypeNaming;
        }
Esempio n. 17
0
        public void TestFrameworkDescriptorTestFrameworkPropertyOnlyCreatesOneObject()
        {
            ITestFramework testFramework = descriptor.TestFramework;

            testFramework = descriptor.TestFramework;

            List <string> expectedClassNames = new List <string>();

            expectedClassNames.Add("UnitTesting.Tests.Utils.MockTestFramework");

            Assert.AreEqual(expectedClassNames, mockTestFrameworkFactory.ClassNamesPassedToCreateMethod);
        }
Esempio n. 18
0
        /// <inheritdoc/>
        public void Assert(ITestFramework testFramework, object value, string messagePrefix)
        {
            testFramework.IsInstanceOfType(value, typeof(DateTime), $"{messagePrefix} is not a valid DateTime object");

            DateTime actualDay = GetDateDay((DateTime)value);

            TimeSpan difference = actualDay - ExpectedDateDay;

            testFramework.AreEqual(ExpectedDateDay,
                                   actualDay,
                                   $"{messagePrefix} is different by {{0}}",
                                   $"{difference.TotalDays} day{(Math.Abs(difference.TotalDays) == 1 ? "" : "s")}");
        }
Esempio n. 19
0
        /// <summary>
        /// <para>Asserts that the value is correct, according to the expected value.</para>
        /// <para>Where the expected value is a native type, object equality is used as the test.  Where the expected value is an <see cref="IComparison"/> object, the specific <see cref="IComparison"/> assertion logic is used</para>
        /// </summary>
        /// <param name="testFramework">The test framework to use for assertions</param>
        /// <param name="expectedValue">The expected value.  This can be either a native type or an <see cref="IComparison"/> object</param>
        /// <param name="value">The value to test</param>
        /// <param name="messagePrefix">The prefix of the message to use during assertion failure</param>
        public static void Assert(ITestFramework testFramework, object expectedValue, object value, string messagePrefix)
        {
            expectedValue = expectedValue ?? DBNull.Value;
            value         = value ?? DBNull.Value;

            if (expectedValue is IComparison comparisonValue)
            {
                comparisonValue.Assert(testFramework, value, messagePrefix);
            }
            else
            {
                testFramework.AreEqual(expectedValue, value, $"{messagePrefix} has an unexpected value");
            }
        }
Esempio n. 20
0
        internal TestFixture(TestSuite suite, ITestFramework framework,
                             AsyncTestFixtureAttribute attr, Type type)
        {
            this.Suite     = suite;
            this.Framework = framework;
            this.Attribute = attr;
            this.Type      = type;

            IDictionary <Type, TestCategoryAttribute> categories;
            IList <TestWarning> warnings;

            Resolve(suite, null, type, out categories, out warnings, out config, out disabled);
            Categories = categories.Values.ToList().AsReadOnly();
            Warnings   = warnings;
        }
        public void TestFramework_PropertyAccessTwice_OnlyOneObjectCreated()
        {
            CreateDoozer();
            ITestFramework testFramework = descriptor.TestFramework;

            testFramework = descriptor.TestFramework;

            List <string> expectedClassNames = new List <string>();

            expectedClassNames.Add("UnitTesting.Tests.Utils.MockTestFramework");

            List <string> classNamesCreated = mockTestFrameworkFactory.ClassNamesPassedToCreateMethod;

            Assert.AreEqual(expectedClassNames, classNamesCreated);
        }
Esempio n. 22
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);

#if NET35 || NET452
            // Only safe to assume the execution reference is copied in a desktop project
            if (verifyAssembliesOnDisk)
            {
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);
            }

            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#else
            CanUseAppDomains = false;
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            appDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

#if NET35 || NET452
            var runnerUtilityAssemblyLocation = Path.GetDirectoryName(typeof(AssemblyHelper).Assembly.GetLocalCodeBase());
            assemblyHelper = appDomain.CreateObjectFrom <AssemblyHelper>(typeof(AssemblyHelper).Assembly.Location, typeof(AssemblyHelper).FullName, runnerUtilityAssemblyLocation);
#endif

            testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
            {
                assemblyInfo = appDomain.CreateObject <IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);
            }

            framework = appDomain.CreateObject <ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);

            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
        public static SyntaxTestCasesBuilder For(
            ICollection <IMethodSignature> signatures,
            IMethods methods,
            ITestFramework framework)
        {
            if (!signatures.Any())
            {
                return(new SyntaxTestCaseBuilderNoParameters(methods));
            }

            if (framework.TestAssertException().Supported)
            {
                return(new SyntaxTestCaseBuilderWrapPartialsWithTryBlock(signatures, methods, framework));
            }

            return(new SyntaxTestCaseBuilderCallPartialDirect(signatures, methods));
        }
        private static ITestFramework DetectFramework()
        {
            ITestFramework detectedFramework = null;

            detectedFramework = AttemptToDetectUsingAppSetting();
            if (detectedFramework == null)
            {
                detectedFramework = AttemptToDetectUsingAssemblyScanning();
            }

            if (detectedFramework == null)
            {
                FailWithIncorrectConfiguration();
            }

            return(detectedFramework);
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AppDomainTestFramework"/> class.
        /// </summary>
        /// <param name="sourceInformationProvider">The source code information provider.</param>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="testFrameworkFileName">The file path of the test framework assembly (i.e., xunit2.dll).</param>
        /// <param name="testFrameworkTypeName">The fully qualified type name of the implementation of <see cref="ITestFramework"/>
        /// in the test framework assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <param name="shadowCopy">If set to <c>true</c>, runs tests in a shadow copied app domain, which allows
        /// tests to be discovered and run without locking assembly files on disk.</param>
        public AppDomainTestFramework(ISourceInformationProvider sourceInformationProvider, string assemblyFileName, string testFrameworkFileName, string testFrameworkTypeName, string configFileName = null, bool shadowCopy = true)
        {
            Guard.ArgumentNotNull("sourceInformationProvider", sourceInformationProvider);
            Guard.ArgumentNotNullOrEmpty("testFrameworkFileName", testFrameworkFileName);

            testFrameworkFileName = Path.GetFullPath(testFrameworkFileName);
            Guard.ArgumentValid("testFrameworkFileName", "File not found: " + testFrameworkFileName, File.Exists(testFrameworkFileName));

            SourceInformationProvider = sourceInformationProvider;

            // assemblyFileName might be null (during AST-based discovery), so pass along with the test
            // framework filename instead if we don't have an assembly under test yet.
            appDomain = new RemoteAppDomainManager(assemblyFileName ?? testFrameworkFileName, configFileName, shadowCopy);

            testFrameworkAssemblyName = AssemblyName.GetAssemblyName(testFrameworkFileName);
            testFramework             = appDomain.CreateObject <ITestFramework>(testFrameworkAssemblyName.FullName, testFrameworkTypeName);
            testFramework.SourceInformationProvider = SourceInformationProvider;
        }
Esempio n. 26
0
        Xunit2Discoverer(ISourceInformationProvider sourceInformationProvider, IAssemblyInfo assemblyInfo, string assemblyFileName, string xunitExecutionAssemblyPath, string configFileName, bool shadowCopy)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            Guard.ArgumentValid("xunitExecutionAssemblyPath", "File not found: " + xunitExecutionAssemblyPath, File.Exists(xunitExecutionAssemblyPath));

            appDomain = new RemoteAppDomainManager(assemblyFileName ?? xunitExecutionAssemblyPath, configFileName, shadowCopy);

            var testFrameworkAssemblyName = AssemblyName.GetAssemblyName(xunitExecutionAssemblyPath).FullName;

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
            {
                assemblyInfo = appDomain.CreateObject <IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);
            }

            framework  = appDomain.CreateObject <ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
Esempio n. 27
0
        private static CompilationUnitSyntax AppendUsings(
            CompilationUnitSyntax syntaxFactory,
            ClassInformation classInfo,
            ITestFramework testFramework)
        {
            classInfo.AppendUsing(UsingEntry.CreateFrom("Moq"));
            classInfo.AppendUsing(testFramework.UsingEntry);
            classInfo.AppendUsing(UsingEntry.CreateFrom(classInfo.NamespaceDecl));

            foreach (var usingName in classInfo.SortedUsingEntries)
            {
                syntaxFactory = syntaxFactory
                                .AddUsings(
                    SyntaxFactory.UsingDirective(
                        SyntaxFactory.ParseName(usingName.Value)));
            }

            return(syntaxFactory);
        }
        private static ITestFramework FindStrategy()
        {
            ITestFramework detectedFramework = null;

#if !WINRT
            detectedFramework = AttemptToDetectUsingAppSetting();
#endif
            if (detectedFramework == null)
            {
                detectedFramework = AttemptToDetectUsingAssemblyScanning();
            }

            if (detectedFramework == null)
            {
                FailWithIncorrectConfiguration();
            }

            return(detectedFramework);
        }
        private static ITestFramework AttemptToDetectUsingAppSetting()
        {
            string frameworkName = ConfigurationManager.AppSettings[AppSettingKey];

            if (!string.IsNullOrEmpty(frameworkName) && frameworks.ContainsKey(frameworkName.ToLower()))
            {
                ITestFramework framework = frameworks[frameworkName.ToLower()];
                if (!framework.IsAvailable)
                {
                    throw new Exception(
                              "FluentAssertions was configured to use " + frameworkName +
                              " but the required test framework assembly could not be found");
                }

                return(framework);
            }

            return(null);
        }
Esempio n. 30
0
        /// <summary>
        /// Create an appropriate implementation for the given
        /// environment.
        /// </summary>
        /// <returns>a new <see cref="ITestFramework"/></returns>
        public ITestFramework NewImplementation()
        {
            Type implementationType = getStaticImplementationType();

            if (implementationType == null)
            {
                implementationType = getDynamicImplementationType();
            }
            if (implementationType == null)
            {
                throw new SystemException(
                          "Cannot find an appropriate test framework implementation."
                          );
            }
            ITestFramework implementation = (ITestFramework)
                                            _linker.CreateInstance(implementationType);

            return(implementation);
        }
Esempio n. 31
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            if (verifyAssembliesOnDisk)
            {
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);
            }

#if PLATFORM_DOTNET
            CanUseAppDomains = false;
#else
            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            appDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

            var testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
            {
                assemblyInfo = appDomain.CreateObject <IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);
            }

            framework  = appDomain.CreateObject <ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
		public void AddTestFrameworkForProject(IProject project, ITestFramework testFramework)
		{
			testFrameworks.Add(project, testFramework);
		}
		void CreateTestFrameworkIfNotCreated()
		{
			if (testFramework == null) {
				testFramework = (ITestFramework)objectFactory(ClassName);
			}
		}
Esempio n. 34
0
 /// <summary>
 /// Constructor, including the test framework to use and the query result data
 /// </summary>
 /// <param name="testFramework">The test framework to use for assertions</param>
 /// <param name="rawData">The data returned from the query execution</param>
 public QueryResult(ITestFramework testFramework, DataTable rawData)
 {
     TestFramework = testFramework;
     RawData       = rawData ?? new DataTable();
 }
Esempio n. 35
0
 /// <summary>
 /// Constructor, including the test framework to use
 /// </summary>
 /// <param name="testFramework">The test framework to use for assertions</param>
 public QueryResult(ITestFramework testFramework)
 {
     TestFramework = testFramework;
     RawData       = new DataTable();
 }
Esempio n. 36
0
        public IEnumerable<Violation> Apply(TestCase testCase)
        {
            // Store the framework so that we don't have to pass it around everywhere.
            _framework = testCase.Framework;

            var calledAssertingMethods = testCase.GetCalledAssertingMethods();
            var tracker = new MethodValueTracker(testCase.TestMethod);

            var whitelistedFields = FindWhitelistedFields(testCase.TestMethod.DeclaringType);

            // For each asserting method with >= 1 parameters:
            foreach (var cm in calledAssertingMethods.Where(cm => cm.MethodDefinition.HasParameters))
            {
                var method = cm.MethodDefinition;
                //TODO: if the method is a helper, we need to "unfold" the helper
                // to get to the real asserting methods, and this will require us
                // to join value-generation graphs across method calls...
                var paramPurposes = _framework.GetParameterPurposes(method);
                if (paramPurposes == null) continue; // unknown method, rule does not apply

                foreach (var valueGraph in tracker.ValueGraphs)
                {
                    IList<MethodValueTracker.Value> consumedValues = tracker.GetConsumedValues(valueGraph, cm.Instruction).ToList();
                    if (consumedValues.Count == 0)
                        continue; // not part of value graph

                    // Build a list of arguments with the details we need to know if the rule applies.
                    var arguments = method.Parameters
                        .Select((p, index) => new ArgumentDetails { Method = method, Index = index, Purpose = paramPurposes[index], ConsumedValue = consumedValues[index] }).ToList();

                    // Handle cases like Assert.IsTrue(x == 5) by expanding arguments
                    ExpandIfSingleTruthCheckingMethod(method, ref arguments);

                    // We're only interested in arguments that represent expectations!
                    var interestingArguments = arguments.Where(a => IsPerhapsExpectation(a.Purpose)).ToList();

                    // This might happen with for example Assert.Fail("some reason").
                    if (interestingArguments.Count == 0)
                        continue;

                    // Add in the "forbidden producer", if any, for each argument. A forbidden producer is an
                    // instruction that generates a value externally, such as a call.
                    interestingArguments = interestingArguments.Select(
                            a => { a.ForbiddenProducer = FirstForbiddenProducer(valueGraph, a.ConsumedValue, whitelistedFields); return a; }).ToList();

                    // If there is at least one locally produced argument, the rule doesn't apply.
                    if (interestingArguments.Any(IsLocallyProduced))
                        continue;

                    if (interestingArguments.All(a => a.Purpose == ParameterPurpose.ExpectedOrActual))
                    {
                        // Since we don't know exactly which parameter that represents the expectation, we
                        // just generate a single violation.
                        yield return new Violation(this, testCase, interestingArguments[0].ConsumedValue.Consumer,
                            CreateViolationMessageForUncertainCase(interestingArguments[0]));
                        continue;
                    }

                    foreach (var a in interestingArguments.Where(IsExternallyProduced))
                    {

                        // Generate a violation at the location of the forbidden producer!
                        yield return new Violation(this, testCase, a.ForbiddenProducer, CreateViolationMessage(a));
                    }
                }
            }
        }
        /// <summary>
        /// Adds the references.
        /// </summary>
        /// <param name="vsProject">The vs project.</param>
        /// <param name="testFramework">The test framework.</param>
        private static void AddReferences(VSProject vsProject, ITestFramework testFramework)
        {
            if (vsProject != null)
            {
                string executingDirectory =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                foreach (string reference in testFramework.References)
                {
                    try
                    {
                        vsProject.References.Add(Path.Combine(executingDirectory, reference));
                    }
                    catch (Exception ex)
                    {
                        Logger.Write(ex.ToString());
                    }
                }
            }
        }
		void CreateTestFrameworkIfNotCreated()
		{
			if (testFramework == null) {
				testFramework = factory.Create(ClassName);
			}
		}
		public void Add(string className, ITestFramework framework)
		{
			frameworks.Add(className, framework);
		}
Esempio n. 40
0
 public void CannotCallCreateTestMethodWithInvalidName(ITestFramework testClass)
 {
     Assert.Throws <ArgumentNullException>(() => testClass.CreateTestMethod(null, true, false));
 }
Esempio n. 41
0
 public void CannotCallCreateTestCaseMethodWithNullValueType(ITestFramework testClass)
 {
     Assert.Throws <ArgumentNullException>(() => testClass.CreateTestCaseMethod("TestValue160877669", true, false, default(TypeSyntax), new[] { new object(), new object(), new object() }));
 }
Esempio n. 42
0
 public void CannotCallCreateTestCaseMethodWithNullTestValues(ITestFramework testClass)
 {
     Assert.Throws <ArgumentNullException>(() => testClass.CreateTestCaseMethod("TestValue1054789916", false, true, SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)), default(IEnumerable <object>)));
 }
Esempio n. 43
0
 public void CannotCallCreateTestCaseMethodWithNullName(ITestFramework testClass)
 {
     Assert.Throws <ArgumentNullException>(() => testClass.CreateTestCaseMethod(default(string), true, false, SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)), new[] { new object(), new object(), new object() }));
 }
Esempio n. 44
0
 public void CannotCallCreateSetupMethodWithInvalidTargetTypeName(ITestFramework testClass)
 {
     Assert.Throws <ArgumentNullException>(() => testClass.CreateSetupMethod(null));
 }
Esempio n. 45
0
		internal TestFixture (TestSuite suite, ITestFramework framework,
		                      AsyncTestFixtureAttribute attr, Type type)
		{
			this.Suite = suite;
			this.Framework = framework;
			this.Attribute = attr;
			this.Type = type;

			IDictionary<Type, TestCategoryAttribute> categories;
			IList<TestWarning> warnings;

			Resolve (suite, null, type, out categories, out warnings, out config, out disabled);
			Categories = categories.Values.ToList ().AsReadOnly ();
			Warnings = warnings;
		}
        /// <summary>
        /// Updates the model.
        /// </summary>
        /// <param name="projectItems">The project items.</param>
        /// <param name="fw">The fw.</param>
        public static void UpdateModel(
            ProjectItems projectItems,
            ITestFramework fw)
        {
            for (var i = 1; i < projectItems.Count - 1; i++)
            {
                var projectItem = projectItems.Item(i);

                if (projectItem.Name.EndsWith(
                    ".log",
                    StringComparison.OrdinalIgnoreCase)) continue;

                var testClass =
                    (from tc in fw.Classes
                     where tc.Name == projectItem.Name.Replace(".cs", "")
                     select tc).FirstOrDefault();

                if (testClass == null)
                {
                    //todo: dump code to log....
                    continue;
                }

                string fileContent;
                using (var sr = new StreamReader(projectItem.FileNames[0]))
                {
                    fileContent = sr.ReadToEnd();
                }

                var usingMatches = s_usingRegex.Matches(fileContent);
                for (var j = 0; j < usingMatches.Count; j++)
                {
                    var match = usingMatches[j];
                    if (!testClass.UsingStatements.Contains(match.Value))
                    {
                        testClass.UsingStatements.Add(match.Value);
                    }
                }

                var matches = s_codeRegex.Matches(fileContent);
                for (var j = 0; j < matches.Count; j++)
                {
                    var match = matches[j];

                    if (!match.Success) continue;

                    var testName = match.Groups["testname"].Value;
                    var testAttributes = match.Groups["attributes"].Value;
                    var testImplementation = match.Groups["code"].Value;

                    var test =
                        (from t in testClass.Tests
                         where t.Name == testName
                         select t).FirstOrDefault();

                    if (test == null)
                    {
                        //todo: dump code to log....
                        continue;
                    }

                    test.Attributes = testAttributes;
                    test.Implementation = testImplementation;
                }
            }
        }
Esempio n. 47
0
 public RelatedFrameworks(ITestFramework framework, params IMockFramework[] others)
 {
     MockFrameworks = others.ToArray(); // make copy
     TestFramework = framework;
 }
Esempio n. 48
0
			internal void CheckTestFramework()
			{
				ITestFramework newTestFramework = testSolution.testService.GetTestFrameworkForProject(project);
				if (newTestFramework == oldTestFramework)
					return; // test framework is unchanged
				
				// Remove old testProject
				if (testProject != null) {
					testSolution.NestedTestCollection.Remove(testProject);
					testProject = null;
				}
				// Create new testProject
				if (newTestFramework != null) {
					testProject = newTestFramework.CreateTestProject(testSolution, project);
					if (testProject == null)
						throw new InvalidOperationException("CreateTestProject() returned null");
					testSolution.NestedTestCollection.Add(testProject);
				}
				oldTestFramework = newTestFramework;
			}
Esempio n. 49
0
 /// <summary>
 /// Constructor, including the test framework and the query result data
 /// </summary>
 /// <param name="testFramework">The test framework to use for assertions</param>
 /// <param name="rawData">The data returned from the query execution</param>
 public ScalarResult(ITestFramework testFramework, T rawData)
 {
     TestFramework = testFramework;
     RawData       = rawData;
 }
Esempio n. 50
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            if (verifyAssembliesOnDisk)
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);

#if PLATFORM_DOTNET
            CanUseAppDomains = false;
#else
            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            appDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

            var testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
                assemblyInfo = appDomain.CreateObject<IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);

            framework = appDomain.CreateObject<ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }