Exemplo n.º 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)
            );
        }
Exemplo n.º 2
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)
            );
        }