public void Test_Construct_WithNullFileName_ShouldDefaultFileName() { //---------------Set up test pack------------------- const string fileName = null; //---------------Assert Precondition---------------- Assert.IsNull(fileName); //---------------Execute Test ---------------------- IPropDef propDef = GetPropDef(); var valueGenerator = new ValidValueGeneratorTextFile(propDef, fileName); //---------------Test Result ----------------------- Assert.AreEqual(propDef.PropertyName + ".txt", valueGenerator.FileName); }
public void Test_Construct_WithFileName_StoresFileName() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var valueGenerator = new ValidValueGeneratorTextFile(GetPropDef(), GoodFileName); //---------------Test Result ----------------------- Assert.AreSame(GoodFileName, valueGenerator.FileName); Assert.IsNotNull(ValidValueGeneratorTextFile.CachedSampleValues); Assert.AreEqual(0, ValidValueGeneratorTextFile.CachedSampleValues.Count); }
public void Test_Construct_WithEmptyFileName_ShouldDefaultFileName() { //---------------Set up test pack------------------- const string fileName = null; //---------------Assert Precondition---------------- Assert.IsNull(fileName); //---------------Execute Test ---------------------- IPropDef propDef = GetPropDef(); var valueGenerator = new ValidValueGeneratorTextFile(propDef, ""); //---------------Test Result ----------------------- Assert.AreEqual(propDef.PropertyName + ".txt", valueGenerator.FileName); }
public void Test_GenerateValue_WhenFileNotExists_ShouldThrowException() { //---------------Set up test pack------------------- var valueGenerator = new ValidValueGeneratorTextFile(GetPropDef(), BadFileName); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { var value = valueGenerator.GenerateValidValue(); Assert.Fail("Expected to throw a FileNotFoundException"); } //---------------Test Result ----------------------- catch (FileNotFoundException ex) { StringAssert.Contains( "Could not find file", ex.Message); } }
public void Test_GenerateValue_WhenFileIsEmpty_ShouldThrowException() { //---------------Set up test pack------------------- CreateFile(GoodFileName); var valueGenerator = new ValidValueGeneratorTextFile(GetPropDef(), GoodFileName); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { var value = valueGenerator.GenerateValidValue(); Assert.Fail("Expected to throw a HabaneroApplicationException"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { StringAssert.Contains( "The test data file " + GoodFileName + " does not contain any data to use for random data generation.", ex.Message); } }