public void IfValueIsOverwrittenTheNewValueIsRead() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_basePublicField", "Hello"); builder.SetMember("_basePublicField", "Hi!"); builder.GetMember <string>("_basePublicField").Should().Be("Hi!"); }
public void ValuesCanBeRead() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_basePublicField", "Hello"); builder.SetMember("BasePublicProperty", 42); builder.GetMember <string>("_basePublicField").Should().Be("Hello"); builder.GetMember <int>("BasePublicProperty").Should().Be(42); }
public void BeforeInstantiation_ValueCanBeSetTwice() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_childPrivateField", "Ahoy"); builder.SetMember("_childPrivateField", "Hello"); var instance = builder.GetInstance(); instance.GetChildPrivateField().Should().Be("Hello"); }
public void PrivateChildValuesCanBeSet() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_childPrivateField", "Hello"); builder.SetMember("ChildPrivateProperty", 42); var instance = builder.GetInstance(); instance.GetChildPrivateField().Should().Be("Hello"); instance.GetChildPrivateProperty().Should().Be(42); }
public void ValuesCanBeRead_AfterCreation() { var builder = new InstanceBuilder <TestClass>(true); //note that we enable after creation manipulation builder.SetMember("_basePublicField", "Hello"); builder.SetMember("BasePublicProperty", 42); var instance = builder.GetInstance(); builder.GetMember <string>("_basePublicField").Should().Be("Hello"); builder.GetMember <int>("BasePublicProperty").Should().Be(42); }
public void PublicBaseValuesCanBeSet() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_basePublicField", "Hello"); builder.SetMember("BasePublicProperty", 42); var instance = builder.GetInstance(); instance._basePublicField.Should().Be("Hello"); instance.BasePublicProperty.Should().Be(42); }
public static object DeserializerForOldVersion(IShapeshifterReader reader) { var builder = new InstanceBuilder <IndividualCustomer>(); builder.SetMember("Name", reader.Read <string>("Name")); var oldAddress = reader.Read <string>("HomeAddress"); builder.SetMember("HomeAddress", ConvertStringToAddress(oldAddress)); builder.SetMember("Orders", reader.Read <List <Order> >("Orders")); return(builder.GetInstance()); }
public static MyClassWithComplexField Deserialize(IShapeshifterReader reader) { var builder = new InstanceBuilder <MyClassWithComplexField>(reader); builder.SetMember("_myIntField", 44); return(builder.GetInstance()); }
public void SetNonExistingMember_ShouldThrowException() { var builder = new InstanceBuilder <TestClass>(); Action action = () => builder.SetMember("noSuchField", "Hello"); action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.CannotFindFieldOrPropertyId); }
public void SetMemberAfterGetInstance_EnabledModification_ShouldModifyTheValue() { var builder = new InstanceBuilder <TestClass>(true); var instance = builder.GetInstance(); builder.SetMember("_childPrivateField", "Hello"); instance.GetChildPrivateField().Should().Be("Hello"); }
public void SetWrongValue_ShouldThrowException() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_childPrivateField", 42); Action action = () => builder.GetInstance(); action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.FailedToSetValueId); }
public void SetMemberAfterGetInstance_ShouldThrowException() { var builder = new InstanceBuilder <TestClass>(); builder.GetInstance(); Action action = () => builder.SetMember("_childPrivateField", "Hello"); action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.InstanceAlreadyGivenAwayId); }
public void GetMember_AfterCreation_ShouldThrow() { var builder = new InstanceBuilder <TestClass>(); builder.SetMember("_basePublicField", "Hello"); var instance = builder.GetInstance(); Action action = () => builder.GetMember <string>("_basePublicField"); action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.InstanceAlreadyGivenAwayId); }
public void InstancePopulatedFromReaderModifiedAfterwards_ButBeforeCreation() { var objectProperties = new ObjectProperties(new Dictionary <string, object>() { { Constants.TypeNameKey, "TestClass" }, { Constants.VersionKey, (long)1 }, { "_basePrivateField", "Hello" }, { "BasePrivateProperty", "Invalid value" }, { "_childPrivateField", "Seeya" }, { "ChildPrivateProperty", 43 }, }); var reader = new ShapeshifterReader(objectProperties); var builder = new InstanceBuilder <TestClass>(reader); builder.SetMember("BasePrivateProperty", 1); var instance = builder.GetInstance(); instance.GetBasePrivateProperty().Should().Be(1); }