public void Parse_WhenEmptyInput_ShouldThrowException() { // Arrange string input = string.Empty; // Act GenericResponseParser<int> target = new GenericResponseParser<int>(); var actual = target.Parse(input) as UsageResponseInfo; // Assert }
public void Parse_WhenNullInput_ShouldThrowException() { // Arrange string input = null; // Act GenericResponseParser<int> target = new GenericResponseParser<int>(); target.Parse(input); // Assert }
public void Parse_WhenCalled_ShouldAllValuesParsed() { // Arrange const string expectedVersion = "2.0"; IEnumerable<int> expectdData = Enumerable.Range(1, 10); DateTime expectedCreationTime = RandomGenerator.GetDate(); int expectedBitsUsed = RandomGenerator.GetInteger(1); int expectedBitsLeft = RandomGenerator.GetInteger(1); int expectedRequestsLeft = RandomGenerator.GetInteger(1); int expectedAdvisoryDelay = RandomGenerator.GetInteger(1, 1000); int expectedId = RandomGenerator.GetInteger(1); var input = new JObject( new JProperty("jsonrpc", expectedVersion), new JProperty("result", new JObject( new JProperty("random", new JObject( new JProperty("data", new JArray(expectdData)), new JProperty("completionTime", expectedCreationTime) ) ), new JProperty("bitsUsed", expectedBitsUsed), new JProperty("bitsLeft", expectedBitsLeft), new JProperty("requestsLeft", expectedRequestsLeft), new JProperty("advisoryDelay", expectedAdvisoryDelay) ) ), new JProperty("id", expectedId) ); GenericResponseParser<int> target = new GenericResponseParser<int>(); var actual = target.Parse(input.ToString()) as DataResponseInfo<int>; actual.Should().Not.Be.Null(); actual.Version.Should().Equal(expectedVersion); actual.Data.Should().Equal(expectdData); actual.CompletionTime.Should().Equal(expectedCreationTime); actual.BitsUsed.Should().Equal(expectedBitsUsed); actual.BitsLeft.Should().Equal(expectedBitsLeft); actual.RequestsLeft.Should().Equal(expectedRequestsLeft); actual.Id.Should().Equal(expectedId); actual.AdvisoryDelay.Should().Equal(expectedAdvisoryDelay); }