예제 #1
0
        public async Task SetupTests_ExampleTestClass_NullTestsNameAndTestGroup()
        {
            await RunDependencyInjectedTestAsync
            (
                async (serviceProvider) =>
            {
                //Setup

                var exampleTestClass = new ExampleTestClass();

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

                //Act
                var observed = uutConcrete.SetupTests(exampleTestClass);

                //Assert
                Assert.AreEqual(2, observed.Count());

                var observedList = observed.ToList();

                Assert.AreEqual("Example_MethodOne_Async", observedList[0].MethodInfo.Name);
                Assert.AreEqual("Example_MethodTwo_Async", observedList[1].MethodInfo.Name);

                Assert.IsNull(observedList[0].TestsName);
                Assert.IsNull(observedList[1].TestsName);

                Assert.IsNull(observedList[0].TestGroup);
                Assert.IsNull(observedList[1].TestGroup);

                await Task.CompletedTask.ConfigureAwait(false);
            },
                serviceCollection => ConfigureServices(serviceCollection)
            );
        }
예제 #2
0
        async Task DoMain()
        {
            try
            {
                var services = InitializeDependencyInjection();
                ConfigureServices(services);

                using (var provider = services.BuildServiceProvider())
                {
                    var integrationTestService  = provider.GetRequiredService <IIntegrationTestService>();
                    var hostApplicationLifetime = provider.GetService <IHostApplicationLifetime>();

                    var exampleTestClass = new ExampleTestClass();

                    //Setup Tests
                    var tests = integrationTestService.SetupTests(exampleTestClass);

                    //Run Tests
                    var testSummary = await integrationTestService.RunTests(tests).ConfigureAwait(false);

                    //Process Test Summary
                    var trxReport = integrationTestService.GenerateTRXReport(testSummary);
                    var log       = integrationTestService.GenerateLog(testSummary, true);

                    //Save Results

                    await integrationTestService.SaveResultsToDatabase(testSummary).ConfigureAwait(false);

                    //Package Results
                    var zip = integrationTestService.GenerateZip(trxReport, log);

                    //Conole Summary
                    Console.WriteLine("Log:");
                    Console.WriteLine(log);
                    Console.WriteLine();

                    Console.WriteLine("TRX Report:");
                    Console.WriteLine(trxReport);
                    Console.WriteLine();

                    Console.WriteLine($"Zip Generated: {zip != null}");
                    Console.WriteLine();

                    hostApplicationLifetime.StopApplication();
                }
                await Task.CompletedTask.ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                Console.WriteLine("End...");
                Console.ReadKey();
            }
        }
예제 #3
0
        public async Task Process_MethodRuns_ReturnsTestResult()
        {
            await RunDependencyInjectedTestAsync
            (
                async (serviceProvider) =>
            {
                // Arrange

                var exampleTestClass = new ExampleTestClass();

                var expectedMethodInfos = exampleTestClass
                                          .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 test = new Models.TestAutomation.Test()
                {
                    MethodInfo = expectedMethodInfos.First(),
                    TestClass  = exampleTestClass
                };

                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.IsNull(observed.TestGroup);
                Assert.AreEqual(test.MethodInfo.ReflectedType.Name, observed.ClassName);
                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(1, observed.SuccessLog.Count());
                Assert.IsNotNull(observed.TestId);
                Assert.IsNotNull(test.MethodInfo.Name, observed.TestName);
                Assert.IsNotNull(observed.TestType);
            },
                serviceCollection => ConfigureServices(serviceCollection)
            );
        }
예제 #4
0
        public async Task Process_MethodThrows_ReturnsTestResult()
        {
            await RunDependencyInjectedTestAsync
            (
                async (serviceProvider) =>
            {
                // Arrange

                var exampleTestClass = new ExampleTestClass();

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

                var test = new Models.TestAutomation.Test()
                {
                    MethodInfo = expectedMethodInfos.Last(),
                    TestClass  = exampleTestClass
                };

                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.IsNotNull(observed.CorrelationId);
                Assert.IsNotNull(observed.Duration);
                Assert.IsNotNull(observed.EndTime);
                Assert.IsNotNull(observed.Exception);
                Assert.IsNotNull(observed.ExecutionId);
                Assert.IsFalse(observed.Pass);
                Assert.IsNotNull(observed.StartTime);
                Assert.AreEqual(1, observed.SuccessLog.Count());
                Assert.IsNotNull(observed.TestId);
                Assert.IsNotNull(test.MethodInfo.Name, observed.TestName);
                Assert.IsNotNull(observed.TestType);
            },
                serviceCollection => ConfigureServices(serviceCollection)
            );
        }