public MapSeeder(IMap map, IServiceProvider serviceProvider, GameObjectsCreationEvent gameObjectsCreationEvent, IEventRecorder eventRecorder) { _map = map; _serviceProvider = serviceProvider; _gameObjectsCreationEvent = gameObjectsCreationEvent; _eventRecorder = eventRecorder; }
/// <summary> /// Asserts that at least one occurrence of the event had arguments matching all predicates. /// </summary> public static IEventRecorder WithArgs <T>(this IEventRecorder eventRecorder, params Expression <Func <T, bool> >[] predicates) { Func <T, bool>[] compiledPredicates = predicates.Select(p => p?.Compile()).ToArray(); if (!eventRecorder.First().Parameters.OfType <T>().Any()) { throw new ArgumentException("No argument of event " + eventRecorder.EventName + " is of type <" + typeof(T) + ">."); } bool expected = eventRecorder.Any(recordedEvent => { T[] parameters = recordedEvent.Parameters.OfType <T>().ToArray(); int parametersToCheck = Math.Min(parameters.Length, predicates.Length); bool isMatch = true; for (int i = 0; i < parametersToCheck && isMatch; i++) { isMatch = compiledPredicates[i]?.Invoke(parameters[i]) ?? true; } return(isMatch); }); if (!expected) { Execute.Assertion .FailWith("Expected at least one event with arguments matching {0}, but found none.", string.Join(" | ", predicates.Where(p => p != null).Select(p => p.Body.ToString()))); } return(eventRecorder); }
public EaterImpl(ILoggerFactory loggerFactory, EatingEvent eatingEvent, IEventRecorder recorder) { _logger = loggerFactory.CreateLogger <EaterImpl>(); _stringBuilder = new StringBuilder(); _eatingEvent = eatingEvent; _eventRecorder = recorder; }
public MaleImpl(ILoggerFactory loggerFactory, ReproductionEvent reproductionEvent, IEventRecorder eventRecorder) { _reproductionEvent = reproductionEvent; _eventRecorder = eventRecorder; _logger = loggerFactory.CreateLogger <MaleImpl>(); _stringBuilder = new StringBuilder(); }
public MovableImpl(ILoggerFactory loggerFactory, MovementEvent movementEvent, IEventRecorder eventRecorder) { _movementEvent = movementEvent; _eventRecorder = eventRecorder; _logger = loggerFactory.CreateLogger <MovableImpl>(); _stringBuilder = new StringBuilder(); }
/// <summary> /// Generates an eventhandler for an event of type eventSignature that calls RegisterEvent on recorder /// when invoked. /// </summary> public static Delegate GenerateHandler(Type eventSignature, IEventRecorder recorder) { Type returnType = GetDelegateReturnType(eventSignature); Type[] parameters = GetDelegateParameterTypes(eventSignature); var eventHandler = new DynamicMethod( eventSignature.Name + "DynamicHandler", returnType, AppendParameterListThisReference(parameters), recorder.GetType() .Module); MethodInfo methodToCall = typeof(IEventRecorder).GetMethod("RecordEvent", BindingFlags.Instance | BindingFlags.Public); ILGenerator ilGen = eventHandler.GetILGenerator(); // Make room for the one and only local variable in our function ilGen.DeclareLocal(typeof(object[])); // Create the object array for the parameters and store in local var index 0 ilGen.Emit(OpCodes.Ldc_I4, parameters.Length); ilGen.Emit(OpCodes.Newarr, typeof(Object)); ilGen.Emit(OpCodes.Stloc_0); for (var index = 0; index < parameters.Length; index++) { // Push the object array onto the evaluation stack ilGen.Emit(OpCodes.Ldloc_0); // Push the array index to store our parameter in onto the evaluation stack ilGen.Emit(OpCodes.Ldc_I4, index); // Load the parameter ilGen.Emit(OpCodes.Ldarg, index + 1); // Box value-type parameters if (parameters[index] .IsValueType) { ilGen.Emit(OpCodes.Box, parameters[index]); } // Store the parameter in the object array ilGen.Emit(OpCodes.Stelem_Ref); } // Push the this-reference on the stack as param 0 for calling the handler ilGen.Emit(OpCodes.Ldarg_0); // Push the object array onto the stack as param 1 for calling the handler ilGen.Emit(OpCodes.Ldloc_0); // Call the handler ilGen.EmitCall(OpCodes.Call, methodToCall, null); ilGen.Emit(OpCodes.Ret); return(eventHandler.CreateDelegate(eventSignature, recorder)); }
/// <summary> /// Generates an eventhandler for an event of type eventSignature that calls RegisterEvent on recorder /// when invoked. /// </summary> public static Delegate GenerateHandler(Type eventSignature, IEventRecorder recorder) { Type returnType = GetDelegateReturnType(eventSignature); Type[] parameters = GetDelegateParameterTypes(eventSignature); var eventHandler = new DynamicMethod( eventSignature.Name + "DynamicHandler", returnType, AppendParameterListThisReference(parameters), recorder.GetType() .Module); MethodInfo methodToCall = typeof (IEventRecorder).GetMethod("RecordEvent", BindingFlags.Instance | BindingFlags.Public); ILGenerator ilGen = eventHandler.GetILGenerator(); // Make room for the one and only local variable in our function ilGen.DeclareLocal(typeof (object[])); // Create the object array for the parameters and store in local var index 0 ilGen.Emit(OpCodes.Ldc_I4, parameters.Length); ilGen.Emit(OpCodes.Newarr, typeof (Object)); ilGen.Emit(OpCodes.Stloc_0); for (var index = 0; index < parameters.Length; index++) { // Push the object array onto the evaluation stack ilGen.Emit(OpCodes.Ldloc_0); // Push the array index to store our parameter in onto the evaluation stack ilGen.Emit(OpCodes.Ldc_I4, index); // Load the parameter ilGen.Emit(OpCodes.Ldarg, index + 1); // Box value-type parameters if (parameters[index] .IsValueType) { ilGen.Emit(OpCodes.Box, parameters[index]); } // Store the parameter in the object array ilGen.Emit(OpCodes.Stelem_Ref); } // Push the this-reference on the stack as param 0 for calling the handler ilGen.Emit(OpCodes.Ldarg_0); // Push the object array onto the stack as param 1 for calling the handler ilGen.Emit(OpCodes.Ldloc_0); // Call the handler ilGen.EmitCall(OpCodes.Call, methodToCall, null); ilGen.Emit(OpCodes.Ret); return eventHandler.CreateDelegate(eventSignature, recorder); }
public Fish(IMap map, IGrowable growable, IMovable movable, IEater eater, IEatable eatable, IGender gender, DeathEvent deathEvent, IEventRecorder eventRecorder) : base(map, growable, movable, eater, gender, deathEvent, eventRecorder) { Hp = 10; _eatable = eatable; _eatable.EatableOwner = this; }
public RacesWorkflow(ICompetitionContext context, IDistanceDisciplineExpertManager expertManager, IEventRecorder recorder) { this.context = context; this.expertManager = expertManager; this.recorder = recorder; context.ProxyCreationEnabled = false; context.LazyLoadingEnabled = false; }
public DistanceDrawingWorkflow(ICompetitionContext context, IDisciplineCalculatorManager calculatorManager, IDistanceDisciplineExpertManager distanceExpertManager, IEventRecorder recorder) { this.context = context; this.calculatorManager = calculatorManager; this.distanceExpertManager = distanceExpertManager; personTimesWorkflow = new PersonTimesWorkflow(context, calculatorManager, distanceExpertManager); distancesWorkflow = new DistancesWorkflow(context, calculatorManager, distanceExpertManager, recorder); }
public KubeResourceStore(IKubernetes client, IEventRecorder eventRecorder, ILogger <KubeResourceStore> logger) { _client = client ?? throw new ArgumentNullException(nameof(client)); _eventRecorder = eventRecorder ?? throw new ArgumentNullException(nameof(eventRecorder)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _backgroundCts = new CancellationTokenSource(); _watchIngressesTask = WatchIngresses(); _watchServicesTask = WatchServices(); _watchEndpointsTask = WatchServiceEndpoints(); }
protected Animal(IMap map, IGrowable growable, IMovable movable, IEater eater, IGender gender, DeathEvent deathEvent, IEventRecorder eventRecorder) : base(map, growable, deathEvent, eventRecorder) { IsPregnant = false; _gender = gender; _gender.GenderOwner = this; _eater = eater; _eater.EaterOwner = this; _movable = movable; _movable.MovableOwner = this; }
/// <summary> /// Asserts that an object has not raised a particular event. /// </summary> /// <param name="eventName"> /// The name of the event that should not be raised. /// </param> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <remarks> /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can /// subscribe for the events of the object. /// </remarks> public void NotRaise(string eventName, string because = "", params object[] becauseArgs) { IEventRecorder eventRecorder = monitor.GetEventRecorder(eventName); if (eventRecorder.Any()) { Execute.Assertion .BecauseOf(because, becauseArgs) .FailWith("Expected object {0} to not raise event {1}{reason}, but it did.", monitor.Subject, eventName); } }
public FemaleImpl(ILoggerFactory loggerFactory, GettingPregnantEvent gettingPregnantEvent, PregnancyProgressionEvent pregnancyProgressionEvent, BirthEvent birthEvent, GameObjectsCreationEvent gameObjectsCreationEvent, IEventRecorder eventRecorder) { _gettingPregnantEvent = gettingPregnantEvent; _pregnancyProgressionEvent = pregnancyProgressionEvent; _birthEvent = birthEvent; _gameObjectsCreationEvent = gameObjectsCreationEvent; _eventRecorder = eventRecorder; _logger = loggerFactory.CreateLogger <FemaleImpl>(); _stringBuilder = new StringBuilder(); }
/// <summary> /// Asserts that an object has not raised a particular event. /// </summary> /// <param name="eventSource">The object exposing the event.</param> /// <param name="eventName"> /// The name of the event that should not be raised. /// </param> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <remarks> /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can /// subscribe for the events of the object. /// </remarks> public static void ShouldNotRaise( this object eventSource, string eventName, string because, params object[] becauseArgs) { IEventRecorder eventRecorder = EventMonitor.Get(eventSource).GetEventRecorder(eventName); if (eventRecorder.Any()) { Execute.Assertion .BecauseOf(because, becauseArgs) .FailWith("Expected object {0} to not raise event {1}{reason}, but it did.", eventSource, eventName); } }
/// <summary> /// Asserts that only one event was raised. /// </summary> /// <param name="eventRecorder">The IEventRecorder to check.</param> /// <returns>The IEventRecorder instance for chaining.</returns> public static IEventRecorder OnlyOnce(this IEventRecorder eventRecorder) { var count = eventRecorder.Count(); if (count != 1) { Execute.Assertion.FailWith( "Expected only 1 event to be raised, but found {0}.", count); } return(eventRecorder); }
public CompetitionsWorkflow(ICompetitionContext context, IDisciplineCalculatorManager calculatorManager, IDistanceDisciplineExpertManager distanceExpertManager, IEventRecorder recorder) { this.context = context; this.calculatorManager = calculatorManager; this.recorder = recorder; this.distanceExpertManager = distanceExpertManager; DistancesWorkflow = new DistancesWorkflow(context, calculatorManager, distanceExpertManager, recorder); DistanceCombinationsWorkflow = new DistanceCombinationsWorkflow(context, recorder); LicensesWorkflow = new LicensesWorkflow(context, calculatorManager, recorder); RacesWorkflow = new RacesWorkflow(context, distanceExpertManager, recorder); }
public SimulatedAppliance(ILogger <BaseAppliance> logger, IHub hub, IThermocouple thermo1, IThermocouple thermo2, IThermocouple thermo3, IThermocouple thermo4, IThermocouple thermo5, IThermocouple thermo6, IThermocouple thermo7, IThermocouple thermo8, IPid pid1, IPid pid2, IPid pid3, ISsr ssr1, ISsr ssr2, IEventRecorder eventRecorder) : base(logger) { _hub = hub; thermocouples.Add(thermo1); thermocouples.Add(thermo2); thermocouples.Add(thermo3); thermocouples.Add(thermo4); thermocouples.Add(thermo5); thermocouples.Add(thermo6); thermocouples.Add(thermo7); thermocouples.Add(thermo8); pids.Add(pid1); pids.Add(pid2); pids.Add(pid3); ssrs.Add(ssr1); ssrs.Add(ssr2); eventRecorders.Add(eventRecorder); Configure(); // This initially starts the process. _hub.Publish <ComponentStateRequest <PidState> >(new ComponentStateRequest <PidState> { Location = Location.HLT, Updates = (state) => { state.SetPoint = Temperature.RoomTemp + 10; state.PidMode = PidMode.Temperature; state.IsEngaged = true; } }); }
public CredentialsOperator(IKubernetes client, ILogger <Operator <CredentialsResource> > logger, IKubernetesService k8sService, DatabaseServerRehydrator rehydrator, IEventRecorder <CredentialsResource> eventRecorder, ISqlManagementService sqlService, SecretSourceRehydrator secretSourceRehydrator) : base(client, logger, 1000, 100, 5) { this.k8sService = k8sService; this.rehydrator = rehydrator; this.eventRecorder = eventRecorder; this.sqlService = sqlService; this.secretSourceRehydrator = secretSourceRehydrator; }
public DatabaseOperator(IKubernetes client, ILogger <Operator <DatabaseResource> > logger, IKubernetesService k8sService, ISqlManagementService sqlService, IEventRecorder <DatabaseResource> eventRecorder, DatabaseServerRehydrator rehydrator) : base(client, logger) { this.k8sService = k8sService; this.sqlService = sqlService; this.eventRecorder = eventRecorder; this.rehydrator = rehydrator; Filters.Add(new IgnoreStatusUpdatesOperatorFilter <DatabaseResource, DatabaseStatus>()); }
/// <summary> /// Asserts that an object has not raised the <see cref="INotifyPropertyChanged.PropertyChanged"/> event for a particular property. /// </summary> /// <param name="propertyExpression"> /// A lambda expression referring to the property for which the property changed event should have been raised. /// </param> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <remarks> /// You must call <see cref="AssertionExtensions.Monitor"/> on the same object prior to this call so that Fluent Assertions can /// subscribe for the events of the object. /// </remarks> public void NotRaisePropertyChangeFor(Expression <Func <T, object> > propertyExpression, string because = "", params object[] becauseArgs) { IEventRecorder eventRecorder = monitor.GetEventRecorder(PropertyChangedEventName); string propertyName = propertyExpression.GetPropertyInfo().Name; if (eventRecorder.Any(@event => GetAffectedPropertyName(@event) == propertyName)) { Execute.Assertion .BecauseOf(because, becauseArgs) .FailWith("Did not expect object {0} to raise the {1} event for property {2}{reason}, but it did.", monitor.Subject, PropertyChangedEventName, propertyName); } }
public DeploymentScriptOperator(IKubernetes client, ILogger <Operator <DeploymentScriptResource> > logger, IKubernetesService k8sService, DatabaseServerRehydrator rehydrator, ISqlManagementService sqlService, IEventRecorder <DeploymentScriptResource> eventRecorder, IMetrics metrics) : base(client, logger, 1000, 100, 5) { this.k8sService = k8sService; this.rehydrator = rehydrator; this.sqlService = sqlService; this.eventRecorder = eventRecorder; Metrics = metrics; Filters.Add(new IgnoreStatusUpdatesOperatorFilter <DeploymentScriptResource, DeploymentScriptStatus>()); }
/// <summary> /// Asserts that an object has raised the <see cref="INotifyPropertyChanged.PropertyChanged"/> event for a particular property. /// </summary> /// <param name="propertyExpression"> /// A lambda expression referring to the property for which the property changed event should have been raised, or /// <c>null</c> to refer to all properties. /// </param> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <remarks> /// You must call <see cref="AssertionExtensions.Monitor"/> on the same object prior to this call so that Fluent Assertions can /// subscribe for the events of the object. /// </remarks> public IEventRecorder RaisePropertyChangeFor(Expression <Func <T, object> > propertyExpression, string because = "", params object[] becauseArgs) { IEventRecorder eventRecorder = monitor.GetEventRecorder(PropertyChangedEventName); string propertyName = propertyExpression?.GetPropertyInfo().Name; if (!eventRecorder.Any()) { Execute.Assertion .BecauseOf(because, becauseArgs) .FailWith("Expected object {0} to raise event {1} for property {2}{reason}, but it did not.", monitor.Subject, PropertyChangedEventName, propertyName); } return(eventRecorder.WithArgs <PropertyChangedEventArgs>(args => args.PropertyName == propertyName)); }
/// <summary> /// Asserts that at least one occurrence of the event had an <see cref="EventArgs"/> object matching a predicate. /// </summary> public static IEventRecorder WithArgs <T>(this IEventRecorder eventRecorder, Expression <Func <T, bool> > predicate) where T : EventArgs { Func <T, bool> compiledPredicate = predicate.Compile(); if (!eventRecorder.First().Parameters.OfType <T>().Any()) { throw new ArgumentException("No argument of event " + eventRecorder.EventName + " is of type <" + typeof(T) + ">."); } if (!eventRecorder.Any(@event => compiledPredicate(@event.Parameters.OfType <T>().Single()))) { Execute.Assertion .FailWith("Expected at least one event with arguments matching {0}, but found none.", predicate.Body); } return(eventRecorder); }
/// <summary> /// Asserts that an object has raised the <see cref="INotifyPropertyChanged.PropertyChanged"/> event for a particular property. /// </summary> /// <param name="eventSource">The object exposing the event.</param> /// <param name="propertyExpression"> /// A lambda expression referring to the property for which the property changed event should have been raised, or /// <c>null</c> to refer to all properties. /// </param> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <remarks> /// You must call <see cref="AssertionExtensions.MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can /// subscribe for the events of the object. /// </remarks> public static IEventRecorder ShouldRaisePropertyChangeFor <T>( this T eventSource, Expression <Func <T, object> > propertyExpression, string because, params object[] becauseArgs) { IEventRecorder eventRecorder = EventMonitor.Get(eventSource).GetEventRecorder(PropertyChangedEventName); string propertyName = (propertyExpression != null) ? propertyExpression.GetPropertyInfo().Name : null; if (!eventRecorder.Any()) { Execute.Assertion .BecauseOf(because, becauseArgs) .FailWith("Expected object {0} to raise event {1} for property {2}{reason}, but it did not.", eventSource, PropertyChangedEventName, propertyName); } return(eventRecorder.WithArgs <PropertyChangedEventArgs>(args => args.PropertyName == propertyName)); }
/// <summary> /// Asserts that all occurences of the event originated from the <param name="expectedSender"/>. /// </summary> public static IEventRecorder WithSender(this IEventRecorder eventRecorder, object expectedSender) { foreach (RecordedEvent recordedEvent in eventRecorder) { if (!recordedEvent.Parameters.Any()) { throw new ArgumentException(string.Format( "Expected event from sender <{0}>, but event {1} does not include any arguments", expectedSender, eventRecorder.EventName)); } object actualSender = recordedEvent.Parameters.First(); Execute.Assertion .ForCondition(ReferenceEquals(actualSender, expectedSender)) .FailWith("Expected sender {0}, but found {1}.", expectedSender, actualSender); } return(eventRecorder); }
public TestClassFake(IEventRecorder record) : base(record) { }
protected TestClass(IEventRecorder eventRecorder) { _eventRecorder = eventRecorder; }
public Sparrow(IMap map, IGrowable growable, IMovable movable, IEater eater, IGender gender, DeathEvent deathEvent, IEventRecorder eventRecorder) : base(map, growable, movable, eater, gender, deathEvent, eventRecorder) { Hp = 10; }
protected Creature(IMap map, IGrowable growable, DeathEvent deathEvent, IEventRecorder eventRecorder) : base(map, deathEvent, eventRecorder) { CurrentAge = 0; _growable = growable; _growable.GrowableOwner = this; }
public MapGenerator(IMap map, MapGenerationEvent mapGenerationEvent, IEventRecorder eventRecorder) { Map = map; _mapGenerationEvent = mapGenerationEvent; _eventRecorder = eventRecorder; }