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

            Assert.True(result > 0);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void ShouldLazyLoadProperty()
        {
            var model    = new PatternModel();
            var expected = model.RandomInt;
            var value    = model.RandomInt;

            Assert.Equal(expected, value);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
        public void CanSwallowException()
        {
            var model = new PatternModel();

            model.CreateException();
        }
Exemplo n.º 8
0
 public void ShouldNotThrowExceptionInConstructor()
 {
     var model = new PatternModel();
 }