Ejemplo n.º 1
0
        public void Should_Use_Custom_Boundaries_for_DateTime_Value_Injection()
        {
            //Create an instance of our test class
            var testInstance = new DateTimeTestClass();

            var dateTimeMax = DateTime.UtcNow.AddYears(1);
            var dateTimeMin = DateTime.UtcNow.AddYears(-1);

            //Create an instance of our IntSelector and set some custom bounds
            var selector =
                new DateTimeSelector().SetMax(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMax, dateTimeMax))
                                 .SetMin(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMin, dateTimeMin));

            //Iterate over the test object's properties
            foreach (var property in testInstance.GetType().GetProperties())
            {
                Assert.IsTrue(selector.CanBind(property),
                              string.Format("should have been able to bind to property {0}", property.Name));

                //Inject the value into this property on our test instance class
                selector.Generate(testInstance, property);

                //Get the value out of the property
                var fieldValue = (DateTime)property.GetValue(testInstance, null);
                Assert.IsNotNull(fieldValue);
                Assert.AreNotEqual(fieldValue, default(DateTime));
                Assert.IsTrue(fieldValue <= dateTimeMax && fieldValue >= dateTimeMin, "Custom range should have worked");
            }
        }
Ejemplo n.º 2
0
    public void SerializeUTC()
    {
      DateTimeTestClass c = new DateTimeTestClass();
      c.DateTimeField = new DateTime(2008, 12, 12, 12, 12, 12, 0, DateTimeKind.Utc).ToLocalTime();
      c.PreField = "Pre";
      c.PostField = "Post";
      string json = JavaScriptConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
      Assert.AreEqual(@"{""PreField"":""Pre"",""DateTimeField"":""2008-12-12T12:12:12.0000000Z"",""PostField"":""Post""}", json);

      //test the other edge case too
      c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc).ToLocalTime();
      c.PreField = "Pre";
      c.PostField = "Post";
      json = JavaScriptConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
      Assert.AreEqual(@"{""PreField"":""Pre"",""DateTimeField"":""2008-01-01T01:01:01.0000000Z"",""PostField"":""Post""}", json);
    }
Ejemplo n.º 3
0
        public void DateTime_Selector_Injects_All_DateTime_Values()
        {
            var dateTimeSelector = new DateTimeSelector();
            var dateTimeTestClass = new DateTimeTestClass();

            //Iterate over all of the properties in the fullNameClass object...
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                //Inject the value into the property
                dateTimeSelector.Generate(dateTimeTestClass, property);
            }

            //Iterate over all of the properties again
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                var fieldValue = (DateTime)property.GetValue(dateTimeTestClass, null);

                Assert.IsAssignableFrom<DateTime>(fieldValue, "Should be type of DateTime...");
                Assert.AreNotEqual(fieldValue, default(DateTime));
            }
        }
Ejemplo n.º 4
0
 public void SerializeShouldChangeNonUTCDates()
 {
     DateTimeTestClass c = new DateTimeTestClass();
       c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Local);
       c.PreField = "Pre";
       c.PostField = "Post";
       string json = JavaScriptConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal }); //note that this fails without the Utc converter...
       c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc);
       string json2 = JavaScriptConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
       Assert.AreNotEqual(json, json2);
 }