public void MaximumUsageOrderValueIs1()
        {
            // Arrange

            var utcNow   = DateTime.UtcNow;
            var first    = CreateDocumentMetadata(utcNow);
            var metadata = new[] { first };

            var preferences = Mock.Of <IUserPreferences>(u =>
                                                         u.ShowRecentUsage == true);

            var service = new NormalizedUsageOrderService();

            // Act

            service.SetUsageOrder(metadata, preferences);

            // Assert

            Assert.That(first.UsageOrder, Is.Not.GreaterThan(1));
        }
        public void UsageOrderIsCalculatedFromActivatedAtTime()
        {
            // Arrange

            var utcNow = DateTime.UtcNow;

            var first  = CreateDocumentMetadata(utcNow);
            var second = CreateDocumentMetadata(utcNow - TimeSpan.FromSeconds(1));
            var third  = CreateDocumentMetadata(utcNow - TimeSpan.FromSeconds(2));

            var metadata = new[]
            {
                second,
                first,
                third
            };

            var preferences = Mock.Of <IUserPreferences>(u =>
                                                         u.ShowRecentUsage == true);

            var service = new NormalizedUsageOrderService();

            // Act

            service.SetUsageOrder(metadata, preferences);

            // Assert

            var interval = 1 / (double)metadata.Length;

            var expectedFirst  = interval * 3;
            var expectedSecond = interval * 2;
            var expectedThird  = interval * 1;

            Assert.That(first.UsageOrder, Is.EqualTo(expectedFirst));
            Assert.That(second.UsageOrder, Is.EqualTo(expectedSecond));
            Assert.That(third.UsageOrder, Is.EqualTo(expectedThird));
        }
        public void UsageOrderIs1WhenShowRecentUsageIsFalse()
        {
            // Arrange

            var utcNow = DateTime.UtcNow;

            var first  = CreateDocumentMetadata(utcNow);
            var second = CreateDocumentMetadata(utcNow - TimeSpan.FromSeconds(1));
            var third  = CreateDocumentMetadata(utcNow - TimeSpan.FromSeconds(2));

            var metadata = new[]
            {
                second,
                first,
                third
            };

            var service = new NormalizedUsageOrderService();

            var builder     = new UserPreferencesBuilder();
            var preferences = builder.CreateUserPreferences();

            preferences.ShowRecentUsage = false;

            // Act

            service.SetUsageOrder(metadata, preferences);

            // Assert

            const double desiredValue = 1;

            Assert.That(first.UsageOrder, Is.EqualTo(desiredValue));
            Assert.That(second.UsageOrder, Is.EqualTo(desiredValue));
            Assert.That(third.UsageOrder, Is.EqualTo(desiredValue));
        }