public void Update_AddItemsThenUpdateSomeItems_UutOrderIsCorrect()
        {
            List <string>       fakeStrings = FakeUserGenerator.GenerateFakeUsers(10).Keys.ToList();
            List <ICacheHandle> handles     = new List <ICacheHandle>(10);

            var random = new Random();

            for (int i = 0; i < 10; i++)
            {
                _uut.Add(fakeStrings[i], DateTime.Now.AddMinutes(random.Next(20)), out var handle);
                handles.Add(handle);
            }

            // Act

            for (int i = 0; i < 10; i++)
            {
                _uut.Update(handles[i], DateTime.Now.AddMinutes(random.Next(-15, 15)));
            }

            for (int i = 0; i < 10; i++)
            {
                _uut.Update(handles[i], DateTime.Now.AddMinutes(random.Next(-15, 15)));
            }

            // Assert
            for (int i = _uut.Collection.Count - 1; i > 0; i--)
            {
                Assert.That(_uut.Collection[i].Expiration.CompareTo(_uut.Collection[i - 1].Expiration), Is.EqualTo(1)); // Assert that the current item is after the one standing before it
            }
        }
Esempio n. 2
0
        public void TimerExpired_CallsCorrectHandlersForLoggedOutUsers()
        {
            // Arrange

            _fakeUserCache.Confirm(Arg.Any <string>()).Returns(true);

            var handleOneCount = 0;
            var handleTwoCount = 0;

            var usersThatLeave = FakeUserGenerator.GenerateFakeUsers(50).Keys.ToList();

            foreach (var user in usersThatLeave)
            {
                _uut.SubscribeOnLogOut(user, (o, username) => { handleOneCount++; });
            }

            for (int i = 0; i < 25; i++)
            {
                _uut.SubscribeOnLogOut(usersThatLeave[i], ((o, username) => { handleTwoCount++; }));
            }

            // Act
            foreach (var user in usersThatLeave)
            {
                _fakeUserCache.UsersTimedOutEvent += Raise.EventWith(null, new TimedOutUserEventArgs(user));
            }

            Thread.Sleep(500);

            // Assert
            Assert.That(handleOneCount, Is.EqualTo(50));
            Assert.That(handleTwoCount, Is.EqualTo(25));
        }
        public void Add_AddTenRandomStringsWithRandomDateTimes_UutOrderIsCorrect()
        {
            List <string> fakeStrings = FakeUserGenerator.GenerateFakeUsers(10).Keys.ToList();
            var           random      = new Random();

            foreach (var fakeString in fakeStrings)
            {
                _uut.Add(fakeString, DateTime.Now.AddMinutes(random.Next(20)), out var handle);
            }

            for (int i = _uut.Collection.Count - 1; i > 0; i--)
            {
                Assert.That(_uut.Collection[i].Expiration.CompareTo(_uut.Collection[i - 1].Expiration), Is.EqualTo(1)); // Assert that the current item is after the one standing before it
            }
        }
        public void Remove_AddToGetHandleThenRemove_RemovesItem()
        {
            List <string>       fakeStrings = FakeUserGenerator.GenerateFakeUsers(10).Keys.ToList();
            List <ICacheHandle> handles     = new List <ICacheHandle>(15);

            var random = new Random();

            for (int i = 0; i < 10; i++)
            {
                _uut.Add(fakeStrings[i], DateTime.Now.AddMinutes(random.Next(20)), out var handle);
                handles.Add(handle);
            }

            _uut.Remove(handles[4]);

            // Assert
            Assert.That(_uut.Collection.Count(t => t.Item == fakeStrings[4]) == 0);
        }
Esempio n. 5
0
 public void SetUp()
 {
     _fakeTimer = Substitute.For <ITimer>();
     _uut       = new UserCache(_fakeTimer);
     _fakeUsers = FakeUserGenerator.GenerateFakeUsers(50000);
 }