public async Task <TestingModel> CalculateSomethingRandom(int a, int b) { var value = RandomService.GenerateRandomValue(1, 1000); var sleep = await Sleepy.SleepForATime(); if (!sleep) { FactoryException.Create(); } var result = FactoryTestingModel.Empty(); if (value < 250 && value > 0) { result = FactoryTestingModel.Create("Plus", value, a + b); } else if (value < 500 && value >= 250) { result = FactoryTestingModel.Create("Minus 10", value, a + b - 10); } else if (value < 750 && value >= 500) { result = FactoryTestingModel.Create("Plus 10", value, a + b + 10); } else if (value <= 1000 && value >= 750) { result = FactoryTestingModel.Create("Plus 20", value, a + b + 20); } else { FactoryException.Create("Out of range"); } return(await AsyncExecutor.FromResult(result)); }
public void ShouldHandleEventWhenBothReferencesAreAlive() { var alarm = new Alarm(); var sleepy = new Sleepy(alarm); alarm.Beep(); alarm.Beep(); Assert.Equal(2, sleepy.SnoozeCount); }
public void SubscriberShouldNotBeUnsubscribedUntilCollection() { var alarm = new Alarm(); var sleepy = new Sleepy(alarm); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); alarm.Beep(); alarm.Beep(); Assert.Equal(2, sleepy.SnoozeCount); }
public void ShouldAllowSubscriberReferenceToBeCollected() { var alarm = new Alarm(); var sleepyReference = null as WeakReference; new Action(() => { // Run this in a delegate to that the local variable gets garbage collected var sleepy = new Sleepy(alarm); alarm.Beep(); alarm.Beep(); Assert.Equal(2, sleepy.SnoozeCount); sleepyReference = new WeakReference(sleepy); })(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.Null(sleepyReference.Target); }
/// <summary> /// This generates the conditions of the new cow /// </summary> private void GenerateConditions() { //:TODO: add individual variation into fuzzy distributions // Wellness - Physical conditions m_Pain = new Pain(this); m_Sick = new Sick(this); m_Wounded = new Wounded(this); m_Damage = new Damage(this); m_Tired = new Tired(this); m_Hungry = new Hungry(this); m_Thirsty = new Thirsty(this); m_Dead = new Dead(this); // Contentment - Mental conditions m_Anger = new Angry(this); m_Sleepy = new Sleepy(this); m_Scared = new Scared(this); m_Bored = new Bored(this); m_Lonely = new Lonely(this); m_Happy = new Happy(this); m_Eager = new Eager(this); }