Exemplo n.º 1
0
        public void DataRepository_Initialisation_AutomaticallyFillRepository()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();

            //Assert: The size is more than zero.
            Assert.AreNotEqual(collection, 0);
        }
Exemplo n.º 2
0
        public void DataRepository_InsertionOfUniqueItem_IncreasesSizeByOne()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();
            int Collection_Size = collection.Count;

            //Act: a create is requested
            collection.Create(new MockDataUnit { key = 4, attrTwo="Entry 4", attrThree=4});

            //Assert: The size of the collection has increased by one.
            Assert.AreEqual(Collection_Size+1, collection.Count);
        }
Exemplo n.º 3
0
        public void DataRepository_InsertionOfExistingItem_DoesNotIncreaseSize()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();
            int Collection_Size = collection.Count;

            //Act: a create is requested for an existing entry
            collection.Create(new MockDataUnit { key = 0, attrTwo = "Entry 0", attrThree = 0 });

            //Assert: The size of the collection has not changed.
            Assert.AreEqual(Collection_Size, collection.Count);
        }
Exemplo n.º 4
0
        public void DataRepository_UpdatingMalicousSqlHtml_WillConvertToSafe()
        {
            //Arrange: data repository and data unit with malicous and html code is created.
            MockSqlRepository collection = new MockSqlRepository();
            string malicious = "<div>Hello, world!</div>');DROP TABLE dbo.Users;--";
            MockDataUnit unit = new MockDataUnit { key = 6, attrTwo = malicious, attrThree = 4 };

            //Act: an update is requested
            collection.Update(unit);

            //Assert: The entry that was added no longer contains sql injection code
            Assert.AreNotEqual(malicious, unit.attrTwo);
        }
Exemplo n.º 5
0
        public void DataRepository_UpdatingMalicousHtml_WillConvertToSafe()
        {
            //Arrange: A data repository and malicious entry are created
            MockSqlRepository collection = new MockSqlRepository();
            string malicious = "<div>Hello, world!</div>";
            MockDataUnit unit = new MockDataUnit { key = 5, attrTwo = malicious, attrThree = 3 };

            //Act: an update is requested
            collection.Update(unit);

            //Assert: The entry that was added no longer contains the malicious code.
            Assert.AreNotEqual(malicious, unit.attrTwo);
        }
Exemplo n.º 6
0
        public void DataRepository_WithCorruptedEntries_WillConvertToSafe()
        {
            //Arrange: a data repository with corrupt additions made directly to it.
            string malicious = "<div>Hello, world!</div>');DROP TABLE dbo.Users;--";
            MockDataUnit unit = new MockDataUnit { attrTwo = malicious};
            MockSqlRepository collection = new MockSqlRepository();
            collection.Add(unit);

            //Act: a scrub is performed on the collection
            collection.Scrub();

            //Assert: the unit contained in the repository no longer has malicious member.
            Assert.AreNotEqual(malicious, unit.attrTwo);
        }
Exemplo n.º 7
0
        public void DataRepository_InvalidDeletion_DoesNotDecreaseCollectionSize()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();
            int Collection_Size = collection.Count;

            //Act: a deletion is targeted for non existing entry
            collection.Delete(new MockDataUnit { key = 0, attrTwo = "Entry 1" });

            //Assert: The size of the collection has not changed
            Assert.AreEqual(Collection_Size, collection.Count);
        }
Exemplo n.º 8
0
        public void DataRepository_ValidDeletion_DecreasesCollectionSize()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();
            int Collection_Size = collection.Count;

            //Act: a deletion is targeted for existing entry
            collection.Delete(new MockDataUnit { key=0, attrTwo="Entry 0"});

            //Assert: The size of the collection has decreased by one.
            Assert.AreEqual(Collection_Size-1, collection.Count);
        }
Exemplo n.º 9
0
        public void DataRepository_Update_CollectionChanges()
        {
            //Arrange: Initialise a data repository
            MockSqlRepository collection = new MockSqlRepository();

            //Act: The entry is targeted for update
            collection.Update(new MockDataUnit { attrOne=0, attrTwo="Entry 0", attrThree=5});

            //Assert: The first entry has been changed to two
            Assert.AreEqual(collection.FirstOrDefault().attrThree,5);
        }