コード例 #1
0
        public void AuthorTest()
        {
            // arrange
            AuthorDAL dal = new AuthorDAL(MagicSetup.Connection);
            // act create
            int rv1 = dal.AuthorCreate("Test1", null, "testlocation1");

            Assert.IsTrue(rv1 > 0, $"AuthorCreate failed rv = {rv1}");

            Author a = dal.AuthorFindByID(rv1);

            Assert.IsNotNull(a, $"AuthorFindByID for ID {rv1} (just created) returned null");
            Assert.IsTrue(a.AuthorName == "Test1", $"AuthorName was expected to be 'Test1' but found {a.AuthorName}");
            Assert.IsFalse(a.AuthorDOB.HasValue, $"AuthorDOB was expected to be null, but had a value");
            Assert.IsTrue(a.AuthorLocation == "testlocation1", $"authorlocation was expected to be 'testlocation1' but was actually '{a.AuthorLocation}'");

            int countofauthors = dal.AuthorsObtainCount();

            Assert.IsTrue(countofauthors > 0, $"AuthorsObtainCount should be greater than 0 it is {countofauthors}");
            List <Author> authors = dal.AuthorsGetAll();

            Assert.IsTrue(authors.Count == countofauthors, $"AuthorsGetAll should have brought back {countofauthors} records, but it only found {authors.Count}");
            DateTime now    = DateTime.Now;
            int      number = dal.AuthorUpdateJust(rv1, "Test1New", now, "newLocation1");

            Assert.IsTrue(number == 1, $"authorUpdateJust was expected to return 1, but actually returned {number}");
            a = dal.AuthorFindByID(rv1);
            Assert.IsNotNull(a, $"AuthorFindByID for ID {rv1} (just updated) returned null");
            Assert.IsTrue(a.AuthorName == "Test1New", $"AuthorName after update was expected to be 'Test1New' but was actually '{a.AuthorName}'");
            Assert.IsTrue(a.AuthorDOB.HasValue, "authorDOB was expected to have a value, but was null");
            Assert.IsTrue(a.AuthorLocation == "newLocation1", $"authorlocation was expected to be 'newLocation1' but was actually '{a.AuthorLocation}'");
            number = dal.AuthorUpdateSafe(rv1, "Test1New", now, "newLocation1", "1", null, "2");
            Assert.IsTrue(number == 1, $"authorUpdateSafe was expected to return 1 but actually returned {number}");
            a = dal.AuthorFindByID(rv1);
            Assert.IsNotNull(a, $"AuthorFindByID for ID {rv1} (just safe updated) returned null");
            Assert.IsTrue(a.AuthorName == "1", $"authorname after safeupdate was expected to be '1', but was '{a.AuthorName}");
            Assert.IsFalse(a.AuthorDOB.HasValue, $"authorDOB after safeupdate was expected to be null, but was not");
            Assert.IsTrue(a.AuthorLocation == "2", $"authorlocation after saftupdate was expected to be '2' but was actually '{a.AuthorLocation}'");
            number = dal.AuthorUpdateSafe(rv1, "1", now, "2", "3", null, "4");
            Assert.IsTrue(number == 0, $"authorupdatesafe was expected to return 0, but it actually returned {number}");

            dal.AuthorDelete(rv1);
        }