コード例 #1
0
        public void AddEnvironmentForTest()
        {
            var notifications = new List<TestCompletedNotification>();
            var builder = new Mock<IReportBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);

            var environment = new Mock<IActiveEnvironment>();
            {
                environment.Setup(e => e.Environment)
                    .Returns("a");
            }

            storage.AddEnvironmentForTest(testId, environment.Object);

            Assert.That(
                storage.EnvironmentsForTest(testId),
                Is.EquivalentTo(
                    new List<IActiveEnvironment>
                        {
                            environment.Object
                        }));
        }
コード例 #2
0
        public void Add()
        {
            var notifications = new List<TestCompletedNotification>
                {
                    new FileBasedTestCompletedNotification("b"),
                };

            var report = new Mock<IReport>();
            var builder = new Mock<IReportBuilder>();
            {
                builder.Setup(b => b.Build())
                    .Returns(report.Object);
            }

            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);

            Assert.That(
                storage.NotificationsFor(testId),
                Is.EquivalentTo(notifications));
            Assert.AreSame(report.Object, storage.ReportFor(testId));
        }
コード例 #3
0
        public void EnvironmentFailure()
        {
            var notifications = new List<TestCompletedNotification>();
            var builder = new Mock<IReportBuilder>();
            {
                builder.Setup(b => b.AddToSection(It.IsAny<string>(), It.IsAny<IEnumerable<TestSection>>()))
                    .Verifiable();
            }

            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testCompleted = false;
            var testResult = TestExecutionResult.None;
            storage.OnTestCompletion +=
                (s, e) =>
                {
                    testCompleted = true;
                    testResult = e.Result;
                };

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);

            var environmentId = "a";
            var firstEnvironment = new Mock<IActiveEnvironment>();
            {
                firstEnvironment.Setup(e => e.Environment)
                    .Returns(environmentId);
                firstEnvironment.Setup(e => e.Terminate())
                    .Verifiable();
            }

            var secondEnvironment = new Mock<IActiveEnvironment>();
            {
                secondEnvironment.Setup(e => e.Environment)
                    .Returns(environmentId);
                secondEnvironment.Setup(e => e.Terminate())
                    .Verifiable();
            }

            storage.AddEnvironmentForTest(testId, firstEnvironment.Object);
            storage.AddEnvironmentForTest(testId, secondEnvironment.Object);

            storage.EnvironmentFailure(testId, environmentId);

            Assert.IsTrue(testCompleted);
            Assert.AreEqual(TestExecutionResult.Failed, testResult);
            firstEnvironment.Verify(e => e.Terminate(), Times.Once());
            secondEnvironment.Verify(e => e.Terminate(), Times.Once());
        }
コード例 #4
0
        public void Remove()
        {
            var notifications = new List<TestCompletedNotification>();
            var builder = new Mock<IReportBuilder>();
            {
                builder.Setup(b => b.AddToSection(It.IsAny<string>(), It.IsAny<IEnumerable<TestSection>>()))
                    .Verifiable();
            }

            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);
            Assert.That(
                storage,
                Is.EquivalentTo(
                    new List<int>
                        {
                            testId
                        }));

            storage.Remove(testId);
            Assert.AreEqual(0, storage.Count());
        }
コード例 #5
0
        public void HandleEnvironmentTestCompletion()
        {
            var notifications = new List<TestCompletedNotification>();
            var builder = new Mock<IReportBuilder>();
            {
                builder.Setup(b => b.AddToSection(It.IsAny<string>(), It.IsAny<IEnumerable<TestSection>>()))
                    .Verifiable();
            }

            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testCompleted = false;
            storage.OnTestCompletion += (s, e) => testCompleted = true;

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);

            var environment = new Mock<IActiveEnvironment>();
            {
                environment.Setup(e => e.Environment)
                    .Returns("a");
            }

            storage.AddEnvironmentForTest(testId, environment.Object);

            environment.Raise(e => e.OnTestCompletion += null, new TestExecutionResultEventArgs(testId, TestExecutionResult.Failed));
            Assert.IsTrue(testCompleted);
        }
コード例 #6
0
        public void HandleEnvironmentExecutionProgress()
        {
            var notifications = new List<TestCompletedNotification>();
            var builder = new Mock<IReportBuilder>();
            {
                builder.Setup(b => b.AddToSection(It.IsAny<string>(), It.IsAny<IEnumerable<TestSection>>()))
                    .Verifiable();
            }

            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var storage = new ActiveTestStorage(diagnostics);

            var testId = 10;
            storage.Add(testId, builder.Object, notifications);

            var environment = new Mock<IActiveEnvironment>();
            {
                environment.Setup(e => e.Environment)
                    .Returns("a");
            }

            storage.AddEnvironmentForTest(testId, environment.Object);

            environment.Raise(
                e => e.OnExecutionProgress += null,
                new TestExecutionProgressEventArgs(
                    testId,
                    "a",
                    new TestSection(
                        "b",
                        DateTimeOffset.Now,
                        DateTimeOffset.Now,
                        false,
                        Enumerable.Empty<DateBasedTestInformation>(),
                        Enumerable.Empty<DateBasedTestInformation>(),
                        Enumerable.Empty<DateBasedTestInformation>())));
            builder.Verify(b => b.AddToSection(It.IsAny<string>(), It.IsAny<IEnumerable<TestSection>>()), Times.Once());
        }
コード例 #7
0
        public void ActivateTestsWithoutEnvironments()
        {
            var configuration = CreateConfiguration();
            var environmentPackage = new Mock<ITestEnvironmentPackage>();
            {
                environmentPackage.Setup(e => e.PackagePath)
                    .Returns("a");
            }

            var suitePackage = new Mock<ITestSuitePackage>();
            {
                suitePackage.Setup(s => s.Environment(It.IsAny<string>()))
                    .Returns(environmentPackage.Object);
            }

            Func<ITestSuitePackage> packageFunc = () => suitePackage.Object;

            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var activeTests = new ActiveTestStorage(diagnostics);
            var environmentContext = new Mock<IProvideTestingContext>();
            {
                environmentContext.Setup(
                    e => e.InactiveMachinesWith(
                        It.IsAny<OperatingSystemDescription>(),
                        It.IsAny<IEnumerable<ApplicationDescription>>()))
                    .Returns(new List<MachineDescription>());
                environmentContext.Setup(e => e.InactiveTests())
                    .Returns(
                        new List<Shared.DataAccess.Test>
                            {
                                new Shared.DataAccess.Test
                                    {
                                        pk_TestId = 10,
                                        IsReadyForExecution = true,
                                        Owner = "a",
                                        ProductName = "b",
                                        ProductVersion = "1.2.3.4",
                                        RequestTime = DateTimeOffset.Now,
                                        ReportPath = @"c:\d\e\f",
                                        TestEnvironments = new List<TestEnvironment>(),
                                    },
                            });
            }

            var activeEnvironment = new Mock<IActiveEnvironment>();
            var activator = new Mock<IEnvironmentActivator>();
            {
                activator.Setup(a => a.Load(It.IsAny<MachineDescription>(), It.IsAny<ITestSectionBuilder>(), It.IsAny<Action<string>>()))
                    .Returns(activeEnvironment.Object);
            }

            var activators = new List<IEnvironmentActivator>
                {
                    activator.Object,
                };
            var fileSystem = new Mock<IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                    .Returns(new MockPath());
            }

            Func<IReportBuilder> reportBuilders = () => new Mock<IReportBuilder>().Object;
            Func<string, IReportBuilder, ITestSectionBuilder> sectionBuilders = (s, b) => new Mock<ITestSectionBuilder>().Object;

            var controller = new TestController(
                configuration.Object,
                activeTests,
                () => new Owned<IProvideTestingContext>(environmentContext.Object, new MockDisposable()),
                activators,
                packageFunc,
                fileSystem.Object,
                reportBuilders,
                sectionBuilders,
                diagnostics);
            controller.ActivateTests();
            Assert.AreEqual(0, activeTests.Count());
        }
コード例 #8
0
        public void ActivateTestsWithSingleEnvironment()
        {
            var configuration = CreateConfiguration();
            var environmentName = "td";
            var testEnvironment = CreateFakeTestEnvironment(environmentName);
            var test = CreateFakeTestSpecification(testEnvironment);
            var steps = new List<TestStep>
            {
                new MsiInstallTestStep
                    {
                        Order = 0,
                        FailureMode = TestStepFailureMode.Continue,
                    }
            };

            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var activeTests = new ActiveTestStorage(diagnostics);
            var machineDescription = new PhysicalMachineDescription
                {
                    Id = "a-b",
                    Name = "ma",
                    Description = "mb",
                    MacAddress = "mc",
                    NetworkName = "md",
                    OperatingSystemId = 0,
                    IsAvailableForTesting = true,
                    CanStartRemotely = false,
                };
            var environmentContext = CreateEnvironmentContext(machineDescription, test, steps);

            var activeEnvironment = new Mock<IActiveEnvironment>();
            {
                activeEnvironment.Setup(
                        a => a.Execute(
                            It.IsAny<int>(),
                            It.IsAny<IEnumerable<TestStep>>(),
                            It.IsAny<IEnumerable<InputParameter>>(),
                            It.IsAny<string>()))
                    .Callback<int, IEnumerable<TestStep>, IEnumerable<InputParameter>, string>(
                        (id, s, parameters, file) =>
                        {
                            Assert.AreEqual(test.Id, id);
                            Assert.AreEqual(1, s.Count());
                            Assert.IsInstanceOf(typeof(MsiInstallTestStep), s.First());
                            Assert.AreEqual(1, parameters.Count());

                            var parameter = parameters.First();
                            Assert.AreEqual(environmentName, parameter.Key);
                            Assert.AreEqual(machineDescription.NetworkName, parameter.Value);
                            Assert.False(string.IsNullOrWhiteSpace(file));
                        })
                    .Verifiable();
                activeEnvironment.Setup(a => a.Environment)
                    .Returns("ea");
            }

            var activator = new Mock<IEnvironmentActivator>();
            {
                activator.Setup(a => a.EnvironmentTypeToLoad)
                    .Returns(typeof(PhysicalMachineDescription));
                activator.Setup(a => a.Load(It.IsAny<MachineDescription>(), It.IsAny<ITestSectionBuilder>(), It.IsAny<Action<string>>()))
                    .Returns(activeEnvironment.Object);
            }

            var activators = new List<IEnvironmentActivator>
                {
                    activator.Object,
                };

            var environmentPackage = new Mock<ITestEnvironmentPackage>();
            {
                environmentPackage.Setup(e => e.PackagePath)
                    .Returns("a");
            }

            var suitePackage = new Mock<ITestSuitePackage>();
            {
                suitePackage.Setup(s => s.Environment(It.IsAny<string>()))
                    .Returns(environmentPackage.Object);
            }

            Func<ITestSuitePackage> packageFunc = () => suitePackage.Object;
            var fileSystem = new Mock<IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                    .Returns(new MockPath());
            }

            Func<IReportBuilder> reportBuilders = () => new Mock<IReportBuilder>().Object;
            Func<string, IReportBuilder, ITestSectionBuilder> sectionBuilders = (s, b) => new Mock<ITestSectionBuilder>().Object;
            var controller = new TestController(
                configuration.Object,
                activeTests,
                () => new Owned<IProvideTestingContext>(environmentContext.Object, new MockDisposable()),
                activators,
                packageFunc,
                fileSystem.Object,
                reportBuilders,
                sectionBuilders,
                diagnostics);
            controller.ActivateTests();
            Assert.AreEqual(1, activeTests.Count());
            activeEnvironment.Verify(
                a => a.Execute(
                    It.IsAny<int>(),
                    It.IsAny<IEnumerable<TestStep>>(),
                    It.IsAny<IEnumerable<InputParameter>>(),
                    It.IsAny<string>()),
                Times.Once());
        }
コード例 #9
0
        public void ActivateTestsWithoutTests()
        {
            var configuration = CreateConfiguration();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var activeTests = new ActiveTestStorage(diagnostics);

            var environmentPackage = new Mock<ITestEnvironmentPackage>();
            {
                environmentPackage.Setup(e => e.PackagePath)
                    .Returns("a");
            }

            var suitePackage = new Mock<ITestSuitePackage>();
            {
                suitePackage.Setup(s => s.Environment(It.IsAny<string>()))
                    .Returns(environmentPackage.Object);
            }

            Func<ITestSuitePackage> packageFunc = () => suitePackage.Object;

            var environmentContext = new Mock<IProvideTestingContext>();
            {
                environmentContext.Setup(
                    e => e.InactiveMachinesWith(
                        It.IsAny<OperatingSystemDescription>(),
                        It.IsAny<IEnumerable<ApplicationDescription>>()))
                    .Returns(
                        new List<MachineDescription>
                            {
                                new PhysicalMachineDescription
                                    {
                                        Id = "a-b",
                                        Name = "a",
                                        Description = "b",
                                        MacAddress = "c",
                                        NetworkName = "d",
                                        OperatingSystemId = 0,
                                        IsAvailableForTesting = true,
                                        CanStartRemotely = false,
                                    }
                            });
                environmentContext.Setup(e => e.InactiveTests())
                    .Returns(new List<Shared.DataAccess.Test>());
            }

            var activeEnvironment = new Mock<IActiveEnvironment>();
            var activator = new Mock<IEnvironmentActivator>();
            {
                activator.Setup(a => a.Load(It.IsAny<MachineDescription>(), It.IsAny<ITestSectionBuilder>(), It.IsAny<Action<string>>()))
                    .Returns(activeEnvironment.Object);
            }

            var activators = new List<IEnvironmentActivator>
                {
                    activator.Object,
                };
            var fileSystem = new Mock<IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                    .Returns(new MockPath());
            }

            Func<IReportBuilder> reportBuilders = () => new Mock<IReportBuilder>().Object;
            Func<string, IReportBuilder, ITestSectionBuilder> sectionBuilders = (s, b) => new Mock<ITestSectionBuilder>().Object;

            var controller = new TestController(
                configuration.Object,
                activeTests,
                () => new Owned<IProvideTestingContext>(environmentContext.Object, new MockDisposable()),
                activators,
                packageFunc,
                fileSystem.Object,
                reportBuilders,
                sectionBuilders,
                diagnostics);
            controller.ActivateTests();
            Assert.AreEqual(0, activeTests.Count());
        }