コード例 #1
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());
        }
コード例 #2
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());
        }
コード例 #3
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());
        }
コード例 #4
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());
        }