コード例 #1
0
        public void Activate()
        {
            var contract = "a";
            var specification = new MockEnvironmentSpecification(
                new EnvironmentId("e"),
                "a",
                "b",
                "c",
                true,
                true,
                "d",
                "e",
                new OperatingSystemSpecification("f", "g", CultureInfo.InvariantCulture, 64),
                new List<ApplicationSpecification>());
            var activeEnvironment = new Mock<IActiveEnvironment>();
            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var activator = new Mock<IEnvironmentActivator>();
            {
                activator.Setup(a => a.EnvironmentContractToLoad)
                    .Returns(contract);
                activator.Setup(
                        a => a.Load(
                            It.IsAny<MachineEnvironmentSpecification>(),
                            It.IsAny<ITestSectionBuilder>(),
                            It.IsAny<Action<EnvironmentId>>()))
                    .Callback<MachineEnvironmentSpecification, ITestSectionBuilder, Action<EnvironmentId>>(
                        (e, t, a) =>
                        {
                            Assert.AreSame(specification, e);
                            Assert.IsNotNull(t);
                            Assert.IsNotNull(a);
                        })
                    .Returns(activeEnvironment.Object);
            }

            var controller = new EnvironmentController(
                new List<MachineEnvironmentSpecification>
                    {
                        specification,
                    },
                new List<IEnvironmentActivator>
                    {
                        activator.Object,
                    });

            var environment = controller.Activate(specification.Id, sectionBuilder.Object);
            Assert.AreSame(activeEnvironment.Object, environment);

            Assert.AreEqual(0, controller.CurrentlyInActive().Count());
            Assert.AreEqual(1, controller.CurrentlyActive().Count());
            Assert.AreSame(specification.Id, controller.CurrentlyActive().First());
        }
コード例 #2
0
        public void ActivateWithMissingActivator()
        {
            var specification = new MockEnvironmentSpecification(
                new EnvironmentId("e"),
                "a",
                "b",
                "c",
                true,
                true,
                "d",
                "e",
                new OperatingSystemSpecification("f", "g", CultureInfo.InvariantCulture, 64),
                new List<ApplicationSpecification>());

            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var controller = new EnvironmentController(
                new List<MachineEnvironmentSpecification>
                    {
                        specification,
                    },
                new List<IEnvironmentActivator>());

            Assert.Throws<ArgumentException>(() => controller.Activate(specification.Id, sectionBuilder.Object));
        }