Пример #1
0
        public async Task Return_False_OnCreatesAnArticle_CreateArticleAsync()
        {
            var _fileLoggerMock = new Mock <IFileLogger>();

            AppDbContext context = DbHelpers.InitContext("TestDB");



            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 command = new ArticleRepository(context, _fileLoggerMock.Object, mockCache.Object);

            var exc = await command.CreateArticleAsync(new LikeButton.Core.DTOs.APIRequest.CreateArticleRequest {
                ArticleUniqueIdentifier = Guid.NewGuid(), Body = "England"
            });


            Assert.True(exc);
        }