public void MyTestInitialize() { try { // Creating a package will set the factory service provider. this.package = new StyleCopVSPackage(); this.mockServiceProvider = new Mock <IServiceProvider>(); // Creates a dummy violation (In visual studio the violation is displayed in Error List panel) this.violation = CreateDummyViolationInfo(); Assert.IsNotNull(this.package, "this.package is null"); PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage))); StyleCopCore core = (StyleCopCore)actual.GetFieldOrProperty("Core"); Assert.IsNotNull(core, "core is null"); core.DisplayUI = false; this.taskUnderTest = new ViolationTask(this.package, this.violation, null); this.taskUnderTestShell = this.taskUnderTest; } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
public void ViolationTaskConstructorTest() { try { PrivateObject actual = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask))); ViolationInfo violationInfo = (ViolationInfo)actual.GetFieldOrProperty("violation"); Assert.IsNotNull(violationInfo, "Constructor didn't set internal field 'violation'"); Assert.AreEqual( this.violation.File, this.taskUnderTestShell.Document, "Constructor failed to set up property Document"); Assert.AreEqual( this.violation.LineNumber, this.taskUnderTestShell.Line + 1, "Constructor failed to set up property Line"); Assert.AreEqual( this.violation.Description, this.taskUnderTestShell.Text, "Constructor failed to set up property Text"); Assert.AreEqual(0, this.taskUnderTestShell.Column + 1, "Constructor failed to set up property Column"); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
private static ViolationInfo CreateDummyViolationInfo() { ViolationInfo violation = new ViolationInfo() { File = @"c:\MyFile.cs", LineNumber = 666, Description = "My Description" }; return(violation); }
public void MyTestInitialize() { // Creating a package will set the factory service provider. this.package = new StyleCopVSPackage(); this.mockServiceProvider = new Mock <IServiceProvider>(MockBehavior.Strict); this.violation = CreateDummyViolationInfo(); this.package.Core.DisplayUI = false; this.taskUnderTest = new ViolationTask(this.package, this.violation, null); this.taskUnderTestShell = taskUnderTest; }