Ejemplo n.º 1
0
        public void Save_on_GrandChildList_Item_Throws_InvalidOperationException()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(e.Object);
#if SILVERLIGHT
                e.Object[0].GrandChildren[0].BeginSave((o1, e1) =>
                {
                    context.Assert.IsNotNull(e1.Error);
                    context.Assert.Success();
                }
                                                       );
#else
                try
                {
                    e.Object[0].GrandChildren[0].Save();
                    context.Assert.Fail();
                }
                catch (InvalidOperationException ex)
                {
                    context.Assert.Success();
                }
#endif
            });

            context.Complete();
        }
Ejemplo n.º 2
0
        public void After_Saved_FetchedList_should_contain_same_number_of_items()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var fetchedList = (MockList)e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(fetchedList);
                context.Assert.AreEqual(1, fetchedList.Count);

                fetchedList[0].Name = "saving";
                fetchedList.Saved  += (o2, e2) =>
                {
                    context.Assert.IsNotNull(e2.NewObject);
                    var savedList = (MockList)e2.NewObject;

                    context.Assert.AreEqual(fetchedList.Count, savedList.Count);

                    context.Assert.Success();
                };
                fetchedList.BeginSave();
            });

            context.Complete();
        }
Ejemplo n.º 3
0
            public Guid Create(Guid ownerId, string name, string description, bool isPrivate)
            {
                var account = this.Storage.AccountStorage.GetMock(ownerId);
                var list    = new MockList
                {
                    Description = description,
                    IsPersonnal = false,
                    IsPrivate   = isPrivate,
                    Name        = name,
                    Owner       = ownerId,
                    Members     = new HashSet <Guid> {
                        ownerId
                    },
                    Followers = new HashSet <Guid> {
                        ownerId
                    },
                    Messages = new List <Guid>()
                };
                var id = Guid.NewGuid();

                account.AllFollowedLists.Add(id);
                if (!isPrivate)
                {
                    account.PublicOwnedLists.Add(id);
                    account.PublicFollowedLists.Add(id);
                }

                account.AllOwnedLists.Add(id);
                account.MemberOfLists.Add(id);
                this.ListFromId.Add(id, list);

                return(id);
            }
Ejemplo n.º 4
0
        public void After_Saved_FetchedList_Items_should_contain_same_values_and_Marked_NotDirty()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var fetchedList = (MockList)e.Object;

                context.Assert.AreEqual("c2", fetchedList[0].Name);
                context.Assert.AreEqual("Child_Fetch", fetchedList[0].DataPortalMethod);

                fetchedList[0].Name = "saving";
                context.Assert.IsTrue(fetchedList[0].IsDirty);

                fetchedList.Saved += (o2, e2) =>
                {
                    context.Assert.IsNotNull(e2.NewObject);
                    var savedList = (MockList)e2.NewObject;

                    context.Assert.AreEqual(fetchedList[0].Id, savedList[0].Id);
                    context.Assert.AreEqual(fetchedList[0].Name, savedList[0].Name);

                    context.Assert.AreEqual("Child_Update", savedList[0].DataPortalMethod);
                    context.Assert.IsFalse(savedList[0].IsDirty);

                    context.Assert.AreEqual(fetchedList[0].GrandChildren.Count, savedList[0].GrandChildren.Count);

                    context.Assert.Success();
                };
                fetchedList.BeginSave();
            });

            context.Complete();
        }
Ejemplo n.º 5
0
        public void FetchAll_Loads_GrandChildren_with_correct_Ids()
        {
            var context = GetContext();

            MockList.FetchAll((o, e) =>
            {
                var list = (MockList)e.Object;

                var expectedGrandChildIds =
                    new[]
                {
                    GrandChildList.GrandChildId1,
                    GrandChildList.GrandChildId2,
                    GrandChildList.GrandChildId3
                };

                for (int index = 0; index < list.Count; index++)
                {
                    var child = list[index];
                    context.Assert.IsNotNull(child.GrandChildren);
                    context.Assert.AreEqual(1, child.GrandChildren.Count);
                    context.Assert.AreEqual(expectedGrandChildIds[index], child.GrandChildren[0].Id);
                    context.Assert.AreEqual("Child_Fetch", child.GrandChildren[0].DataPortalMethod);
                }

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 6
0
        public MockList CreateMockObject()
        {
            var _listMockObject = new MockList()
            {
                Title              = "ListTitle",
                Description        = "Description",
                BaseType           = 1,
                EnableContentTypes = true,
                VersioningEnbabled = false
            };

            List <MockContentType> _contentTypeRefs = new List <MockContentType>();

            MockContentType _cti1 = new MockContentType()
            {
                ID   = "0x0101000728167cd9c94899925ba69c4af6743e01",
                Name = "SAMPLE1 CONTENT TYPE"
            };

            MockContentType _cti2 = new MockContentType()
            {
                ID   = "0x0101000728167cd9c94899925ba69c4af6743e02",
                Name = "SAMPLE1 CONTENT TYPE"
            };

            _contentTypeRefs.Add(_cti1);
            _contentTypeRefs.Add(_cti2);

            _listMockObject.ContentTypes = _contentTypeRefs;

            return(_listMockObject);
        }
 public void SetUp()
 {
     _readOnlyTestee          = new MockList <int>();
     _mutableTestee           = new MockListMutable <int>();
     _readOnlyNonGeneric      = _readOnlyTestee;
     _mutableNonGeneric       = _mutableTestee;
     _backList                = CollectionTestUtils.MakeTestList <int>(_size);
     _readOnlyTestee.TrueList = _backList;
     _mutableTestee.TrueList  = _backList;
 }
Ejemplo n.º 8
0
        public void FetchAll_Returns_all_3_Elements_and_does_not_throw_any_Exceptions()
        {
            var context = GetContext();

            MockList.FetchAll((o, e) =>
            {
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(e.Object);
                context.Assert.AreEqual(3, e.Object.Count);
                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 9
0
        public void FetchByName_INVALID_Returns_Empty_List()
        {
            var context = GetContext();

            MockList.FetchByName("INVALID", (o, e) =>
            {
                var list = (MockList)e.Object;

                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(list);
                context.Assert.AreEqual(0, list.Count);

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 10
0
        public void FetchByName_c2_Returns_Element_with_correct_Id_Marked_NotNew_and_NotDirty()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var list = (MockList)e.Object;

                context.Assert.AreEqual(MockList.MockEditableChildId2, list[0].Id);
                Assert.AreEqual("Child_Fetch", list[0].DataPortalMethod);
                context.Assert.IsFalse(list[0].IsNew);
                context.Assert.IsFalse(list[0].IsDirty);

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 11
0
        public void FetchByName_c2_Returns_one_Element_with_name_c2_and_correct_Id()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var list = (MockList)e.Object;

                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(list);
                context.Assert.AreEqual(1, list.Count);
                context.Assert.AreEqual("c2", list[0].Name);

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 12
0
        public void FetchByName_c2_Returns_Element_with_one_GrandChild()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var list  = (MockList)e.Object;
                var child = list[0];
                context.Assert.AreEqual(1, child.GrandChildren.Count);
                context.Assert.AreEqual(GrandChildList.GrandChildId2, child.GrandChildren[0].Id);
                Assert.AreEqual("Child_Fetch", child.GrandChildren[0].DataPortalMethod);
                context.Assert.IsFalse(child.GrandChildren[0].IsNew);
                context.Assert.IsFalse(child.GrandChildren[0].IsDirty);

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 13
0
        public void After_Saved_GrandChild_should_be_NotDirty_and_should_have_same_value_as_Fetched_GrandChild()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                var fetchedList = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(e.Object);
                context.Assert.AreEqual(1, e.Object.Count);
                context.Assert.AreEqual("c2", e.Object[0].Name);

                var fetchedGrandChild = fetchedList[0].GrandChildren[0];

                context.Assert.AreEqual("Child_Fetch", fetchedGrandChild.DataPortalMethod);

                fetchedGrandChild.Name = "saving";
                context.Assert.IsTrue(fetchedGrandChild.IsDirty);

                fetchedList.Saved += (o3, e3) =>
                {
                    //context.Assert.IsNull(e3.Error);
                    context.Assert.IsNotNull(e3.NewObject);

                    var savedList = (MockList)e3.NewObject;
                    context.Assert.IsNotNull(savedList);
                    if (savedList != null)
                    {
                        var savedGrandChild = savedList[0].GrandChildren[0];
                        context.Assert.AreEqual("Child_Update", savedGrandChild.DataPortalMethod);
                        context.Assert.IsFalse(savedGrandChild.IsDirty);
                        context.Assert.AreEqual(fetchedGrandChild.Name, savedGrandChild.Name);
                        context.Assert.AreEqual(fetchedGrandChild.Id, savedGrandChild.Id);//Guids used - otherwisewe would not test for this
                        context.Assert.Success();
                    }
                };

                fetchedList.BeginSave();
            });

            context.Complete();
        }
Ejemplo n.º 14
0
        public void FetchAll_Returns_Elements_with_correctly_assigned_Ids()
        {
            var context = GetContext();

            MockList.FetchAll((o, e) =>
            {
                var list = (MockList)e.Object;
                context.Assert.AreEqual(MockList.MockEditableChildId1, list[0].Id);
                context.Assert.AreEqual("Child_Fetch", list[0].DataPortalMethod);

                context.Assert.AreEqual(MockList.MockEditableChildId2, list[1].Id);
                context.Assert.AreEqual("Child_Fetch", list[1].DataPortalMethod);

                context.Assert.AreEqual(MockList.MockEditableChildId3, list[2].Id);
                context.Assert.AreEqual("Child_Fetch", list[2].DataPortalMethod);

                context.Assert.Success();
            });

            context.Complete();
        }
Ejemplo n.º 15
0
        public void Save_on_GrandChildList_Item_Throws_InvalidOperationException()
        {
            var context = GetContext();

            MockList.FetchByName("c2", (o, e) =>
            {
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(e.Object);
                try
                {
                    e.Object[0].GrandChildren[0].Save();
                    context.Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                    context.Assert.Success();
                }
            });

            context.Complete();
        }
Ejemplo n.º 16
0
        public void TestRemoveIndexed()
        {
            AbstractList <String> list = new MockList <String>();

            try
            {
                list.Remove(0);
                Assert.Fail("should throw NotSupportedException");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                list.Set(0, null);
                Assert.Fail("should throw NotSupportedException");
            }
            catch (NotSupportedException)
            {
            }
        }
Ejemplo n.º 17
0
            public Guid Create(Guid adminId, string name, string description, bool bypassNameReservation = false)
            {
                var user = this.Storage.UserStorage.GetMock(adminId);

                if (this.IdFromName.ContainsKey(name))
                {
                    throw new AccountAlreadyExists();
                }

                var id = Guid.NewGuid();
                user.Accounts.Add(id);
                this.IdFromName.Add(name, id);
                var personalList = new MockList
                    {
                        Description = "Personal list of " + name,
                        Followers = new HashSet<Guid> { id },
                        Name = name,
                        IsPersonnal = true,

                        // TODO: ?
                        IsPrivate = true,
                        Members = new HashSet<Guid> { id },
                        Owner = id,
                        Messages = new List<Guid>()
                    };
                this.Storage.ListStorage.ListFromId.Add(id, personalList);
                var account = new MockAccount
                    {
                        Admin = adminId,
                        Description = description,
                        Name = name,
                        Users = new HashSet<Guid> { adminId },

                        // TODO: Is the personal list here ?
                        AllFollowedLists = new HashSet<Guid> { id },
                        AllOwnedLists = new HashSet<Guid> { id },
                        MemberOfLists = new HashSet<Guid> { id },
                        PersonalList = id,
                        PublicFollowedLists = new HashSet<Guid>(),
                        Messages = new HashSet<Guid>(),
                        TaggedMessages = new HashSet<Guid>(),
                        PublicOwnedLists = new HashSet<Guid>()
                    };
                this.AccountFromId.Add(id, account);

                return id;
            }
Ejemplo n.º 18
0
            public Guid Create(Guid adminId, string name, string description, bool bypassNameReservation = false)
            {
                var user = this.Storage.UserStorage.GetMock(adminId);

                if (this.IdFromName.ContainsKey(name))
                {
                    throw new AccountAlreadyExists();
                }

                var id = Guid.NewGuid();

                user.Accounts.Add(id);
                this.IdFromName.Add(name, id);
                var personalList = new MockList
                {
                    Description = "Personal list of " + name,
                    Followers   = new HashSet <Guid> {
                        id
                    },
                    Name        = name,
                    IsPersonnal = true,

                    // TODO: ?
                    IsPrivate = true,
                    Members   = new HashSet <Guid> {
                        id
                    },
                    Owner    = id,
                    Messages = new List <Guid>()
                };

                this.Storage.ListStorage.ListFromId.Add(id, personalList);
                var account = new MockAccount
                {
                    Admin       = adminId,
                    Description = description,
                    Name        = name,
                    Users       = new HashSet <Guid> {
                        adminId
                    },

                    // TODO: Is the personal list here ?
                    AllFollowedLists = new HashSet <Guid> {
                        id
                    },
                    AllOwnedLists = new HashSet <Guid> {
                        id
                    },
                    MemberOfLists = new HashSet <Guid> {
                        id
                    },
                    PersonalList        = id,
                    PublicFollowedLists = new HashSet <Guid>(),
                    Messages            = new HashSet <Guid>(),
                    TaggedMessages      = new HashSet <Guid>(),
                    PublicOwnedLists    = new HashSet <Guid>()
                };

                this.AccountFromId.Add(id, account);

                return(id);
            }
Ejemplo n.º 19
0
            public Guid Create(Guid ownerId, string name, string description, bool isPrivate)
            {
                var account = this.Storage.AccountStorage.GetMock(ownerId);
                var list = new MockList
                    {
                        Description = description,
                        IsPersonnal = false,
                        IsPrivate = isPrivate,
                        Name = name,
                        Owner = ownerId,
                        Members = new HashSet<Guid> { ownerId },
                        Followers = new HashSet<Guid> { ownerId },
                        Messages = new List<Guid>()
                    };
                var id = Guid.NewGuid();
                account.AllFollowedLists.Add(id);
                if (!isPrivate)
                {
                    account.PublicOwnedLists.Add(id);
                    account.PublicFollowedLists.Add(id);
                }

                account.AllOwnedLists.Add(id);
                account.MemberOfLists.Add(id);
                this.ListFromId.Add(id, list);

                return id;
            }