private static void TestResults(UsageResponseInfo results)
 {
     results.Should().Not.Be.Null();
     results.Version.Should().Not.Be.Null();
     results.AdvisoryDelay.Should().Equal(0);
     results.Id.Should().Be.GreaterThan(0);
     results.CreationTime.Date.Should().Be.LessThan(DateTime.Today);
     results.Status.Should().Equal(StatusType.Running);
 }
        public IResponseInfo Parse(string response)
        {
            if (string.IsNullOrWhiteSpace(response))
                throw new RandomOrgRuntimeException(ResourceHelper.GetString(StringsConstants.EXCEPTION_CANNOT_BE_NULLOREMPTY, nameof(response)));

            JObject json = JObject.Parse(response);

            var version = JsonHelper.JsonToString(json.GetValue(JsonRpcConstants.RPC_PARAMETER_NAME));
            var result = json.GetValue(JsonRpcConstants.RESULT_PARAMETER_NAME) as JObject;
            StatusType status = StatusType.Unknown;
            DateTime creationTime = DateTime.MinValue;
            int bitsLeft = 0;
            int requestsLeft = 0;
            int totalBits = 0;
            int totalRequests = 0;

            if (result != null)
            {
                var statusString = JsonHelper.JsonToString(result.GetValue(JsonRpcConstants.STATUS_PARAMETER_NAME));
                switch (statusString)
                {
                    case RandomOrgConstants.STATUS_STOPPED:
                        status = StatusType.Stopped;
                        break;
                    case RandomOrgConstants.STATUS_PAUSED:
                        status = StatusType.Paused;
                        break;
                    case RandomOrgConstants.STATUS_RUNNING:
                        status = StatusType.Running;
                        break;
                    default:
                        status = StatusType.Unknown;
                        break;
                }

                creationTime = JsonHelper.JsonToDateTime(result.GetValue(JsonRpcConstants.CREATION_TIME_PARAMETER_NAME));
                bitsLeft = JsonHelper.JsonToInt(result.GetValue(JsonRpcConstants.BITS_LEFT_PARAMETER_NAME));
                requestsLeft = JsonHelper.JsonToInt(result.GetValue(JsonRpcConstants.REQUESTS_LEFT_PARAMETER_NAME));
                totalBits = JsonHelper.JsonToInt(result.GetValue(JsonRpcConstants.TOTAL_BITS_PARAMETER_NAME));
                totalRequests = JsonHelper.JsonToInt(result.GetValue(JsonRpcConstants.TOTAL_REQUESTS_PARAMETER_NAME));
            }
            var id = JsonHelper.JsonToInt(json.GetValue("id"));

            var usageResponse = new UsageResponseInfo(version, status, creationTime, bitsLeft, requestsLeft, totalBits, totalRequests, id);
            return usageResponse;
        }
        public void Constructor_WhenCalled_ExpectAllValuesSet()
        {
            const string version = "2.0";
            const StatusType status = StatusType.Running;
            DateTime creationTime = new DateTime(2016, 2, 1);
            const int bitsLeft = 200;
            const int requestsLeft = 300;
            const int totalBits = 100;
            const int totalRequests = 2;
            const int id = 400;

            UsageResponseInfo target = new UsageResponseInfo(version, status, creationTime, bitsLeft, requestsLeft, totalBits, totalRequests, id);

            target.Version.Should().Equal(version);
            target.Status.Should().Equal(status);
            target.CreationTime.Should().Equal(creationTime);
            target.BitsLeft.Should().Equal(bitsLeft);
            target.RequestsLeft.Should().Equal(requestsLeft);
            target.TotalBits.Should().Equal(totalBits);
            target.TotalRequests.Should().Equal(totalRequests);
            target.Id.Should().Equal(id);
            target.AdvisoryDelay.Should().Equal(0);
        }
 private static void TestResults(UsageResponseInfo results)
 {
     results.Should().Not.Be.Null();
 }