public void InitializeTest() { // Arrange. const string ProcessName = "TestProcess"; var dtm = Mock.Create<IDynamicTypeManager>(); Mock.Arrange(() => dtm.GetEditableRootType(ProcessName)).Returns(typeof(TestEdit)); var mapping = new DataTriggerFieldMapping(TestsHelper.ExtractPropertyName(() => new TestEdit().Text), true, (s, d) => null); var updater = new SimpleFieldUpdater { DynamicTypeManager = dtm }; // Act. updater.Initialize(ProcessName, mapping); // Assert. Assert.AreEqual(TestsHelper.ExtractPropertyName(() => new TestEdit().Text), updater.FieldName); Assert.IsTrue(updater.IsKey); Assert.AreSame(mapping.ValueCalculator, updater.ValueCalculator); Assert.AreSame(typeof(string), updater.PropertyType); // Exceptions. var invalidMapping1 = new DataTriggerFieldMapping("InvalidField", false, (s, d) => null); var invalidMapping2 = new DataTriggerFieldMapping(TestsHelper.ExtractPropertyName(() => new TestEdit().ReadOnly), false, (s, d) => null); TestsHelper.VerifyThrow<ArgumentNullException>(() => updater.Initialize(ProcessName, null)); TestsHelper.VerifyThrow<InvalidOperationException>(() => updater.Initialize(ProcessName, invalidMapping1)); TestsHelper.VerifyThrow<InvalidOperationException>(() => updater.Initialize(ProcessName, invalidMapping2)); }
public void InitializeLocalizedFieldTest() { // Arrange. const string ProcessName = "TestProcess"; var dtm = Mock.Create<IDynamicTypeManager>(); Mock.Arrange(() => dtm.GetEditableRootType(ProcessName)).Returns(typeof(TestEdit)); var mapping = new DataTriggerFieldMapping(TestsHelper.ExtractPropertyName(() => new TestEdit().Localized), true, (s, d) => null); var updater = new SimpleFieldUpdater { DynamicTypeManager = dtm }; // Act. updater.Initialize(ProcessName, mapping); // Assert. Assert.AreEqual(TestsHelper.ExtractPropertyName(() => new TestEdit().Localized), updater.FieldName); Assert.IsTrue(updater.IsKey); Assert.AreSame(mapping.ValueCalculator, updater.ValueCalculator); Assert.AreSame(typeof(string), updater.PropertyType); Assert.IsTrue(updater.AllowLocalizedData); Assert.AreEqual(3, updater.SupportedLocalizations.Count); Assert.IsTrue(updater.SupportedLocalizations.Any(l => Equals(l.CultureName, "en-US"))); Assert.IsTrue(updater.SupportedLocalizations.Any(l => Equals(l.CultureName, "es-ES"))); Assert.IsTrue(updater.SupportedLocalizations.Any(l => Equals(l.CultureName, "fr-FR"))); }
public void TryCreateFilterTest() { // Arrange. var updater1 = new SimpleFieldUpdater { FieldName = "TestField", PropertyType = typeof(string), ValueCalculator = (data, root) => "Test Value" }; var updater2 = new SimpleFieldUpdater { FieldName = "TestField", PropertyType = typeof(string), ValueCalculator = (data, root) => null }; IFilterDescriptor filter1; IFilterDescriptor filter2; // Act. Assert.IsTrue(updater1.TryCreateFilter(new DataTriggerSourceData(), new TestEdit(), out filter1)); Assert.IsNotNull(filter1); Assert.AreEqual("TestField", filter1.ColumnName); Assert.AreEqual(FilterOperator.IsEqualTo, filter1.Operator); Assert.AreEqual("Test Value", filter1.Value); Assert.IsFalse(updater2.TryCreateFilter(new DataTriggerSourceData(), new TestEdit(), out filter2)); Assert.IsNull(filter2); // Exceptions. TestsHelper.VerifyThrow<ArgumentNullException>(() => updater1.TryCreateFilter(null, new TestEdit(), out filter1)); TestsHelper.VerifyThrow<ArgumentNullException>(() => updater1.TryCreateFilter(new DataTriggerSourceData(), null, out filter1)); }
public void AreEqualTest() { // Arrange. var comparer1 = new SimpleFieldUpdater { FieldName = TestsHelper.ExtractPropertyName(() => new TestEdit().Text), ValueCalculator = (s, d) => null, PropertyType = typeof(string) }; var comparer2 = new SimpleFieldUpdater { FieldName = TestsHelper.ExtractPropertyName(() => new TestEdit().Text), ValueCalculator = (s, d) => 123, PropertyType = typeof(string) }; var item1 = new TestEdit { Text = null }; var item2 = new TestEdit { Text = "123" }; var item3 = new TestEdit { Text = "Test" }; var sourceData = new DataTriggerSourceData(); // Act / Assert. Assert.IsTrue(comparer1.AreEqual(sourceData, item1)); Assert.IsFalse(comparer1.AreEqual(sourceData, item2)); Assert.IsFalse(comparer1.AreEqual(sourceData, item3)); Assert.IsFalse(comparer2.AreEqual(sourceData, item1)); Assert.IsTrue(comparer2.AreEqual(sourceData, item2)); Assert.IsFalse(comparer2.AreEqual(sourceData, item3)); // Exceptions. TestsHelper.VerifyThrow<ArgumentNullException>(() => comparer1.AreEqual(null, item1)); TestsHelper.VerifyThrow<ArgumentNullException>(() => comparer1.AreEqual(sourceData, null)); }
public void SimpleFieldUpdaterCanUpdateCurrentState() { // Arrange. var updater = new SimpleFieldUpdater { FieldName = Constants.CurrentStateColumnName, NewValue = TestEdit.States.Approved.Name, PropertyType = typeof(string) }; var item = new TestEdit(); // Act. updater.Update(item); // Assert. Assert.AreEqual(TestEdit.States.Approved.Id, item.CurrentState); // Exceptions. var statelessItem = Mock.Create<IEditableRoot>(); TestsHelper.VerifyThrow<InvalidOperationException>(() => updater.Update(statelessItem)); updater.NewValue = null; TestsHelper.VerifyThrow<InvalidOperationException>(() => updater.Update(item)); updater.NewValue = "Invalid State"; TestsHelper.VerifyThrow<InvalidOperationException>(() => updater.Update(item)); }
public void SimpleFieldUpdaterCanUpdateLocalizedFields() { // Arrange. var englishCulture = new CultureInfo("en-US"); var spanishCulture = new CultureInfo("es-ES"); var frenchCulture = new CultureInfo("fr-FR"); var updater = new SimpleFieldUpdater { FieldName = TestsHelper.ExtractPropertyName(() => new TestEdit().Localized), PropertyType = typeof(string), AllowLocalizedData = true }; updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(englishCulture.Name)); updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(spanishCulture.Name)); updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(frenchCulture.Name)); updater.SetValue(englishCulture.Name, "English Text"); updater.SetValue(spanishCulture.Name, "Spanish Text"); updater.SetValue(frenchCulture.Name, "French Text"); var item = new TestEdit(); // Act. updater.Update(item); // Assert. Assert.AreEqual("English Text", item.Localized_en_US); Assert.AreEqual("Spanish Text", item.Localized_es_ES); Assert.AreEqual("French Text", item.Localized_fr_FR); }
public void SimpleFieldUpdaterCanUpdateSimpleFields() { // Arrange. var updater = new SimpleFieldUpdater { FieldName = TestsHelper.ExtractPropertyName(() => new TestEdit().Text), NewValue = "123", PropertyType = typeof(string) }; var item = new TestEdit(); // Act. updater.Update(item); // Assert. Assert.AreEqual("123", item.Text); // Exceptions. TestsHelper.VerifyThrow<ArgumentNullException>(() => updater.Update(null)); }
public void CalculateNewLocalizedFieldValueTest() { // Arrange. var englishCulture = new CultureInfo("en-US"); var spanishCulture = new CultureInfo("es-ES"); var frenchCulture = new CultureInfo("fr-FR"); var updater = new SimpleFieldUpdater { ValueCalculator = (s, d) => GetLocalizedValue(), PropertyType = typeof(string), AllowLocalizedData = true }; updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(englishCulture.Name)); updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(spanishCulture.Name)); updater.SupportedLocalizations.Add(new LocalizationInfoAttribute(frenchCulture.Name)); // Act. updater.CalculateNewValue(new DataTriggerSourceData(), new TestEdit()); // Assert. Assert.AreEqual("English Text", updater.GetValue(englishCulture.Name)); Assert.AreEqual("Spanish Text", updater.GetValue(spanishCulture.Name)); Assert.AreEqual("French Text", updater.GetValue(frenchCulture.Name)); }
public void CalculateNewValueTest() { // Arrange. var updater = new SimpleFieldUpdater { ValueCalculator = (s, d) => 123, PropertyType = typeof(string) }; // Act. updater.CalculateNewValue(new DataTriggerSourceData(), new TestEdit()); // Assert. Assert.AreEqual("123", updater.NewValue); // Exceptions. TestsHelper.VerifyThrow<ArgumentNullException>(() => updater.CalculateNewValue(null, new TestEdit())); TestsHelper.VerifyThrow<ArgumentNullException>(() => updater.CalculateNewValue(new DataTriggerSourceData(), null)); }