コード例 #1
0
        public void WriteJson_ValidPositiveInput_Success(JsonToken jsonTokenType, object input, DateTime expectedResult)
        {
            //Arrange
            var unixTimeConverter = new UnixTime.UnixTimeConverter();
            var jsonReaderMock    = new Mock <JsonReader>();

            jsonReaderMock.SetupGet(x => x.TokenType).Returns(jsonTokenType);
            jsonReaderMock.SetupGet(x => x.Value).Returns(input);

            //Act
            var result = unixTimeConverter.ReadJson(jsonReaderMock.Object, null, false, null);

            //Assert
            Assert.Equal(expectedResult, result);
        }
コード例 #2
0
        public void WriteJson_InvalidTokenType_ExceptionThrown()
        {
            //Arrange
            var unixTimeConverter = new UnixTime.UnixTimeConverter();
            var jsonReaderMock    = new Mock <JsonReader>();

            jsonReaderMock.SetupGet(x => x.TokenType).Returns(JsonToken.Boolean);

            //Act
            var ex = Assert.Throws <ArgumentException>(
                () => unixTimeConverter.ReadJson(jsonReaderMock.Object, null, false, null));

            //Assert
            Assert.Equal("Unexpected token. Integer or String was expected, got Boolean", ex.Message);
        }
コード例 #3
0
        public void WriteJson_InvalidString_ExceptionThrown()
        {
            //Arrange
            var unixTimeConverter = new UnixTime.UnixTimeConverter();
            var jsonReaderMock    = new Mock <JsonReader>();

            jsonReaderMock.SetupGet(x => x.TokenType).Returns(JsonToken.String);
            jsonReaderMock.SetupGet(x => x.Value).Returns("wrongInput");

            //Act
            var ex = Assert.Throws <ArgumentException>(
                () => unixTimeConverter.ReadJson(jsonReaderMock.Object, null, false, null));

            //Assert
            Assert.Equal("wrongInput isn't a number", ex.Message);
        }