Esempio n. 1
0
        public async Task Return_Success_OnValue_Found_GetArticleAsync()
        {
            var mockCache      = new Mock <IMemoryCache>();
            var mockCacheEntry = new Mock <ICacheEntry>();

            string?keyPayload = null;

            mockCache
            .Setup(mc => mc.CreateEntry(It.IsAny <object>()))
            .Callback((object k) => keyPayload = (string)k)
            .Returns(mockCacheEntry.Object);

            object?valuePayload = null;

            mockCacheEntry
            .SetupSet(mce => mce.Value           = It.IsAny <object>())
            .Callback <object>(v => valuePayload = v);

            TimeSpan?expirationPayload = null;

            mockCacheEntry
            .SetupSet(mce => mce.AbsoluteExpirationRelativeToNow = It.IsAny <TimeSpan?>())
            .Callback <TimeSpan?>(dto => expirationPayload       = dto);

            var          _fileLoggerMock = new Mock <IFileLogger>();
            AppDbContext context         = DbHelpers.InitContext("TestDB");

            await context.Articles.AddAsync(new LikeButton.Core.Entities.Article {
                ArticleUniqueIdentifier = Guid.Empty, Title = "some"
            });

            var saved = await context.SaveChangesAsync() > 0;

            Assert.True(saved);
            var command = new ArticleRepository(context, _fileLoggerMock.Object, mockCache.Object);

            var exc = await command.GetArticleAsync(Guid.Empty);

            Assert.NotNull(exc);
            Assert.True(exc.Title == "some");
        }