Exemple #1
0
    public void UndoParentThenChildEnsureNoEditLevelMismatch()
    {
      using (var context = GetContext())
      {
        Person p = new Person();
        p.Addresses = new AddressList();
        Address a = new Address();
        p.Addresses.Add(a);

        p.BeginEdit();
        a.BeginEdit();
        context.Assert.Try(p.CancelEdit);
      }
    }
Exemple #2
0
    public void ApplyEditOnChildThenRoot()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      p.Addresses.Add(a);

      p.BeginEdit();
      a.ApplyEdit();
      context.Assert.Try( p.ApplyEdit );
      context.Complete();
    }
Exemple #3
0
    public void UndoWithDeleteAddToList()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      a.ZipCode = "0";
      p.Addresses.Add(a);
      Address a1 = new Address();
      a1.ZipCode = "1";
      p.Addresses.Add(a1);

      int age1 = p.Age;
      string city1 = a.City;

      p.BeginEdit();

      int age2 = p.Age = 2;
      string city2 = a.City = "two";
      p.Addresses[0].ZipCode = "000";

      Address a2 = new Address();
      a2.ZipCode = "2";
      p.Addresses.Add(a2);
      Address a3 = new Address();
      a3.ZipCode = "3";
      p.Addresses.Add(a3);
      p.Addresses.RemoveAt(0);

      context.Assert.AreEqual(age2, p.Age);
      context.Assert.AreEqual(city2, a.City);
      p.CancelEdit();

      context.Assert.AreEqual(age1, p.Age);
      context.Assert.AreEqual(city1, a.City);
      context.Assert.AreEqual("0", a.ZipCode);
      context.Assert.AreEqual(2, p.Addresses.Count);
      context.Assert.Success();
      context.Complete();
    }
Exemple #4
0
    public void ApplyEditWithChildSuccess()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      p.Addresses.Add(a);

      p.Age = 1;
      a.City = "one";
      p.BeginEdit();

      p.Age = 2;
      a.City = "two";
      p.ApplyEdit();

      context.Assert.AreEqual(2, p.Age);
      context.Assert.AreEqual("two", a.City);
      context.Assert.Success();
      context.Complete();
    }
Exemple #5
0
    public void UndoChildSuccess()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      p.Addresses.Add(a);

      int age1 = p.Age = 1;
      string city1 = a.City = "one";
      p.BeginEdit();

      int age2 = p.Age = 2;
      string city2 = a.City = "two";
      a.BeginEdit();

      string city3 = a.City = "three";
      a.CancelEdit();

      context.Assert.AreEqual(age2, p.Age);
      context.Assert.AreEqual(city2, a.City);
      p.CancelEdit();

      context.Assert.AreEqual(age1, p.Age);
      context.Assert.AreEqual(city1, a.City);
      context.Assert.Success();
      context.Complete();
    }
Exemple #6
0
    public void ApplyChildAfterRootUndo()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      p.Addresses.Add(a);

      p.BeginEdit();
      p.CancelEdit();
      a.ApplyEdit();
      context.Assert.Success();
      context.Complete();
    }
Exemple #7
0
    public void UndoChildFail()
    {
      UnitTestContext context = GetContext();
      Person p = new Person();
      p.Addresses = new AddressList();
      Address a = new Address();
      p.Addresses.Add(a);

      p.BeginEdit();
      p.CancelEdit();
      a.CancelEdit();
      context.Assert.Success();
      context.Complete();
    }
Exemple #8
0
    public void BusinessObjectWithChildList()
    {
      UnitTestContext context = GetContext();
      DateTime birthdate = new DateTime(1980, 2, 3);

      Person expectedPerson = new Person();
      expectedPerson.Name = "test";
      expectedPerson.Unserialized = "should be null";
      expectedPerson.Birthdate = birthdate;

      AddressList expectedAddressList = new AddressList();
      expectedPerson.Addresses = expectedAddressList;
      
      Address expectedA1 = new Address();
      expectedA1.City = "Minneapolis";
      expectedA1.ZipCode = "55414";
      
      Address expectedA2 = new Address();
      expectedA2.City = "Eden Prairie";
      expectedA2.ZipCode = "55403";

      expectedAddressList.Add(expectedA1);
      expectedAddressList.Add(expectedA2);
      expectedPerson.PrimaryAddress = expectedAddressList[1];

      var buffer = MobileFormatter.Serialize(expectedPerson);
      var actualPerson = (Person)MobileFormatter.Deserialize(buffer);

      context.Assert.AreEqual(expectedPerson.Name, actualPerson.Name);
      context.Assert.AreEqual(expectedPerson.Birthdate, actualPerson.Birthdate);
      context.Assert.AreEqual(expectedPerson.Age, actualPerson.Age);
      context.Assert.AreEqual(actualPerson.Unserialized, string.Empty);
      context.Assert.IsNotNull(expectedPerson.Unserialized);
      context.Assert.AreSame(expectedPerson.PrimaryAddress, expectedAddressList[1]);

      var actualAddressList = actualPerson.Addresses;
      context.Assert.IsNotNull(actualAddressList);
      context.Assert.AreEqual(expectedAddressList.Count, actualAddressList.Count);

      context.Assert.AreEqual(expectedAddressList[0].City, actualAddressList[0].City);
      context.Assert.AreEqual(expectedAddressList[0].ZipCode, actualAddressList[0].ZipCode);

      context.Assert.AreEqual(expectedAddressList[1].City, actualAddressList[1].City);
      context.Assert.AreEqual(expectedAddressList[1].ZipCode, actualAddressList[1].ZipCode);

      context.Assert.AreSame(actualPerson.PrimaryAddress, actualAddressList[1]);
      context.Assert.Success();
      context.Complete();
    }