Ejemplo n.º 1
0
        public async Task GetAll_WhenAnEntityOfDifferentTypeAreAdded_ThenAllCanBeRetrieved()
        {
            // arrange
            var type1Entities = new[]
            { new TestCompany {
                  Name = "test1_1", Id = "1"
              }, new TestCompany {
                  Name = "test1_2", Id = "2"
              } };
            var type2Entities = new[]
            { new TestPerson {
                  FirstName = "test2_1", Id = "1"
              }, new TestPerson {
                  FirstName = "test2_2", Id = "2"
              } };

            await _cacheType1.AddOrUpdateAsync(type1Entities.First());

            await _cacheType1.AddOrUpdateAsync(type1Entities.Last());

            await _cacheType2.AddOrUpdateAsync(type2Entities.First());

            await _cacheType2.AddOrUpdateAsync(type2Entities.Last());

            // act
            var retrievedAllType1Entities = (await _cacheType1.GetAllAsync()).ToArray();
            var retrievedAllType2Entities = (await _cacheType2.GetAllAsync()).ToArray();

            // assert
            Assert.That(retrievedAllType1Entities, Has.Length.EqualTo(2));
            Assert.That(retrievedAllType2Entities, Has.Length.EqualTo(2));
            Assert.That(retrievedAllType1Entities, Is.EquivalentTo(type1Entities));
            Assert.That(retrievedAllType2Entities, Is.EquivalentTo(type2Entities));
        }
Ejemplo n.º 2
0
        public async Task Set_GivenEmptyStoreAndExpiryIs1Second_WhenFetchingAfter1Second_ThenItemsSetCannotBeRetrieved()
        {
            // arrange
            var load = TestType1Entities.Take(5).ToArray();

            // act
            await _cacheType1WithExpiry.SetAsync(load);

            // assert
            var immediateItems = (await _cacheType1WithExpiry.GetAllAsync()).ToArray();

            await Task.Delay(1500);

            var delayedItems = (await _cacheType1WithExpiry.GetAllAsync()).ToArray();

            Assert.That(immediateItems, Is.EquivalentTo(load));
            Assert.That(delayedItems, Is.Empty);
        }
Ejemplo n.º 3
0
        public async Task AddOrUpdate_WhenTheSameKeyIsAddedTwice_ThenItIsAddedThenUpdated()
        {
            // arrange
            var firstEntity  = TestCompany.Apple;
            var secondEntity = TestCompany.Apple;

            secondEntity.Id = firstEntity.Id;

            // act
            await _cacheType1.AddOrUpdateAsync(firstEntity);

            await _cacheType1.AddOrUpdateAsync(secondEntity);

            var retrievedAllEntities = (await _cacheType1.GetAllAsync()).ToArray();
            var retrievedEntity      = await _cacheType1.GetAsync(firstEntity.Id);

            // assert
            Assert.That(retrievedEntity, Is.EqualTo(firstEntity));    // name updated properly
            Assert.That(retrievedAllEntities, Has.Length.EqualTo(1)); // no duplicate
        }