Exemple #1
0
        public async Task Process_MethodRunsWithTestClassAndTestGroup_ReturnsTestResult()
        {
            await RunDependencyInjectedTestAsync
            (
                async (serviceProvider) =>
            {
                // Arrange

                var exampleMixedClass = new MixedClass();

                var expectedMethodInfos = exampleMixedClass
                                          .GetType()
                                          .GetMethods(BindingFlags.Public | BindingFlags.Instance)
                                          .Where
                                          (
                    methodInfo =>
                    methodInfo.GetParameters().Length == 1 &&
                    methodInfo.GetParameters()[0].Name == IntegrationTestService.SUCCESSLOG_PRAM_NAME &&
                    methodInfo.GetParameters()[0].ParameterType == typeof(List <string>) &&
                    methodInfo.ReturnType == typeof(Task)
                                          );
                var testAPIAttribute = (TestAPIAttribute)System.Attribute.GetCustomAttributes(exampleMixedClass.GetType()).FirstOrDefault(e => e is TestAPIAttribute);

                var test = new Models.TestAutomation.Test()
                {
                    MethodInfo = expectedMethodInfos.First(),
                    TestClass  = exampleMixedClass,
                    TestGroup  = testAPIAttribute.Group,
                    TestsName  = testAPIAttribute.Name
                };

                var uut         = serviceProvider.GetRequiredService <IIntegrationTestService>();
                var uutConcrete = (IntegrationTestService)uut;

                // Act

                var observed = await uutConcrete.Process(test.TestClass, test).ConfigureAwait(false);

                // Assert

                Assert.IsNotNull(observed);
                Assert.AreEqual(test.MethodInfo.ReflectedType.Name, observed.ClassName);
                Assert.AreEqual(test.TestGroup, observed.TestGroup);
                Assert.AreEqual(test.TestsName, observed.TestsName);
                Assert.IsNotNull(observed.CorrelationId);
                Assert.IsNotNull(observed.Duration);
                Assert.IsNotNull(observed.EndTime);
                Assert.IsNull(observed.Exception);
                Assert.IsNotNull(observed.ExecutionId);
                Assert.IsTrue(observed.Pass);
                Assert.IsNotNull(observed.StartTime);
                Assert.AreEqual(0, observed.SuccessLog.Count());
                Assert.IsNotNull(observed.TestId);
                Assert.IsNotNull(test.MethodInfo.Name, observed.TestName);
                Assert.IsNotNull(observed.TestType);
            },
                serviceCollection => ConfigureServices(serviceCollection)
            );
        }
Exemple #2
0
        public async Task RunTests_MethodRuns_ReturnsTestResults()
        {
            await RunDependencyInjectedTestAsync
            (
                async (serviceProvider) =>
            {
                // Arrange​
                var exampleTestClass = new MixedClass();

                var expectedMethodInfos = exampleTestClass
                                          .GetType()
                                          .GetMethods(BindingFlags.Public | BindingFlags.Instance)
                                          .Where(e => e.DeclaringType.Name == exampleTestClass.GetType().Name);

                var tests = new List <Models.TestAutomation.Test>
                {
                    new Models.TestAutomation.Test()
                    {
                        MethodInfo = expectedMethodInfos.First(),
                        TestClass  = exampleTestClass
                    },
                    new Models.TestAutomation.Test()
                    {
                        MethodInfo = expectedMethodInfos.Last(),
                        TestClass  = exampleTestClass
                    }
                };

                var uut         = serviceProvider.GetRequiredService <IIntegrationTestService>();
                var uutConcrete = (IntegrationTestService)uut;

                // Act

                var observed = await uutConcrete.RunTests(tests).ConfigureAwait(false);

                // Assert​
                Assert.IsNotNull(observed);
                Assert.IsNotNull(observed.Duration);
                Assert.IsNotNull(observed.EndDateTime);
                Assert.IsNotNull(observed.StartDateTime);
                Assert.AreEqual(2, observed.TestResults.Count());
            },
                serviceCollection => ConfigureServices(serviceCollection)
            );
        }