public void HasChanged_ReturnsTrue_IfMutuableValueHasBeenMutated() { // Arrange TableEntityContext entityContext = new TableEntityContext(); byte[] bytes = new byte[] { 0x12 }; DynamicTableEntity value = new DynamicTableEntity { PartitionKey = "PK", RowKey = "RK", Properties = new Dictionary <string, EntityProperty> { { "Item", new EntityProperty(bytes) } } }; Type valueType = typeof(DynamicTableEntity); TableEntityValueBinder product = new TableEntityValueBinder(entityContext, value, valueType); bytes[0] = 0xFE; // Act bool hasChanged = product.HasChanged; // Assert Assert.True(hasChanged); }
public TableItem(IDictionary <string, EntityProperty> properties) { _eTag = Guid.NewGuid().ToString(); _timestamp = DateTimeOffset.Now; // Clone properties when persisting, so changes to source value in memory don't affect the persisted // data. _properties = TableEntityValueBinder.DeepClone(properties); }
public void DeepClone_IfBooleanNull_PreservesValue() { // Arrange bool?input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Boolean, property.PropertyType); Assert.Null(property.BooleanValue); }
public void DeepClone_IfStringNull_PreservesValue() { // Arrange string input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.String, property.PropertyType); Assert.Null(property.StringValue); }
public void DeepClone_IfInt64Null_PreservesValue() { // Arrange long?input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Int64, property.PropertyType); Assert.Null(property.Int64Value); }
public void DeepClone_IfString_PreservesValue() { // Arrange string expected = "abc"; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.String, property.PropertyType); Assert.AreSame(expected, property.StringValue); }
public void DeepClone_IfGuid_PreservesValue() { // Arrange Guid expected = Guid.NewGuid(); // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Guid, property.PropertyType); Assert.AreEqual(expected, property.GuidValue); }
public void DeepClone_IfInt64_PreservesValue() { // Arrange long expected = 123; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Int64, property.PropertyType); Assert.AreEqual(expected, property.Int64Value); }
public void DeepClone_IfDateTimeNull_PreservesValue() { // Arrange DateTime?input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.DateTime, property.PropertyType); Assert.Null(property.DateTime); }
public void DeepClone_IfDouble_PreservesValue() { // Arrange double expected = 1.23; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Double, property.PropertyType); Assert.AreEqual(expected, property.DoubleValue); }
public void DeepClone_IfBoolean_PreservesValue() { // Arrange bool?expected = true; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Boolean, property.PropertyType); Assert.AreEqual(expected, property.BooleanValue); }
public void DeepClone_IfDateTime_PreservesValue() { // Arrange DateTime expected = DateTime.Now; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.DateTime, property.PropertyType); Assert.AreEqual(expected, property.DateTime); }
public void DeepClone_IfEmptyBinary_PreservesValue() { // Arrange byte[] expected = new byte[0]; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert Assert.NotNull(property); Assert.AreEqual(EdmType.Binary, property.PropertyType); Assert.AreEqual(expected, property.BinaryValue); }
public void DeepClone_IfBinaryNull_PreservesValue() { // Arrange byte[] input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.Equal(EdmType.Binary, property.PropertyType); Assert.Null(property.BinaryValue); }
public void DeepClone_IfGuidNull_PreservesValue() { // Arrange Guid?input = null; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(input)); // Assert Assert.NotNull(property); Assert.Equal(EdmType.Guid, property.PropertyType); Assert.Null(property.GuidValue); }
public void DeepClone_IfBinary_CopiesValue() { // Arrange byte original = 0x12; byte[] expected = new byte[] { original, 0x34 }; // Act EntityProperty property = TableEntityValueBinder.DeepClone(new EntityProperty(expected)); // Assert expected[0] = 0xFF; Assert.NotNull(property); Assert.AreEqual(EdmType.Binary, property.PropertyType); // Guard byte[] actual = property.BinaryValue; Assert.NotNull(actual); // Guard Assert.True(actual.Length == 2); // Guard Assert.AreEqual(original, actual[0]); }
public void HasChanged_ReturnsFalse_IfValueHasNotChanged() { // Arrange TableEntityContext entityContext = new TableEntityContext(); DynamicTableEntity value = new DynamicTableEntity { PartitionKey = "PK", RowKey = "RK", Properties = new Dictionary <string, EntityProperty> { { "Item", new EntityProperty("Foo") } } }; Type valueType = typeof(DynamicTableEntity); TableEntityValueBinder product = new TableEntityValueBinder(entityContext, value, valueType); // Act bool hasChanged = product.HasChanged; // Assert Assert.False(hasChanged); }
public IDictionary <string, EntityProperty> CloneProperties() { // Clone properties when retrieving, so changes to the retrieved value in memory don't affect the // persisted data. return(TableEntityValueBinder.DeepClone(_properties)); }