示例#1
0
        public void TestNoPoint()
        {
            var      systemTime = new Mock <ISystemTime>();
            DateTime fakeTime   = DateTime.Now;

            systemTime.Setup(x => x.UtcNow).Returns(() => fakeTime);

            Availability availability = new Availability("Test", systemTime.Object);

            for (int j = 0; j < 100; j++)
            {
                availability.AddPoint(true);
                fakeTime = fakeTime.AddMinutes(10);
            }

            for (int j = 0; j < 100; j++)
            {
                availability.NoPoint();
                fakeTime = fakeTime.AddMinutes(10);
            }

            for (int j = 0; j < 100; j++)
            {
                availability.AddPoint(false);
                fakeTime = fakeTime.AddMinutes(10);
            }

            // Note approx equal since we lose a bit of information when no point is measured
            TestUtilities.ApproxEqual(TimeSpan.FromMinutes(2000).TotalDays, availability.ExpectedTime.TotalDays, .1);
            TestUtilities.ApproxEqual(TimeSpan.FromMinutes(1000).TotalDays, availability.RunningTime.TotalDays, .1);
        }
示例#2
0
        public void TestAddPoint()
        {
            var      systemTime = new Mock <ISystemTime>();
            DateTime fakeTime   = DateTime.Now;

            systemTime.Setup(x => x.UtcNow).Returns(() => fakeTime);

            for (int i = 1; i < 100; i++)
            {
                Availability availability = new Availability("Test", systemTime.Object);
                fakeTime = fakeTime.AddMinutes(10);

                for (int j = 0; j < 100; j++)
                {
                    availability.AddPoint(j % i == 0);
                    fakeTime = fakeTime.AddMinutes(10);
                }

                Assert.Equal(TimeSpan.FromMinutes(1000), availability.ExpectedTime);
                Assert.Equal(TimeSpan.FromMinutes(Math.Ceiling(100.0 / i) * 10), availability.RunningTime);
            }
        }