Пример #1
0
        public void Add()
        {
            // Arrange
            FakeDbContext db = new FakeDbContext();

            db.AddSet(TestData.Contacts);
            int newContactId = TestData.Contacts.Select(c => c.ContactId)
                               .DefaultIfEmpty(0).Max() + 1;
            var newContact = new Contact
            {
                ContactId    = newContactId,
                FirstName    = "Anita",
                Surname      = "Bath",
                EmailAddress = "*****@*****.**"
            };

            // Act
            db.Add(newContact);
            var addedContact = db.Find <Contact>(newContactId);

            // Assert
            Assert.AreEqual("Bath", addedContact.Surname,
                            "New contact surname check failed!!");
            Assert.AreEqual(1, db.Added.Count,
                            "New contact count check failed!!");
        }
Пример #2
0
        public void Find_StandardPrimaryKey()
        {
            // Arrange
            FakeDbContext db = new FakeDbContext();

            db.AddSet(TestData.Contacts);

            // Act
            var contact2 = db.Find <Contact>(2);
            var contact1 = db.Find <Contact>(1);

            // Assert
            Assert.AreEqual("*****@*****.**", contact1.EmailAddress,
                            "Find - Contact 1 email address check failed!!");
            Assert.AreEqual("*****@*****.**", contact2.EmailAddress,
                            "Find - Contact 2 email address check failed!!");
        }
Пример #3
0
        public void Remove()
        {
            // Arrange
            FakeDbContext db = new FakeDbContext();

            db.AddSet(TestData.Contacts);

            // Act
            var contact2 = db.Find <Contact>(2);

            db.Remove <Contact>(contact2);
            var removedContact = db.Find <Contact>(2);

            // Assert
            Assert.AreEqual(null, removedContact);
            Assert.AreEqual(1, db.Removed.Count);
        }
Пример #4
0
        public void Update()
        {
            // Arrange
            FakeDbContext db = new FakeDbContext();

            db.AddSet(TestData.Contacts);

            // Act
            var contact2 = db.Find <Contact>(2);

            contact2.Title = "Brain Surgeon";
            db.Update <Contact>(contact2);
            var updatedContact = db.Find <Contact>(2);

            // Assert
            Assert.AreEqual("Brain Surgeon", updatedContact.Title,
                            "Updated contact title check failed");
            Assert.AreEqual(1, db.Updated.Count,
                            "Updated contact count check failed");
        }