public async Task CreateGuidInfo_DefaultExpire()
        {
            // do not specify expiration date
            var infoBase = new GuidInfoBase()
            {
                User = "******"
            };

            // we are going to add to database
            var mockRepo = new Mock <IRepository <GuidInfoEntity> >();

            mockRepo.Setup(r => r.AddAsync(It.IsAny <GuidInfoEntity>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            // and save changes
            var mockContext = new Mock <IGuidRepositoryContext>();

            mockContext.Setup(r => r.SaveChangesAsync())
            .Returns(Task.CompletedTask)
            .Verifiable();
            mockContext.Setup(r => r.GuidInfos)
            .Returns(mockRepo.Object);

            var mockCache = new Mock <IEntityCache <GuidInfoEntity> >();

            var controller = new GuidInfosController(mockContext.Object, mockCache.Object, _mockClock.Object);
            var info       = await controller.CreateGuidInfoAsync(infoBase);

            Assert.IsType <ActionResult <GuidInfo> >(info);
            var result = Assert.IsType <CreatedAtRouteResult>(info.Result);

            Assert.Equal("GetGuidInfo", result.RouteName);
            Assert.Equal((int)HttpStatusCode.Created, result.StatusCode);
            var value = Assert.IsType <GuidInfo>(result.Value);

            Assert.Equal(value.User, infoBase.User);
            Assert.Equal(value.Expire, _now.AddDays(30));
            Assert.True(System.Guid.TryParse(value.Guid, out System.Guid guid));

            _mockClock.Verify();
            mockRepo.Verify();
            mockContext.Verify();
        }
        public async Task CreateGuidInfo_InvalidUser()
        {
            // User must not be null, empty, or whitespace
            var infoBase = new GuidInfoBase()
            {
                User   = string.Empty,
                Expire = null
            };

            var mockRepo  = new Mock <IGuidRepositoryContext>();
            var mockCache = new Mock <IEntityCache <GuidInfoEntity> >();

            var controller = new GuidInfosController(mockRepo.Object, mockCache.Object, _mockClock.Object);
            var info       = await controller.CreateGuidInfoAsync(infoBase);

            Assert.IsType <ActionResult <GuidInfo> >(info);
            var result = Assert.IsType <BadRequestObjectResult>(info.Result);
            var value  = Assert.IsType <GuidApiError>(result.Value);

            Assert.Equal((int)value.Code, (int)GuidErrorCode.InvalidUser);
        }