Esempio n. 1
0
    public void TestAsyncRulesValid()
    {
      UnitTestContext context = GetContext();

      HasAsyncRule har = new HasAsyncRule();
      context.Assert.IsTrue(har.IsValid, "IsValid 1");

      har.ValidationComplete += (o, e) =>
      {
        context.Assert.IsTrue(har.IsValid, "IsValid 2");
        context.Assert.Success();
      };
      har.Name = "success";
      context.Complete();
    }
Esempio n. 2
0
    public void TestAsyncRuleError()
    {
      UnitTestContext context = GetContext();

      HasAsyncRule har = new HasAsyncRule();
      context.Assert.IsTrue(har.IsValid, "IsValid 1");

      har.ValidationComplete += (o, e) =>
      {
        context.Assert.IsFalse(har.IsValid, "IsValid 2");
        context.Assert.AreEqual(1, har.BrokenRulesCollection.Count);
        context.Assert.Success();
      };
      har.Name = "error";
      context.Complete();
    }
Esempio n. 3
0
    public void ValidateMultipleObjectsSimultaneously()
    {
      UnitTestContext context = GetContext();

      context.Assert.Try(() =>
        {
          int iterations = 20;
          int completed = 0;
          for (int x = 0; x < iterations; x++)
          {
            HasAsyncRule har = new HasAsyncRule();
            har.ValidationComplete += (o, e) =>
            {
              context.Assert.AreEqual("error", har.Name);
              context.Assert.AreEqual(1, har.BrokenRulesCollection.Count);
              System.Diagnostics.Debug.WriteLine(har.BrokenRulesCollection.Count);
              completed++;
              if (completed == iterations)
                context.Assert.Success();
            };

            // set this to error so we can verify that all 6 rules get run for
            // each object. This is essentially the only way to communicate back
            // with the object except byref properties.
            har.Name = "error";
          }
        });

      context.Complete();
    }
Esempio n. 4
0
    public void AsyncCompleteVerifyUIThread()
    {
      UnitTestContext context = GetContext();
      Thread expected = Thread.CurrentThread;

      HasAsyncRule har = new HasAsyncRule();
      context.Assert.IsTrue(har.IsValid, "IsValid 1");

      har.ValidationComplete += (o, e) =>
      {
        Thread actual = Thread.CurrentThread;
        context.Assert.AreSame(expected, actual);
        context.Assert.Success();
      };
      har.Name = "success";
      context.Complete();
    }