public async Task FetchExistingCacheDocument()
        {
            // Prepare.
            var expectedUser     = this.CreateExpectedCacheUser();
            var expectedCacheKey = $"id/{this.global.EncodeCacheKeyPart(expectedUser.Id)}";

            var userCacheMock = new Mock <ICacheStore <CacheUser> >();

            userCacheMock
            .Setup(u => u.GetAsync(expectedCacheKey, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new Optional <CacheUser>(expectedUser)));

            var userTableMock      = new Mock <IVersionedTable <CacheUser> >();
            var internalUserLoader = this.CreateInternalUserLoader(userCacheMock.Object, userTableMock.Object);

            // Act.
            var actualResource = await internalUserLoader.FetchAsync(expectedUser.Id);

            // Assert.
            Assert.NotNull(actualResource);
            AssertHelpers.HasEqualFieldValues(expectedUser, actualResource.ToCache());

            userCacheMock.Verify(u => u.GetAsync(expectedCacheKey, It.IsAny <CancellationToken>()), Times.Once);
            userTableMock.Verify(u => u.FindLastVersionAsync(It.IsAny <Expression <Func <CacheUser, bool> > >(), It.IsAny <CancellationToken>()), Times.Never);
        }
Exemplo n.º 2
0
        public async Task FetchExistingByOtherField()
        {
            // Prepare.
            var userTable        = this.CreateMongoUserTable();
            var expectedDocument = await this.CreateExpectedDocumentAsync(userTable);

            // Act.
            var actualDocument = await userTable.FindAsync(u => u.Email == expectedDocument.Email);

            // Assert.
            AssertHelpers.HasEqualFieldValues(expectedDocument, actualDocument);
        }
Exemplo n.º 3
0
        public async Task FetchExistingByOtherField()
        {
            // Prepare.
            var redisCaches = await this.CreateRedisCachesAsync();

            var expectedDocument = await this.CreateExpectedDocumentAsync(redisCaches);

            // Act.
            var actualDocument = await redisCaches.Users.GetAsync($"entity/{this.global.EncodeCacheKeyPart(expectedDocument.Entity)}");

            // Assert.
            AssertHelpers.HasEqualFieldValues(expectedDocument, actualDocument.Value);
        }
Exemplo n.º 4
0
        public async Task FetchLastVersion()
        {
            // Prepare.
            var userTable = this.CreateMongoUserTable();
            var expectedDocumentVersion1 = await this.CreateExpectedDocumentAsync(userTable);

            var expectedDocumentVersion2 = await this.CreateExpectedDocumentAsync(userTable, expectedDocumentVersion1.Id, DateTime.UtcNow.AddHours(1));

            // Act.
            var actualDocument = await userTable.FindLastVersionAsync(u => u.Id == expectedDocumentVersion1.Id);

            // Assert.
            AssertHelpers.HasEqualFieldValues(expectedDocumentVersion2, actualDocument);
        }
Exemplo n.º 5
0
        public async Task DontReplaceLastVersionWithOld()
        {
            // Prepare.
            var redisCaches = await this.CreateRedisCachesAsync();

            var expectedDocumentVersion1 = await this.CreateExpectedDocumentAsync(redisCaches);

            var expectedDocumentVersion2 = await this.CreateExpectedDocumentAsync(redisCaches, expectedDocumentVersion1.Id, DateTime.UtcNow.AddHours(-1));

            // Act.
            var actualDocument1 = await redisCaches.Users.GetAsync($"id/{this.global.EncodeCacheKeyPart(expectedDocumentVersion1.Id)}");

            var actualDocument2 = await redisCaches.Users.GetAsync($"id-version/{this.global.EncodeCacheKeyPart(expectedDocumentVersion1.Id)}/{this.global.EncodeCacheKeyPart(expectedDocumentVersion1.VersionId)}");

            var actualDocument3 = await redisCaches.Users.GetAsync($"id-version/{this.global.EncodeCacheKeyPart(expectedDocumentVersion2.Id)}/{this.global.EncodeCacheKeyPart(expectedDocumentVersion2.VersionId)}");

            // Assert.
            AssertHelpers.HasEqualFieldValues(expectedDocumentVersion1, actualDocument1.Value);
            AssertHelpers.HasEqualFieldValues(expectedDocumentVersion1, actualDocument2.Value);
            AssertHelpers.HasEqualFieldValues(expectedDocumentVersion2, actualDocument3.Value);
        }