public async Task Can_Create_Returns_201_Creaeted_When_No_Guid_Given()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var raw        = new { user = "******", expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds().ToString() };

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

            var req  = GetHttpRequestMessage(raw, $"guid", HttpMethod.Post);
            var resp = await _client.SendAsync(req);

            Assert.Equal(HttpStatusCode.Created, 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).CreateGuidData(Arg.Any <GuidData>());
        }
        /// <summary>
        /// Set cache after data created
        /// </summary>
        /// <param name="guidData"  cref="GuidData">The guidData</param>
        /// <returns>The newly created GuidData</returns>
        public async Task <GuidData> CreateGuidData(GuidData guidData)
        {
            var created = await _decorated.CreateGuidData(guidData);

            if (created != null)
            {
                await _cache.SetStringAsync(_cacheKey(created.Guid), JsonConvert.SerializeObject(created), _expire(created.Expire));
            }
            return(created);
        }
Exemple #3
0
        public async Task Can_Create_Returns_GuidData_When_No_Guid_Given()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var request    = new GuidDataRequest()
            {
                User = "******", Expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds().ToString()
            };

            _repoMock.CreateGuidData(Arg.Any <GuidData>()).Returns(new GuidData()
            {
                Guid = guid, User = request.User, Expire = long.Parse(request.Expire)
            });

            var actual = await _provider.CreateGuidData(request);

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

            await _repoMock.Received(1).CreateGuidData(Arg.Any <GuidData>());
        }
        public async void Can_Set_To_Cache_When_Created()
        {
            var guid       = Guid.NewGuid();
            var guidString = guid.ToString("N").ToUpper();
            var expected   = new GuidData()
            {
                Guid = guid, User = "******", Expire = DateTimeOffset.UtcNow.AddDays(30).ToUnixTimeSeconds()
            };

            _dbMock.CreateGuidData(Arg.Is <GuidData>(x => x.Guid == expected.Guid)).Returns(expected);

            var actual = await _repo.CreateGuidData(expected);

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

            await _dbMock.Received(1).CreateGuidData(Arg.Any <GuidData>());

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