Пример #1
0
        public void CreditTypeRepository_InsertUpdateDelete()
        {
            // Arrange
            var repo    = new CreditTypeRepository();
            var newItem = new CreditType
            {
                Code         = "TestCode",
                Name         = "TestName",
                IsInactive   = false,
                DisplayOrder = 99
            };
            var item  = repo.Persist(newItem);
            var newId = item.Id;

            // Act for Update
            item.Name         = "XYZ";
            item.Code         = "ABC";
            item.IsInactive   = true;
            item.DisplayOrder = 999;
            item.IsDirty      = true;
            var updatedItem = repo.Persist(item);

            Assert.IsTrue(updatedItem.IsDirty == false);
            Assert.IsTrue(updatedItem.Name == "XYZ");
            Assert.IsTrue(updatedItem.Code == "ABC");
            Assert.IsTrue(updatedItem.IsInactive);
            Assert.IsTrue(updatedItem.DisplayOrder == 999);

            // Assert for Update
            var refetch = repo.Fetch(newId).First();

            Assert.IsTrue(refetch.Name == "XYZ");

            // Clean-up (Act for Delete)
            item.IsMarkedForDeletion = true;
            repo.Persist(item);

            // Assert for Delete
            var result = repo.Fetch(newId);

            Assert.IsFalse(result.Any());
        }
Пример #2
0
        public void CreditTypeRepository_InsertDelete()
        {
            // Arrange
            var repo    = new CreditTypeRepository();
            var newItem = new CreditType
            {
                Code         = "TestCode",
                Name         = "TestName",
                IsInactive   = false,
                DisplayOrder = 99
            };

            // Act for Insert
            var item  = repo.Persist(newItem);
            var newId = item.Id;

            // Assert for Insert - Make sure local object is updated
            Assert.IsTrue(item.Id > 0);
            Assert.IsFalse(item.IsMarkedForDeletion);
            Assert.IsFalse(item.IsDirty);

            // Assert for Insert - Make sure refetched object is correct
            var refetch = repo.Fetch(newId).First();

            Assert.IsTrue(refetch.Id == newId);
            Assert.IsFalse(refetch.IsMarkedForDeletion);
            Assert.IsFalse(refetch.IsDirty);
            Assert.IsTrue(refetch.Code == "TestCode");
            Assert.IsTrue(refetch.Name == "TestName");
            Assert.IsTrue(refetch.IsInactive == false);
            Assert.IsTrue(refetch.DisplayOrder == 99);

            // Clean-up (Act for Delete)
            item.IsMarkedForDeletion = true;
            repo.Persist(item);

            // Assert for Delete
            var result = repo.Fetch(newId);

            Assert.IsFalse(result.Any());
        }
Пример #3
0
        public void CreditTypeRepository_InsertUpdateDelete_Works()
        {
            // Arrange
            var repo = new CreditTypeRepository();
            var testItem = new CreditType
            {
                Name = "TestItem",
                Code = "TestItemCode",
                IsInactive = true,
                DisplayOrder = 99
            };

            // Act - Insert
            var insertedItem = repo.Persist(testItem);
            var newId = insertedItem.CreditTypeId;

            // Assert for Insert
            Assert.IsTrue(newId > 0);
            var existingItem = repo.Fetch(newId).Single();
            Assert.IsTrue(existingItem.Name == "TestItem");
            Assert.IsTrue(existingItem.Code == "TestItemCode");
            Assert.IsTrue(existingItem.IsInactive == true);
            Assert.IsTrue(existingItem.DisplayOrder == 99);

            // Act - Update

            existingItem.Name = "TestItem1";
            existingItem.Code = "TestItemCode1";
            existingItem.IsInactive = false;
            existingItem.DisplayOrder = 10;

            repo.Persist(existingItem);

            // Assert for Update
            var updatedItem = repo.Fetch(newId).Single();
            Assert.IsTrue(updatedItem.Name == "TestItem1");
            Assert.IsTrue(updatedItem.Code == "TestItemCode1");
            Assert.IsTrue(updatedItem.IsInactive == false);
            Assert.IsTrue(updatedItem.DisplayOrder == 10);

            // Act - Delete
            updatedItem.IsMarkedForDeletion = true;
            var deletedItem = repo.Persist(updatedItem);

            // Assert for Delete
            Assert.IsNull(deletedItem);
            var emptyResult = repo.Fetch(newId);
            Assert.IsFalse(emptyResult.Any());
        }
Пример #4
0
        public void CreditTypeRepository_Delete_Deletes()
        {
            // Arrange
            var repo = new CreditTypeRepository();
            var existingItem = repo.Fetch(3).Single();

            // Act
            existingItem.IsMarkedForDeletion = true;
            var deletedItem = repo.Persist(existingItem);

            // Assert for Delete
            Assert.IsNull(deletedItem);
            var emptyResult = repo.Fetch(3);
            Assert.IsFalse(emptyResult.Any());
        }
Пример #5
0
        public void CreditTypeRepository_Update_Updates()
        {
            // Arrange
            var repo = new CreditTypeRepository();
            var existingItem = repo.Fetch(2).Single();

            // Act - Update
            existingItem.Name = "TestItem1";
            existingItem.Code = "TestItemCode1";
            existingItem.IsInactive = false;
            existingItem.DisplayOrder = 10;
            repo.Persist(existingItem);

            // Assert for Update
            var updatedItem = repo.Fetch(2).Single();
            Assert.IsTrue(updatedItem.Name == "TestItem1");
            Assert.IsTrue(updatedItem.Code == "TestItemCode1");
            Assert.IsTrue(updatedItem.IsInactive == false);
            Assert.IsTrue(updatedItem.DisplayOrder == 10);
        }
Пример #6
0
        public void CreditTypeRepository_Insert_Insertss()
        {
            // Arrange
            var repo = new CreditTypeRepository();
            var testItem = new CreditType
            {
                Name = "TestItem",
                Code = "TestItemCode",
                IsInactive = true,
                DisplayOrder = 99
            };

            // Act
            var insertedItem = repo.Persist(testItem);
            var newId = insertedItem.CreditTypeId;

            // Assert
            Assert.IsTrue(newId > 0);
            var existingItem = repo.Fetch(newId).Single();
            Assert.IsTrue(existingItem.Name == "TestItem");
            Assert.IsTrue(existingItem.Code == "TestItemCode");
            Assert.IsTrue(existingItem.IsInactive == true);
            Assert.IsTrue(existingItem.DisplayOrder == 99);
        }