public void CopyPropertyValuesFrom_NullSource_SourceStaysNull() { // Arrange var now = DateTime.UtcNow; var testObj = new { Id = SampleNumbers.int2, name = SampleStrings.str1, dateTime = now, comment = SampleStrings.str2, test = SampleStrings.str3, Trouble = SampleNumbers.int1 }; #pragma warning disable CS8600 // Testing null value to non-nullable type. SampleObject testClass = null; #pragma warning restore CS8600 // Act testClass.CopyPropertyValuesFrom(testObj); // Assert testClass.Should().BeNull("Source will not be initialized."); }
public void CopyPropertyValuesFrom_FieldsAreFound_ApplyChanges() { // Arrange var now = DateTime.UtcNow; var testObj = new { Id = SampleNumbers.int1, Name = SampleStrings.str1, DateTime = now, Comment = SampleStrings.str2, Hidden = SampleStrings.str3, Semi = SampleStrings.str4 }; var testClass = new SampleObject(SampleNumbers.int2, SampleStrings.str4, DateTime.Today, SampleStrings.str5, SampleStrings.str6, SampleStrings.str7); // Act testClass.CopyPropertyValuesFrom(testObj); // Assert testClass.Id.Should().Be(SampleNumbers.int1); testClass.Name.Should().Be(SampleStrings.str1); testClass.DateTime.Should().Be(now); testClass.Comment.Should().Be(SampleStrings.str2); testClass.GetHidden().Should().Be(SampleStrings.str6, "private properties cannot be altered."); testClass.GetSemi().Should().Be(SampleStrings.str7, "protected properties cannot be altered."); }
public void CopyPropertyValuesFrom_NullDestination_KeepValues() { // Arrange var now = DateTime.UtcNow; object?testObj = null; var testClass = new SampleObject(SampleNumbers.int1, SampleStrings.str4, now, SampleStrings.str5, SampleStrings.str6, SampleStrings.str7); testClass.trouble = testClass.Trouble = testClass.TROUBLE = SampleNumbers.int4; // Act testClass.CopyPropertyValuesFrom(testObj); // Assert testClass.Id.Should().Be(SampleNumbers.int1); testClass.Name.Should().Be(SampleStrings.str4); testClass.DateTime.Should().Be(now); testClass.trouble.Should().Be(SampleNumbers.int4); testClass.Trouble.Should().Be(SampleNumbers.int4); testClass.TROUBLE.Should().Be(SampleNumbers.int4); }
public void CopyPropertyValuesFrom_FieldsNotFound_DiscardChanges() { // Arrange var now = DateTime.UtcNow; var today = DateTime.Today; var testObj = new { ID = SampleNumbers.int2, name = SampleStrings.str1, dateTime = now, comment = SampleStrings.str2, test = SampleStrings.str3, Trouble = SampleNumbers.int1 }; var testClass = new SampleObject(SampleNumbers.int1, SampleStrings.str4, today, SampleStrings.str5, SampleStrings.str6, SampleStrings.str7); testClass.trouble = testClass.Trouble = testClass.TROUBLE = SampleNumbers.int4; // Act testClass.CopyPropertyValuesFrom(testObj); // Assert testClass.Id.Should().Be(SampleNumbers.int1); testClass.Name.Should().Be(SampleStrings.str4); testClass.DateTime.Should().Be(today); testClass.trouble.Should().Be(SampleNumbers.int4); testClass.Trouble.Should().Be(SampleNumbers.int1); testClass.TROUBLE.Should().Be(SampleNumbers.int4); }