Пример #1
0
        public async Task GettingNonExistingKeyReturnsNoContent()
        {
            var key        = Guid.NewGuid().ToString();
            var factory    = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).GetAsync() == new ValueTask <CachePulse>(CachePulse.None));
            var controller = new CacheController(factory);

            var result = await controller.GetAsync(key).ConfigureAwait(false);

            Mock.Get(factory).VerifyAll();
            Assert.IsType <NoContentResult>(result.Result);
        }
Пример #2
0
        public async Task GettingExistingKeyReturnsOk()
        {
            // arrange
            var key = Guid.NewGuid().ToString();

            byte[]? value = Guid.NewGuid().ToByteArray();
            var factory    = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).GetAsync() == new ValueTask <CachePulse>(new CachePulse(Guid.NewGuid(), value)));
            var controller = new CacheController(factory);

            // act
            var result = await controller.GetAsync(key).ConfigureAwait(false);

            // assert
            Mock.Get(factory).VerifyAll();
            var ok      = Assert.IsType <OkObjectResult>(result.Result);
            var content = Assert.IsType <byte[]>(ok.Value);

            Assert.Same(value, content);
        }