/// <summary>
        /// Returns a task that runs a simulation until the specified time.
        /// </summary>
        /// <param name="builder">
        /// The <see cref="SimulationBuilder{TSimulationEnvironment}"/>.
        /// </param>
        /// <param name="until">
        /// The time until which to run the simulation.
        /// </param>
        /// <returns>
        /// A task that runs the simulation and returns the simulation result.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="builder"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when <paramref name="until"/> is less than <see cref="TimeSpan.Zero"/>.
        /// </exception>
        public static Task <SimulationResult <TSimulationEnvironment> > SimulateAsync <TSimulationEnvironment>(
            this SimulationBuilder <TSimulationEnvironment> builder,
            TimeSpan until)
            where TSimulationEnvironment : SimulationEnvironment
        {
            Guard.IsNotNull(builder, "builder");
            Guard.IsInRange(until >= TimeSpan.Zero, "at");

            return(Task.Run(() => builder.Simulate(until)));
        }
Ejemplo n.º 2
0
        public void GivenSimulateAsync_WhenSimulationBuilderAndDuration_ThenReturnsTaskThatRunsSimulation_Test()
        {
            var duration = TimeSpan.FromSeconds(1);
            var process  = new Mock <Process>();

            var result = SimulationBuilder.Create()
                         .Activate(() => process.Object)
                         .SimulateAsync(duration)
                         .Result;

            Assert.NotNull(result);
            process.Verify(x => x.Execute(It.IsAny <SimulationEnvironment>()), Times.Once());
        }
Ejemplo n.º 3
0
        public void GivenSimulateAsyncWithNumberOfSimulations_WhenSimulationBuilderAndDuration_ThenReturnsTasksThatRunsSimulations_Test()
        {
            var duration            = TimeSpan.FromSeconds(1);
            var process             = new Mock <Process>();
            var expectedSimulations = 10;

            var results = SimulationBuilder.Create()
                          .Activate(() => process.Object)
                          .SimulateAsync(duration, expectedSimulations)
                          .Result
                          .ToList();

            Assert.Equal(expectedSimulations, results.Count);
            process.Verify(x => x.Execute(It.IsAny <SimulationEnvironment>()), Times.Exactly(expectedSimulations));
        }
Ejemplo n.º 4
0
        public void GivenCreate_WhenFactoryFunc_ReturnsSimulationBuilderForSimulationEnvironment_Test()
        {
            var builder = SimulationBuilder.Create(() => new SimulationEnvironment());

            Assert.IsType <SimulationBuilder <SimulationEnvironment> >(builder);
        }
Ejemplo n.º 5
0
 public void GivenCreate_WhenNullFactory_ThenThrows_Test()
 {
     Assert.Throws <ArgumentNullException>(() => SimulationBuilder.Create((Func <SimulationEnvironment>)null));
 }
Ejemplo n.º 6
0
        public void GivenSimulateAsyncWithNumberOfSimulations_WhenNegativeNumberOfSimulations_ThenThrows_Test()
        {
            var builder = SimulationBuilder.Create();

            Assert.Throws <ArgumentOutOfRangeException>(() => builder.SimulateAsync(TimeSpan.Zero, -1));
        }
Ejemplo n.º 7
0
        public void GivenSimulateAsync_WhenNegativeDuration_ThenThrows_Test()
        {
            var builder = SimulationBuilder.Create();

            Assert.Throws <ArgumentOutOfRangeException>(() => builder.SimulateAsync(TimeSpan.FromSeconds(-1)));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new <see cref="SimulationBuilder"/> for a <see cref="SimulationEnvironment"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="SimulationBuilder{SimulationEnvironment}"/>.
 /// </returns>
 public static SimulationBuilder <SimulationEnvironment> Create()
 {
     return(SimulationBuilder <SimulationEnvironment> .Create(() => new SimulationEnvironment()));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new <see cref="SimulationBuilder"/>.
 /// </summary>
 /// <param name="factory">
 /// A factory function that creates a new <see cref="SimulationEnvironment"/>.
 /// </param>
 /// <returns>
 /// A <see cref="SimulationBuilder"/>.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">
 /// Thrown when <paramref name="factory"/> is <see langword="null"/>.
 /// </exception>
 public static SimulationBuilder <TSimulationEnvironment> Create <TSimulationEnvironment>(
     Func <TSimulationEnvironment> factory)
     where TSimulationEnvironment : SimulationEnvironment
 {
     return(SimulationBuilder <TSimulationEnvironment> .Create(factory));
 }