public void SettingFileBadFormat_NotSuccess() { //Arrange var item = new Mock <ITaskItem>(); item.Setup(x => x.GetMetadata("FullPath")).Returns(".\\Resources\\error-prop.setting"); var appSettingStronglyTyped = new AppSettingStronglyTyped { SettingClassName = "ErrorPropSetting", SettingNamespaceName = "MyNamespace", SettingFiles = new[] { item.Object } }; appSettingStronglyTyped.BuildEngine = buildEngine.Object; //Act var success = appSettingStronglyTyped.Execute(); //Assert Assert.IsFalse(success); Assert.AreEqual(errors.Count, 1); Assert.AreEqual(null, appSettingStronglyTyped.ClassNameFile); Assert.AreEqual(1, errors.Count); var error = errors.First(); Assert.AreEqual("Incorrect line format. Valid format prop:type:defaultvalue", error.Message); Assert.AreEqual(1, error.LineNumber); }
public void SettingFileWithMultipleProperty_ClassGeneratedWithMultipleProperty() { //Arrange var item = new Mock <ITaskItem>(); item.Setup(x => x.GetMetadata("FullPath")).Returns($".\\Resources\\complete-prop.setting"); var appSettingStronglyTyped = new AppSettingStronglyTyped { SettingClassName = $"MyCompletePropSetting", SettingNamespaceName = "MyNamespace", SettingFiles = new[] { item.Object } }; appSettingStronglyTyped.BuildEngine = buildEngine.Object; //Act var success = appSettingStronglyTyped.Execute(); //Assert Assert.IsTrue(success); Assert.AreEqual(errors.Count, 0); Assert.AreEqual($"MyCompletePropSetting.generated.cs", appSettingStronglyTyped.ClassNameFile); Assert.IsTrue(File.Exists(appSettingStronglyTyped.ClassNameFile)); Assert.IsTrue(File.ReadLines(appSettingStronglyTyped.ClassNameFile).SequenceEqual(File.ReadLines(".\\Resources\\complete-prop-class.txt"))); //Cleanup File.Delete(appSettingStronglyTyped.ClassNameFile); }
public void SettingInvalidType_NotSuccess() { //Arrange var item = new Mock <ITaskItem>(); item.Setup(x => x.GetMetadata("FullPath")).Returns(".\\Resources\\notvalidtype-prop.setting"); var appSettingStronglyTyped = new AppSettingStronglyTyped { SettingClassName = "ErrorPropSetting", SettingNamespaceName = "MyNamespace", SettingFiles = new[] { item.Object } }; appSettingStronglyTyped.BuildEngine = buildEngine.Object; //Act var success = appSettingStronglyTyped.Execute(); //Assert Assert.IsFalse(success); Assert.AreEqual(errors.Count, 1); Assert.AreEqual(null, appSettingStronglyTyped.ClassNameFile); Assert.AreEqual("Type not supported -> car", errors.First().Message); }
public void EmptySettingFileList_EmptyClassGenerated() { //Arrange var appSettingStronglyTyped = new AppSettingStronglyTyped { SettingClassName = "MySettingEmpty", SettingNamespaceName = "MyNamespace", SettingFiles = new ITaskItem[0] }; appSettingStronglyTyped.BuildEngine = buildEngine.Object; //Act var success = appSettingStronglyTyped.Execute(); //Assert Assert.IsTrue(success); Assert.AreEqual(errors.Count, 0); Assert.AreEqual("MySettingEmpty.generated.cs", appSettingStronglyTyped.ClassNameFile); Assert.IsTrue(File.Exists(appSettingStronglyTyped.ClassNameFile)); Assert.IsTrue(File.ReadLines(appSettingStronglyTyped.ClassNameFile).SequenceEqual(File.ReadLines(".\\Resources\\empty-class.txt"))); //Cleanup File.Delete(appSettingStronglyTyped.ClassNameFile); }