public void TestFuncInvokeSuccess() { var container = ScriptableObject.CreateInstance <MethodContainer>(); var intFunc = new SerializedFunc <int> { MethodContainer = container, MethodName = "IntFunc" }; var intFuncInt = new SerializedFunc <int, int> { MethodContainer = container, MethodName = "IntFuncInt" }; var intFuncIntDouble = new SerializedFunc <int, double, int> { MethodContainer = container, MethodName = "IntFuncIntDouble" }; var intFuncIntDoubleBool = new SerializedFunc <int, double, bool, int> { MethodContainer = container, MethodName = "IntFuncIntDoubleBool" }; Assert.IsTrue(intFunc.CanInvoke); Assert.IsTrue(intFuncInt.CanInvoke); Assert.IsTrue(intFuncIntDouble.CanInvoke); Assert.IsTrue(intFuncIntDoubleBool.CanInvoke); Assert.AreEqual(1, intFunc.Invoke()); Assert.AreEqual(1, intFuncInt.Invoke(1)); Assert.AreEqual(1, intFuncIntDouble.Invoke(1, 1.0)); Assert.AreEqual(1, intFuncIntDoubleBool.Invoke(1, 1.0, true)); Assert.AreEqual(4, container.InvokeCount); }
private void menuItemSaveAs_Click(object sender, RoutedEventArgs e) { SerializedFunc sf = new SerializedFunc(pf, textBoxEps.Text, textBoxXMin.Text, textBoxXMax.Text, textBoxYMin.Text, textBoxYMax.Text); SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "points.xml"; sfd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; sfd.Filter = "Файлs XML (*.xml)|*.xml|Все файлы (*.*)|*.*"; sfd.DefaultExt = "*.xml"; if (sfd.ShowDialog() == true) { try { sf.Write(sfd.FileName); filePath = sfd.FileName; MessageBox.Show("Файл сохранено"); } catch (Exception) { MessageBox.Show("Ошибка записи в файл"); } } }
public void TestFuncInvokeFail() { var container = ScriptableObject.CreateInstance <MethodContainer>(); var func0 = new SerializedFunc <int> { MethodContainer = container, MethodName = "Fake" }; var func1 = new SerializedFunc <int, int> { MethodContainer = null, MethodName = null, }; var func2 = new SerializedFunc <int, int> { MethodContainer = null, MethodName = string.Empty, }; var func3 = new SerializedFunc <int, int> { MethodContainer = null, MethodName = "Action", }; var func4 = new SerializedFunc <int, double, int> { MethodContainer = container, MethodName = string.Empty }; var func5 = new SerializedFunc <int, double, bool, int> { MethodContainer = container, MethodName = null }; Assert.False(func0.CanInvoke); Assert.False(func1.CanInvoke); Assert.False(func2.CanInvoke); Assert.False(func3.CanInvoke); Assert.False(func4.CanInvoke); Assert.False(func5.CanInvoke); Assert.Throws <InvalidOperationException>(() => func0.Invoke()); Assert.Throws <InvalidOperationException>(() => func1.Invoke(1)); Assert.Throws <InvalidOperationException>(() => func2.Invoke(1)); Assert.Throws <InvalidOperationException>(() => func3.Invoke(1)); Assert.Throws <InvalidOperationException>(() => func4.Invoke(1, 1.0)); Assert.Throws <InvalidOperationException>(() => func5.Invoke(1, 1.0, true)); }
private void menuItemSave_Click(object sender, RoutedEventArgs e) { if (filePath != null && File.Exists(filePath)) { SerializedFunc sf = new SerializedFunc(pf, textBoxEps.Text, textBoxXMin.Text, textBoxXMax.Text, textBoxYMin.Text, textBoxYMax.Text); try { sf.Write(filePath); MessageBox.Show("Файл сохранено", "Сохранено", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception) { MessageBox.Show("Ошибка записи в файл", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else { menuItemSaveAs_Click(sender, new RoutedEventArgs()); } }
private void menuItemOpen_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; ofd.Filter = "XML data file (*.xml)|*.xml|All files|*.*"; ofd.InitialDirectory = Environment.CurrentDirectory; ofd.DefaultExt = "*.xml"; ofd.CheckPathExists = true; SerializedFunc sf = new SerializedFunc(); if (ofd.ShowDialog() == true) { try { sf.Read(ofd.FileName); filePath = ofd.FileName; } catch (Exception) { MessageBox.Show("Ошибка чтения с файла", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } menuItemClear_Click(sender, new RoutedEventArgs()); pf = sf.pf; textBoxEps.Text = sf.eps; textBoxXMin.Text = sf.xMin; textBoxXMax.Text = sf.xMax; textBoxYMin.Text = sf.yMin; textBoxYMax.Text = sf.yMax; textBoxFunc.Text = pf.StringFunction; textBoxSols.Text = ""; buttonDraw_Click(sender, new RoutedEventArgs()); } catch { } }
public void TestFuncInvokeFail() { var container = ScriptableObject.CreateInstance<MethodContainer>(); var func0 = new SerializedFunc<int> { MethodContainer = container, MethodName = "Fake" }; var func1 = new SerializedFunc<int, int> { MethodContainer = null, MethodName = null, }; var func2 = new SerializedFunc<int, int> { MethodContainer = null, MethodName = string.Empty, }; var func3 = new SerializedFunc<int, int> { MethodContainer = null, MethodName = "Action", }; var func4 = new SerializedFunc<int, double, int> { MethodContainer = container, MethodName = string.Empty }; var func5 = new SerializedFunc<int, double, bool, int> { MethodContainer = container, MethodName = null }; Assert.False(func0.CanInvoke); Assert.False(func1.CanInvoke); Assert.False(func2.CanInvoke); Assert.False(func3.CanInvoke); Assert.False(func4.CanInvoke); Assert.False(func5.CanInvoke); Assert.Throws<InvalidOperationException>(() => func0.Invoke()); Assert.Throws<InvalidOperationException>(() => func1.Invoke(1)); Assert.Throws<InvalidOperationException>(() => func2.Invoke(1)); Assert.Throws<InvalidOperationException>(() => func3.Invoke(1)); Assert.Throws<InvalidOperationException>(() => func4.Invoke(1, 1.0)); Assert.Throws<InvalidOperationException>(() => func5.Invoke(1, 1.0, true)); }
public void TestFuncInvokeSuccess() { var container = ScriptableObject.CreateInstance<MethodContainer>(); var intFunc = new SerializedFunc<int> { MethodContainer = container, MethodName = "IntFunc" }; var intFuncInt = new SerializedFunc<int, int> { MethodContainer = container, MethodName = "IntFuncInt" }; var intFuncIntDouble = new SerializedFunc<int, double, int> { MethodContainer = container, MethodName = "IntFuncIntDouble" }; var intFuncIntDoubleBool = new SerializedFunc<int, double, bool, int> { MethodContainer = container, MethodName = "IntFuncIntDoubleBool" }; Assert.IsTrue(intFunc.CanInvoke); Assert.IsTrue(intFuncInt.CanInvoke); Assert.IsTrue(intFuncIntDouble.CanInvoke); Assert.IsTrue(intFuncIntDoubleBool.CanInvoke); Assert.AreEqual(1, intFunc.Invoke()); Assert.AreEqual(1, intFuncInt.Invoke(1)); Assert.AreEqual(1, intFuncIntDouble.Invoke(1, 1.0)); Assert.AreEqual(1, intFuncIntDoubleBool.Invoke(1, 1.0, true)); Assert.AreEqual(4, container.InvokeCount); }