Beispiel #1
0
        public void ShouldNotFailWithStackOverflow()
        {
            var model  = new PatternModel();
            var result = Math.Abs(model.Fib(10000000));

            Assert.True(result > 0);
        }
Beispiel #2
0
        public void WillThrowExceptionIfMultipleThreadCallsOneMethod()
        {
            var obj    = new PatternModel();
            var reset  = new ManualResetEvent(false);
            var reset2 = new ManualResetEvent(false);

            var exCount = 0;

            var task = Task.Run(() => {
                obj.AllowsOnlyOneThread(reset, reset2);
            });

            reset2.WaitOne();

            try
            {
                obj.AllowsOnlyOneThread(reset, reset2);
            }
            catch (Exception)
            {
                exCount++;
            }
            finally
            {
                reset.Set();
                reset2.Set();
            }

            Assert.True(exCount > 0);
        }
Beispiel #3
0
        public void ShouldLazyLoadProperty()
        {
            var model    = new PatternModel();
            var expected = model.RandomInt;
            var value    = model.RandomInt;

            Assert.Equal(expected, value);
        }
Beispiel #4
0
        public void WillNotThrowExceptionDueToUnSafeThread()
        {
            int expected = 10;
            var model    = new PatternModel(output);
            var count    = 0;

            Task.WaitAll(ExecuteOnThreads(expected, () => model.NumberThreadUnSafe(ref count)));
            Assert.Equal(expected, count);
        }
Beispiel #5
0
        public void ShouldReplaceDateTimeNow()
        {
            var model    = new PatternModel();
            var expected = DateTime.Parse("12/5/1985");
            var actual   = model.ReplaceDateNow();
            var actual2  = model.ReplaceDateToday();

            Assert.Equal(expected.Month, actual.Month);
            Assert.Equal(expected.Day, actual.Day);
            Assert.Equal(expected.Year, actual.Year);

            Assert.Equal(expected.Month, actual2.Month);
            Assert.Equal(expected.Day, actual2.Day);
            Assert.Equal(expected.Year, actual2.Year);
        }
Beispiel #6
0
        public void WillThrowExceptionIfInstanceIsUsedInDifferentThread()
        {
            var       obj = new PatternModel();
            Exception ex  = null;

            obj.AllowOnlyOneThreadForInstance();

            Task.Run(() => {
                try
                {
                    obj.AllowOnlyOneThreadForInstance();
                }
                catch (Exception e)
                {
                    ex = e;
                }
            }).Wait();

            Assert.NotNull(ex);
        }
Beispiel #7
0
        public void CanSwallowException()
        {
            var model = new PatternModel();

            model.CreateException();
        }
Beispiel #8
0
 public void ShouldNotThrowExceptionInConstructor()
 {
     var model = new PatternModel();
 }