Esempio n. 1
0
        protected virtual void DataStore_Add_Item_Adds_Item()
        {
            // Arrange
            FooModel item = _dataStore.Create();

            item.AutoPopulate();

            // Act
            _dataStore.Add(item);
            _dataStore.SaveChanges();
            var result = GetItemById(item.ID);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(item.ID, result.ID);
            Assert.AreEqual(item.Title, result.Title);
            Assert.AreEqual(item.CreateDate.ToString(),
                            result.CreateDate.Kind == DateTimeKind.Utc
                    ? result.CreateDate.ToLocalTime().ToString()
                    : result.CreateDate.ToString());
            Assert.AreEqual(item.Content, result.Content);
            if (_dataStore.SupportsComplexStructures)
            {
                Assert.IsNotNull(result.Comments);
                Assert.AreEqual(item.Comments.Count, result.Comments.Count);
                try
                {
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault(), result.Comments.OrderBy(c => c.ID).FirstOrDefault());
                }
                catch
                {
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().ID, result.Comments.OrderBy(c => c.ID).FirstOrDefault().ID);
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().Author, result.Comments.OrderBy(c => c.ID).FirstOrDefault().Author);
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().Message, result.Comments.OrderBy(c => c.ID).FirstOrDefault().Message);
                }
            }

            // cleanup
            CleanOutItemFromStore(item);
        }
Esempio n. 2
0
        protected virtual void DataStore_Query_For_Item_Returns_Result()
        {
            // Arrange
            FooModel item = _dataStore.Create();

            item.AutoPopulate();
            AddItemToStore(item);
            SaveChanges();

            // Act
            var result = _dataStore.SingleOrDefault(it => it.ID == item.ID);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(item.ID, result.ID);
            Assert.AreEqual(item.Title, result.Title);
            Assert.AreEqual(GetLocalDateString(item.CreateDate), GetLocalDateString(result.CreateDate));
            Assert.AreEqual(item.Content, result.Content);
            if (_dataStore.SupportsComplexStructures)
            {
                Assert.IsNotNull(result.Comments);
                Assert.AreEqual(item.Comments.Count, result.Comments.Count);
                try
                {
                    Assert.AreEqual(item.Comments.FirstOrDefault(), result.Comments.FirstOrDefault());
                }
                catch
                {
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().ID, result.Comments.OrderBy(c => c.ID).FirstOrDefault().ID);
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().Author, result.Comments.OrderBy(c => c.ID).FirstOrDefault().Author);
                    Assert.AreEqual(item.Comments.OrderBy(c => c.ID).FirstOrDefault().Message, result.Comments.OrderBy(c => c.ID).FirstOrDefault().Message);
                }
            }

            // cleanup
            CleanOutItemFromStore(item);
        }