public void When_Ignore_is_used_with_the_ClassToExcelAttribute_data_is_not_written_to_the_file() { // Arrange // Arrange // Arrange var originalData = new List <IgnoreTestsExampe1>(); originalData.Add(new IgnoreTestsExampe1 { Id = 1, Name = "Some Name" }); originalData.Add(new IgnoreTestsExampe1 { Id = 2, Name = "Some Other Name" }); // Act // Act // Act // Using a different class with similar properties WITHOUT the ignore attribute to prove that nothing was truly written // if we used the same class the reader would not even look for the Name field. var saveAndReadHelper = new SaveAndReadHelper <IgnoreTestsExampe1, IgnoreTestsExampe2>(); List <IgnoreTestsExampe2> actualList = saveAndReadHelper.SaveAndRead(originalData, true); // Assert // Assert // Assert IgnoreTestsExampe2 data1 = actualList.FirstOrDefault(w => w.Id == 1); Assert.IsNotNull(data1, "Unable to find Id == 1 so data was not written properly"); Assert.IsTrue(string.IsNullOrEmpty(data1.Name)); IgnoreTestsExampe2 data2 = actualList.FirstOrDefault(w => w.Id == 2); Assert.IsNotNull(data2, "Unable to find Id == 2 so data was not written properly"); Assert.IsTrue(string.IsNullOrEmpty(data2.Name)); }
public void When_data_has_a_private_setter_data_is_written_to_the_file() { // If you want to ignore a property, users should use the Ignore property on the ClassToExcelAttribute // I'm testing this because the reader and writer use the same base class method for reflecting over properties. // Arrange // Arrange // Arrange var originalData = new List <IgnoreTestsExampe3>(); originalData.Add(new IgnoreTestsExampe3 { Id = 1 }); originalData.Add(new IgnoreTestsExampe3 { Id = 2 }); // Act // Act // Act // Using a different class with similar properties WITHOUT the ignore attribute to prove that nothing was truly written // if we used the same class the reader would not even look for the Name field. var saveAndReadHelper = new SaveAndReadHelper <IgnoreTestsExampe3, IgnoreTestsExampe2>(); List <IgnoreTestsExampe2> actualList = saveAndReadHelper.SaveAndRead(originalData, true); // Assert // Assert // Assert IgnoreTestsExampe2 data1 = actualList.FirstOrDefault(w => w.Id == 1); Assert.IsNotNull(data1, "Unable to find Id == 1 so data was not written properly"); Assert.AreEqual("Some Name", data1.Name); IgnoreTestsExampe2 data2 = actualList.FirstOrDefault(w => w.Id == 2); Assert.IsNotNull(data2, "Unable to find Id == 2 so data was not written properly"); Assert.AreEqual("Some Name", data2.Name); }