/src/Otis.Tests/FunctionMapTest.cs

http://otis-lib.googlecode.com/ · C# · 67 lines · 45 code · 8 blank · 14 comment · 0 complexity · ea6ee6fcb0d3ad34576728f65f5dbf50 MD5 · raw file

  1. /*
  2. * Created by: Zdeslav Vojkovic
  3. * Created: Wednesday, October 24, 2007
  4. */
  5. using System;
  6. using System.CodeDom;
  7. using System.Collections.Generic;
  8. using NUnit.Framework;
  9. using Otis.CodeGen;
  10. namespace Otis.Tests
  11. {
  12. [TestFixture]
  13. public class FunctionMapTest
  14. {
  15. [SetUp]
  16. public void SetUp() {}
  17. [TearDown]
  18. public void TearDown() {}
  19. [Test]
  20. [ExpectedException(typeof(OtisException))]
  21. public void Registration_Fails_If_Type_Doesnt_Implement_IAggregateFunction()
  22. {
  23. FunctionMap map = new FunctionMap();
  24. map.Register("test", typeof(string));
  25. }
  26. [Test]
  27. public void Registration_Suceeds_For_Well_Implemented_Aggregate_Function()
  28. {
  29. FunctionMap map = new FunctionMap();
  30. map.Register("test", typeof(TestFn<int>));
  31. Type t1 = typeof(TestFn<int>);
  32. Type t2 = map.GetTypeForFunction("test");
  33. Assert.AreEqual(typeof(TestFn<int>), map.GetTypeForFunction("test"));
  34. }
  35. [Test]
  36. [ExpectedException(typeof(OtisException))]
  37. public void Retrieving_Unregistered_Function_Fails()
  38. {
  39. FunctionMap map = new FunctionMap();
  40. map.GetTypeForFunction("test");
  41. }
  42. }
  43. /*
  44. class TestFn<T> : IAggregateFunction<T>
  45. {
  46. public void Initialize(T initialValue){}
  47. public void ProcessValue(T value){}
  48. public int ProcessedItemCount { get { return 0; } }
  49. public T Result { get { return default(T); } }
  50. public string ExpressionFormat { get { return null; }
  51. }
  52. }*/
  53. class TestFn<T> : IAggregateFunctionCodeGenerator
  54. {
  55. public IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { return null; }
  56. public IEnumerable<string> GetIterationStatements(AggregateFunctionContext context, IList<AggregateExpressionPathItem> pathItems) { return null; }
  57. public CodeStatement GetAssignmentStatement(AggregateFunctionContext context) { return null; }
  58. }
  59. }