Example #1
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());
        }
Example #2
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));
        }
Example #3
0
        public void GivenCreate_WhenFactoryFunc_ReturnsSimulationBuilderForSimulationEnvironment_Test()
        {
            var builder = SimulationBuilder.Create(() => new SimulationEnvironment());

            Assert.IsType <SimulationBuilder <SimulationEnvironment> >(builder);
        }
Example #4
0
 public void GivenCreate_WhenNullFactory_ThenThrows_Test()
 {
     Assert.Throws <ArgumentNullException>(() => SimulationBuilder.Create((Func <SimulationEnvironment>)null));
 }
Example #5
0
        public void GivenSimulateAsyncWithNumberOfSimulations_WhenNegativeNumberOfSimulations_ThenThrows_Test()
        {
            var builder = SimulationBuilder.Create();

            Assert.Throws <ArgumentOutOfRangeException>(() => builder.SimulateAsync(TimeSpan.Zero, -1));
        }
Example #6
0
        public void GivenSimulateAsync_WhenNegativeDuration_ThenThrows_Test()
        {
            var builder = SimulationBuilder.Create();

            Assert.Throws <ArgumentOutOfRangeException>(() => builder.SimulateAsync(TimeSpan.FromSeconds(-1)));
        }
Example #7
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()));
 }
Example #8
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));
 }