public async void Can_Get_From_DB_Then_Set_To_Cache_Before_Cached()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var expected   = new GuidData()
            {
                Guid = guid, User = "******", Expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds()
            };

            _cacheMock.GetAsync(Arg.Is <string>(x => x == "GuidData_" + guidString)).Returns(default(byte[]));
            _dbMock.GetGuidData(Arg.Is <Guid>(x => x == guid)).Returns(expected);

            var actual = await _repo.GetGuidData(guid);

            Assert.NotNull(actual);
            Assert.Equal(expected.Guid, actual.Guid);
            Assert.Equal(expected.User, actual.User);
            Assert.Equal(expected.Expire, actual.Expire);

            await _cacheMock.Received(1).GetAsync(Arg.Any <string>());

            await _cacheMock.Received(1).SetAsync(Arg.Any <string>(), Arg.Any <byte[]>(), Arg.Any <DistributedCacheEntryOptions>());

            await _dbMock.Received(1).GetGuidData(Arg.Any <Guid>());
        }
        public async Task Can_Get_Returns_200_OK_When_A_Valid_Guid_Given()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var raw        = new { user = "******", expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds().ToString() };

            _repoMock.GetGuidData(Arg.Is <Guid>(x => x == guid)).Returns((new GuidData()
            {
                Guid = guid, User = raw.user, Expire = long.Parse(raw.expire)
            }));

            var req = GetHttpRequestMessage(raw, $"guid/{guidString}", HttpMethod.Get);

            var resp = await _client.SendAsync(req);

            Assert.Equal(HttpStatusCode.OK, resp.StatusCode);

            var actual = JsonConvert.DeserializeObject <GuidDataResponse>(await resp.Content.ReadAsStringAsync());

            Assert.NotNull(actual);
            Assert.Equal(guidString, actual.Guid);
            Assert.Equal(raw.user, actual.User);
            Assert.Equal(raw.expire, actual.Expire);

            await _repoMock.Received(1).GetGuidData(Arg.Any <Guid>());
        }
Beispiel #3
0
        public async Task Can_Get_Returns_GuidData_When_Guid_Exist()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var raw        = new { user = "******", expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds().ToString() };

            _repoMock.GetGuidData(Arg.Is <Guid>(x => x == guid)).Returns((new GuidData()
            {
                Guid = guid, User = raw.user, Expire = long.Parse(raw.expire)
            }));

            var actual = await _provider.GetGuidData(guidString);

            Assert.NotNull(actual);
            Assert.Equal(guidString, actual.Guid);
            Assert.Equal(raw.user, actual.User);
            Assert.Equal(raw.expire, actual.Expire);

            await _repoMock.Received(1).GetGuidData(Arg.Any <Guid>());
        }