Esempio n. 1
0
        public void The_Controller_Should_Be_Able_To_Save_The_Runtime_To_Db()
        {
            RuntimeController runtimeCtrl = null;
            CheckpointModel checkpoint = null;

            int runtime = 360000000; // Runtime, in milliseconds. Equals 100 hours.
            ContentResult webResponse = null;

            Given("we have a timer and the time keeper wants to save a runtime", () =>
            {
                checkpoint = new CheckpointModel("TheRuntimeCheckpoint", timer, race);
                checkpoint = new CheckpointModel("TheRuntimeCheckpoint", timer, race);
                checkpoint.Sortorder = 1;
            });

            When("the time keeper saves the runtime", () =>
            {
                runtimeCtrl = new RuntimeController();
                webResponse = (ContentResult)runtimeCtrl.Save(runtime.ToString(), checkpoint.Id.ToString());
            });

            Then("the runtime should be saved in the database", () =>
            {
                int runtimeId = Int32.Parse(webResponse.Content);
                RuntimeModel runtimeStoredInDb = RuntimeModel.getById(runtimeId);
                runtimeStoredInDb.Runtime.ShouldBe(runtime);
            });
        }
Esempio n. 2
0
        public void RuntimeControllerReturnsNodeVersions()
        {
            // Arrange
            var nodeDir = new Mock <DirectoryInfoBase>();

            nodeDir.Setup(d => d.Exists).Returns(true);
            nodeDir.Setup(d => d.GetDirectories()).Returns(new[] {
                CreateDirectory("0.8.19", CreateFile("npm.txt", "1.2.8")),
                CreateDirectory("0.10.5", CreateFile("npm.txt", "1.3.11")),
                CreateDirectory("0.10.18"),
                CreateDirectory("node_modules"),
                CreateDirectory("docs")
            });
            var directoryInfo = new Mock <IDirectoryInfoFactory>();

            directoryInfo.Setup(d => d.FromDirectoryName(_nodeDir)).Returns(nodeDir.Object);
            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(f => f.DirectoryInfo).Returns(directoryInfo.Object);
            FileSystemHelpers.Instance = fileSystem.Object;
            var controller = new RuntimeController(Mock.Of <ITracer>());

            // Act
            var nodeVersions = controller.GetRuntimeVersions().NodeVersions.ToList();

            // Assert
            Assert.Equal(new[] { "0.8.19", "0.10.5", "0.10.18" }, nodeVersions.Select(v => v["version"]));
            Assert.Equal(new[] { "1.2.8", "1.3.11", null }, nodeVersions.Select(v => v["npm"]));
        }
Esempio n. 3
0
        public void RuntimeControllerReturnsDotNetCoreVersions()
        {
            // Arrange
            var coreRuntimeDir = new Mock <DirectoryInfoBase>();

            coreRuntimeDir.Setup(d => d.Exists).Returns(true);
            coreRuntimeDir.Setup(d => d.GetDirectories()).Returns(new[] {
                CreateDirectory("2.2.7-alpha2"),
                CreateDirectory("2.2.7-alpha1"),
                CreateDirectory("2.2.7"),
                CreateDirectory("2.2.22"),
                CreateDirectory("1.0.12"),
                CreateDirectory("1.1.9"),
                CreateDirectory("1.1.12"),
                CreateDirectory("2.1.6"),
                CreateDirectory("ignore_me")
            });
            var coreSdkDir = new Mock <DirectoryInfoBase>();

            coreSdkDir.Setup(d => d.Exists).Returns(true);
            coreSdkDir.Setup(d => d.GetDirectories()).Returns(new[] {
                CreateDirectory("1.1.10"),
                CreateDirectory("2.1.403"),
                CreateDirectory("2.2.0-alpha")
            });
            var nonExistingDir = new Mock <DirectoryInfoBase>();

            nonExistingDir.Setup(d => d.Exists).Returns(false);
            var directoryInfo = new Mock <IDirectoryInfoFactory>();

            directoryInfo.Setup(d => d.FromDirectoryName(_dotNetCoreRuntimeDir)).Returns(coreRuntimeDir.Object);
            directoryInfo.Setup(d => d.FromDirectoryName(_dotNetCoreSdkDir)).Returns(coreSdkDir.Object);
            directoryInfo.Setup(d => d.FromDirectoryName(_nodeDir)).Returns(nonExistingDir.Object);
            var fileSystem = new Mock <IFileSystem>();

            SetupFileSystemWithNoFiles(fileSystem);
            fileSystem.Setup(f => f.DirectoryInfo).Returns(directoryInfo.Object);
            FileSystemHelpers.Instance = fileSystem.Object;
            var controller = new RuntimeController(Mock.Of <ITracer>());

            // Act
            dynamic coreVersions = controller.GetRuntimeVersions().DotNetCore32;
            var     shared       = (DotNetCoreSharedFrameworksInfo)coreVersions.shared;
            IEnumerable <string> sdk32Versions = coreVersions.sdk;

            // Assert
            Assert.Equal(new[] { "1.0.12", "1.1.9", "1.1.12", "2.1.6", "2.2.7-alpha1", "2.2.7-alpha2", "2.2.7", "2.2.22" }, shared.NetCoreApp);
            Assert.Equal(new[] { "1.1.10", "2.1.403", "2.2.0-alpha" }, sdk32Versions.ToArray());
        }
        public void Initialize()
        {
            appConfig         = new AppConfig();
            bootstrapSequence = new Mock <IOperationSequence>();
            clientProcess     = new Mock <IProcess>();
            clientProxy       = new Mock <IClientProxy>();
            currentSession    = new SessionConfiguration();
            currentSettings   = new AppSettings();
            logger            = new Mock <ILogger>();
            messageBox        = new Mock <IMessageBox>();
            nextSession       = new SessionConfiguration();
            nextSettings      = new AppSettings();
            runtimeHost       = new Mock <IRuntimeHost>();
            runtimeWindow     = new Mock <IRuntimeWindow>();
            service           = new Mock <IServiceProxy>();
            sessionContext    = new SessionContext();
            sessionSequence   = new Mock <IRepeatableOperationSequence>();
            shutdown          = new Mock <Action>();
            splashScreen      = new Mock <ISplashScreen>();
            text      = new Mock <IText>();
            uiFactory = new Mock <IUserInterfaceFactory>();

            currentSession.Settings = currentSettings;
            nextSession.Settings    = nextSettings;

            sessionContext.ClientProcess = clientProcess.Object;
            sessionContext.ClientProxy   = clientProxy.Object;
            sessionContext.Current       = currentSession;
            sessionContext.Next          = nextSession;

            uiFactory.Setup(u => u.CreateRuntimeWindow(It.IsAny <AppConfig>())).Returns(new Mock <IRuntimeWindow>().Object);
            uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny <AppConfig>())).Returns(new Mock <ISplashScreen>().Object);

            sut = new RuntimeController(
                appConfig,
                logger.Object,
                messageBox.Object,
                bootstrapSequence.Object,
                sessionSequence.Object,
                runtimeHost.Object,
                runtimeWindow.Object,
                service.Object,
                sessionContext,
                shutdown.Object,
                splashScreen.Object,
                text.Object,
                uiFactory.Object);
        }
Esempio n. 5
0
        public async Task RunBatterySimulation()
        {
            // arrange
            var runtime = new RuntimeController(new EnergyValidator());

            // TODO: seem to have a bug when setting up a higher cutoff voltage --> test and fix it
            _battery.CutoffVoltage = 1.2F;
            var s           = _battery.State;
            var batteryArgs = new BatteryArgs();

            batteryArgs.Batteries.Add(_battery);

            var netArgs = new NetworkArgs();
            var device  = new SimpleDevice();

            device.Parts.Add(_battery);
            netArgs.Network.Add(device);

            var batterySim = new BatteryPackSimulator();

            batterySim
            .With(batteryArgs)
            .With(netArgs)
            .With(runtime.Arguments);

            var repo = new SimulatorRepository();

            repo.Add(batterySim);
            if (!runtime.BindSimulators(repo).Validate())
            {
                Assert.Fail("error on validating the simulation");
            }

            // act
            await runtime.RunAsync((rt) =>
            {
                // assert
                return(!_battery.State.IsDepleted);
            });

            Assert.AreNotEqual(s.Initial.ElapsedTime, s.Now.ElapsedTime, "ElapsedTime should not be equal");
            Assert.AreNotEqual(s.Initial.Charge, s.Now.Charge, "Charge should not be equal");
            Assert.AreNotEqual(s.Initial.SoD, s.Now.SoD, "SoD should not be equal");
            Assert.AreNotEqual(s.Initial.Voltage, s.Now.Voltage, "Voltage should not be equal");
            Assert.IsTrue(_battery.State.IsDepleted, "battery should be empty");
        }
Esempio n. 6
0
        public void RuntimeControllerReturnsEmptyListIfDirectoryDoesNotExist()
        {
            // Arrange
            var nodeDir = new Mock <DirectoryInfoBase>();

            nodeDir.Setup(d => d.Exists).Returns(false);
            var directory = new Mock <IDirectoryInfoFactory>();

            directory.Setup(d => d.FromDirectoryName(_nodeDir)).Returns(nodeDir.Object);
            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(f => f.DirectoryInfo).Returns(directory.Object);
            FileSystemHelpers.Instance = fileSystem.Object;
            var controller = new RuntimeController(Mock.Of <ITracer>());

            // Act
            var runtimeInfo = controller.GetRuntimeVersions();

            // Assert
            Assert.Empty(runtimeInfo.NodeVersions);
        }
Esempio n. 7
0
        public RuntimeController GetRuntime()
        {
            var runtime = new RuntimeController(new D3vS1mValidator());

            return(runtime);
        }
Esempio n. 8
0
        public async Task RunNetwork()
        {
            // arrange
            var runtime = new RuntimeController(new BasicValidator());


            var netSim  = new PeerToPeerNetworkSimulator(runtime);
            var netArgs = new NetworkArgs();

            netSim.OnExecuting += (o, e) =>
            {
                _network.AssociationMatrix.Each(ApplyAssociations);
            };
            netSim.With(netArgs);
            _network = netArgs.Network;
            _network.AddRange(ImportDevices().First());

            var simRepo = new SimulatorRepository();

            simRepo.Add(netSim);


            var pass      = 0;
            var maxPasses = 3;

            runtime.IterationPassed += (o, e) =>
            {
                pass++;
                if (pass == maxPasses)
                {
                    var dev = netArgs.Network.Items[0];
                    dev.Controls.Off();
                    _log.Trace($"Device '{dev.Name}' was turned off.");
                }
            };
            runtime.BindSimulators(simRepo)
            .Validate();

            // act iterations until availability is below 100%
            await runtime.RunAsync((r) =>
            {
                if (netArgs.Network.Availability() < 1)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            });

            // assert
            Assert.IsTrue(pass >= maxPasses, $"The iterations should be more than {maxPasses}.");
            netArgs.Network.DistanceMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(v > 0, $"position at row '{r}' and col '{c}' should not be '{v}'");
                _log.Trace($"{r}:{c} -> distance: {v}");
                return(v);
            });

            netArgs.Network.AngleMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(!float.IsNaN(v.Azimuth), $"Azimuth at position at row '{r}' and col '{c}' should not be NaN");
                Assert.IsTrue(!float.IsNaN(v.Elevation), $"Elevation at position at row '{r}' and col '{c}' should not be NaN");
                _log.Trace($"{r}:{c} -> angle: {v}");
                return(v);
            });
        }