Exemplo n.º 1
0
        public void ScheduleAllRelevantItems_ForExpiration_When_Instantiated()
        {
            //Arrange
            var actionLabel = "NotifyMe!";

            var itemToExpire1 = new Items
            {
                Label      = actionLabel,
                Expiration = DateTime.Now.AddDays(-1),
                ItemType   = 1
            };
            var itemToExpire2 = new Items {
                Label = "Also Notify Me!", Expiration = DateTime.Now.AddDays(1), ItemType = 1
            };
            var itemToNotExpire = new Items {
                Label = "Don't Notify Me!", Expiration = DateTime.Now.AddYears(1), ItemType = 1
            };
            var data = new List <Items>
            {
                itemToExpire1,
                itemToExpire2,
                itemToNotExpire
            }.AsQueryable();

            var stExpectedConsoleOut1 = "Item " + itemToExpire1.Label + " expired at ";
            var stExpectedConsoleOut2 = "Item " + itemToExpire2.Label + " expired at ";

            var mockContext   = SetUpContext(data);
            var TimersDict    = new Dictionary <string, Timer>();
            var loggerFactory = new TestLoggerFactory();

            //Action
            var mockMonitor = SetUpMonitor(mockContext, loggerFactory);

            //Assert
            Assert.DoesNotContain(stExpectedConsoleOut1, loggerFactory.Logger.Message);
            Assert.Contains(stExpectedConsoleOut2, loggerFactory.Logger.Message);
            Assert.DoesNotContain(itemToNotExpire.Label, loggerFactory.Logger.Message);
            Assert.Equal(2, mockContext.Items.Count());
        }
Exemplo n.º 2
0
        public void ScheduleATask_ToWriteToConsole_When_ScheduleExpiration_IsCalled()
        {
            //Arrange
            var actionLabel = "NotifyMe!";

            var itemToExpire = new Items
            {
                Label      = actionLabel,
                Expiration = DateTime.Now.AddDays(-1),
                ItemType   = 1
            };
            var itemToNotExpire = new Items {
                Label = "Don't Notify Me!", Expiration = DateTime.Now.AddYears(1), ItemType = 1
            };
            var data = new List <Items>
            {
                itemToExpire,
                itemToNotExpire
            }.AsQueryable();

            var stExpectedConsoleOut = "Item " + itemToExpire.Label + " expired at ";


            var mockContext   = SetUpContext(data);
            var TimersDict    = new Dictionary <string, Timer>();
            var loggerFactory = new TestLoggerFactory();
            var mockMonitor   = SetUpMonitor(mockContext, loggerFactory);

            //Action
            mockMonitor.ScheduleExpiration(itemToExpire);
            mockMonitor.ScheduleExpiration(itemToNotExpire);

            //Assert
            Assert.True(mockMonitor.TimerReferences.ContainsKey(itemToExpire.Label));
            Assert.Contains(stExpectedConsoleOut, loggerFactory.Logger.Message);
            Assert.DoesNotContain(itemToNotExpire.Label, loggerFactory.Logger.Message);
            Assert.Equal(1, mockContext.Items.Count());
        }