Beispiel #1
0
        public void GetterOfNow_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PDateTime.NowGet().Body = () => new DateTime(2014, 02, 14, 11, 30, 55, 00);

                // Act
                var actual = DateTime.Now;

                // Assert
                Assert.AreEqual(new DateTime(2014, 02, 14, 11, 30, 55, 00), actual);
            }
        }
Beispiel #2
0
        public void IsNowLunchBreak_should_return_false_when_13_oclock()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PDateTime.NowGet().Body = () => new DateTime(2013, 12, 13, 13, 00, 00);

                // Act
                var result = LifeInfo.IsNowLunchBreak();

                // Assert
                Assert.IsFalse(result);
            }
        }
        public void IsNowLunchBreak_should_return_false_when_11_oclock()
        {
            // `IndirectionsContext` can minimize the influence of the API replacement.
            using (new IndirectionsContext())
            {
                // Arrange
                // Replace `DateTime.Now` body. Hereafter, `DateTime.Now` will return only `2013/12/13 11:00:00`.
                PDateTime.NowGet().Body = () => new DateTime(2013, 12, 13, 11, 00, 00);

                // Act
                var result = LifeInfo.IsNowLunchBreak();

                // Assert
                Assert.IsFalse(result);
            }
        }
        public void MSCorLib_something_that_is_in_another_AppDomain_should_be_callable_indirectly()
        {
            AppDomain.CurrentDomain.RunAtIsolatedDomain(() =>
            {
                using (new IndirectionsContext())
                {
                    // Arrange
                    PDateTime.NowGet().Body = () => new DateTime(2013, 12, 13, 12, 00, 00);

                    // Act
                    var result = DateTime.Now;

                    // Assert
                    Assert.AreEqual(new DateTime(2013, 12, 13, 12, 00, 00), result);
                }
            });
        }
Beispiel #5
0
        public void GetterOfNow_should_be_callable_originally_any_time()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var count = 0;
                PDateTime.NowGet().Body = () =>
                {
                    if (5 <= ++count)
                    {
                        return(new DateTime(2013, 12, 23, 11, 22, 33, 44));
                    }
                    else
                    {
                        return(IndirectionsContext.ExecuteOriginal(() => DateTime.Now));
                    }
                };

                // Act
                var actuals = new List <DateTime>();
                actuals.Add(DateTime.Now);
                actuals.Add(DateTime.Now);
                actuals.Add(DateTime.Now);
                actuals.Add(DateTime.Now);
                actuals.Add(DateTime.Now);
                actuals.Add(DateTime.Now);

                // Assert
                var indirectValue = new DateTime(2013, 12, 23, 11, 22, 33, 44);
                Assert.AreNotEqual(indirectValue, actuals[0]);
                Assert.AreNotEqual(indirectValue, actuals[1]);
                Assert.AreNotEqual(indirectValue, actuals[2]);
                Assert.AreNotEqual(indirectValue, actuals[3]);
                Assert.AreEqual(indirectValue, actuals[4]);
                Assert.AreEqual(indirectValue, actuals[5]);
            }
        }