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); }
public void DataRepository_InsertingMalicousSql_WillConvertToSafe() { //Arrange: data repository and data unit with sql injection is created. MockSqlRepository collection = new MockSqlRepository(); string malicious = "attribute');DROP TABLE dbo.Users;--"; MockDataUnit unit = new MockDataUnit { key = 6, attrTwo = malicious, attrThree = 4 }; //Act: a create is requested collection.Create(unit); //Assert: The entry that was added no longer contains sql injection code Assert.AreNotEqual(malicious, unit.attrTwo); }
public void DataRepository_CreatingMalicousHtml_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: a create is requested collection.Create(unit); //Assert: The entry that was added no longer contains the malicious code. Assert.AreNotEqual(malicious, unit.attrTwo); }
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); }