public void NameFormatsCorrectly() { var tc = new TestClass { Name = new FullName("Doe", "John", "Test") }; FormatterStrategy strategy = new FormatterStrategy(); strategy.SetFormatter(typeof(IFullNameFormatter), new FirstLeadingWithFullMiddle()); strategy.Format(tc); Assert.AreEqual("John Test Doe", tc.FullName); strategy.SetFormatter(typeof(IFullNameFormatter), new FirstLeadingWithInitializedMiddle()); strategy.Format(tc); Assert.AreEqual("John T. Doe", tc.FullName); strategy.SetFormatter(typeof(IFullNameFormatter), new LastLeadingWithFullMiddle()); strategy.Format(tc); Assert.AreEqual("Doe, John Test", tc.FullName); strategy.SetFormatter(typeof(IFullNameFormatter), new LastLeadingWithInitializedMiddle()); strategy.Format(tc); Assert.AreEqual("Doe, John T.", tc.FullName); }
public void DateFormatsCorrectly() { var tc = new TestClass { Date = new DateTime(2016, 10, 31, 8, 30, 22) }; FormatterStrategy strategy = new FormatterStrategy(); strategy.SetFormatter(typeof(IDateFormatter), new DateFormatter()); strategy.Format(tc); Assert.AreEqual("10/31/2016 8:30:22 AM", tc.FullDateTime); Assert.AreEqual("Monday, October 31, 2016", tc.LongDate); Assert.AreEqual("8:30:22 AM", tc.LongTime); Assert.AreEqual("10/31/2016", tc.ShortDate); Assert.AreEqual("8:30 AM", tc.ShortTime); Assert.AreEqual("2016-10-31T08:30:22", tc.SortableDateTime); Assert.AreEqual("636134994220000000", tc.Ticks); }