public void Change_Value() { var bd = new DateTime(1980, 2, 20, 14, 23, 12); var sut = new DateTimePickerWithUpdate(); var field = sut.GetType().GetField("_valuePicker", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); // ReSharper disable once PossibleNullReferenceException var ctrl = (DateTimePicker)field.GetValue(sut); // lest test... sut.Value = bd; sut.Value.Should().BeCloseTo(bd); ctrl.Value.Should().BeCloseTo(bd); // now press the button sut.UpdateToToday_OnClick(this, null); sut.Value.Should().BeCloseTo(DateTime.Now, 2000); ctrl.Value.Should().BeCloseTo(DateTime.Now, 2000); }
public void Use_Format_Settings() { var sut = new DateTimePickerWithUpdate { Watermark = "the watermark", Format = DateTimeFormat.Custom, FormatString = "yyyy-MMM-dd" }; sut.Watermark.Should().Be("the watermark"); sut.Format.Should().Be(DateTimeFormat.Custom); sut.FormatString.Should().Be("yyyy-MMM-dd"); var field = sut.GetType().GetField("_valuePicker", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); // ReSharper disable once PossibleNullReferenceException var ctrl = (DateTimePicker)field.GetValue(sut); ctrl.Watermark.Should().Be("the watermark"); ctrl.Format.Should().Be(DateTimeFormat.Custom); ctrl.FormatString.Should().Be("yyyy-MMM-dd"); }
protected override Control CreateValueControl() { var control = new DateTimePickerWithUpdate { ToolTip = Definition.Description, Watermark = Definition.Hint }; // set date time format DateFormat = Definition.Settings.Get(nameof(control.Format)); // ReSharper disable once InvertIf if (!string.IsNullOrWhiteSpace(DateFormat)) { control.Format = DateTimeFormat.Custom; control.FormatString = DateFormat; if (Definition.Settings.ContainsKey(nameof(control.Format))) { Definition.Settings[nameof(control.Format)] = Enum.GetName(typeof(DateTimeFormat), DateTimeFormat.Custom); } } return(control); }
public void Be_Creatable() { var sut = new DateTimePickerWithUpdate(); sut.Should().NotBeNull(); }