public void GenerateCollectionItemIdentifiers_zero_primary_key() { Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { new Tuple <string, object>("ZeroKey", 0) }; string guid = Guid.NewGuid().ToString(); string identifiers = U.GenerateCollectionItemIdentifiers(primaryKeys, guid); Assert.AreEqual("Guid=" + guid, identifiers); }
public void GenerateCollectionItemIdentifiers_non_null_non_zero_primary_keys() { Tuple <string, object> nonZeroKey = new Tuple <string, object>("NonZeroKey", 1); Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { nonZeroKey }; string guid = Guid.NewGuid().ToString(); string identifiers = U.GenerateCollectionItemIdentifiers(primaryKeys, guid); Assert.AreEqual(nonZeroKey.Item1 + "=" + nonZeroKey.Item2, identifiers); }
public void GenerateCollectionItemIdentifiers_null_and_non_null_primary_key() { Tuple <string, object> nonNullKey = new Tuple <string, object>("NonNullKey", 1); Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { new Tuple <string, object>("NullKey", null), nonNullKey }; string guid = Guid.NewGuid().ToString(); string identifiers = U.GenerateCollectionItemIdentifiers(primaryKeys, guid); Assert.AreEqual("Guid=" + guid + "," + nonNullKey.Item1 + "=" + nonNullKey.Item2, identifiers); }
public void GenerateCollectionItemPath() { string path = ".Collection"; Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { }; string guid = Guid.NewGuid().ToString(); string collectionItemPath = U.GenerateCollectionItemPath(path, primaryKeys, guid); Assert.IsTrue(collectionItemPath.StartsWith(".Collection[")); Assert.IsTrue(collectionItemPath.EndsWith("].")); }
public void GetLastWeight() { Mock <IWeighted> mockWeighted1 = new Mock <IWeighted>(); mockWeighted1.SetupGet(m => m.Weight).Returns(1); Mock <IWeighted> mockWeighted2 = new Mock <IWeighted>(); mockWeighted2.SetupGet(m => m.Weight).Returns(2); int nextWeight = U.GetNextWeight(new IWeighted[] { mockWeighted1.Object, mockWeighted2.Object }); Assert.AreEqual(3, nextWeight); }
public void UpdatePrimaryKeys_long_to_int() { MockAssociativeEntity entity = new MockAssociativeEntity(); long entity1Id = 1; long entity2Id = 2; Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { new Tuple <string, object>("RelationalEntity1Id", entity1Id), new Tuple <string, object>("RelationalEntity2Id", entity2Id) }; U.UpdatePrimaryKeys(primaryKeys, entity); Assert.AreEqual(entity1Id, entity.RelationalEntity1Id); Assert.AreEqual(entity2Id, entity.RelationalEntity2Id); }
public void One_element_different_integer_and_long_returns_false() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1L) }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", 2) }; Assert.IsFalse(U.PrimaryKeysEqual(s1, s2)); }
public void UpdatePrimaryKeys_object_tree() { MockEntity entity = new MockEntity() { id = 1 }; entity.RelationalEntity1 = new MockEntity() { id = 2 }; entity.AssociativeEntities.Add(new MockAssociativeEntity() { RelationalEntity1Id = entity.id, RelationalEntity2Id = 3, RelationalEntity2 = new MockEntity() { id = 3 } }); string jobPath = "."; string equipmentLocationPath = "RelationalEntity1"; string jobContactsPath = "AssociativeEntities[Guid=" + entity.AssociativeEntities.First().Guid + "]"; string contactPath = jobContactsPath + ".RelationalEntity2"; IDictionary <string, Tuple <string, object>[]> keysToUpdate = new Dictionary <string, Tuple <string, object>[]>() { { jobPath, entity.PrimaryKeys }, { equipmentLocationPath, entity.RelationalEntity1.PrimaryKeys }, { jobContactsPath, entity.AssociativeEntities.First().PrimaryKeys }, { contactPath, entity.AssociativeEntities.First().RelationalEntity2.PrimaryKeys } }; MockEntity entityCopy = new MockEntity() { Guid = entity.Guid }; entityCopy.RelationalEntity1 = new MockEntity() { Guid = entity.RelationalEntity1.Guid }; entityCopy.AssociativeEntities.Add(new MockAssociativeEntity() { Guid = entity.AssociativeEntities.First().Guid, RelationalEntity2 = new MockEntity() { Guid = entity.AssociativeEntities.First().RelationalEntity2.Guid } }); Assert.AreEqual(EntityState.New, entityCopy.State); Assert.AreEqual(EntityState.New, entityCopy.RelationalEntity1.State); Assert.AreEqual(EntityState.New, entityCopy.AssociativeEntities.First().State); Assert.AreEqual(EntityState.New, entityCopy.AssociativeEntities.First().RelationalEntity2.State); U.UpdatePrimaryKeys(keysToUpdate, entityCopy); Assert.IsTrue(U.PrimaryKeysEqual(entity.PrimaryKeys, entityCopy.PrimaryKeys)); Assert.IsTrue(U.PrimaryKeysEqual(entity.RelationalEntity1.PrimaryKeys, entityCopy.RelationalEntity1.PrimaryKeys)); Assert.IsTrue(U.PrimaryKeysEqual(entity.AssociativeEntities.First().PrimaryKeys, entityCopy.AssociativeEntities.First().PrimaryKeys)); Assert.IsTrue(U.PrimaryKeysEqual(entity.AssociativeEntities.First().RelationalEntity2.PrimaryKeys, entityCopy.AssociativeEntities.First().RelationalEntity2.PrimaryKeys)); Assert.AreEqual(EntityState.Persisted, entityCopy.State); Assert.AreEqual(EntityState.Persisted, entityCopy.RelationalEntity1.State); Assert.AreEqual(EntityState.Persisted, entityCopy.AssociativeEntities.First().State); Assert.AreEqual(EntityState.Persisted, entityCopy.AssociativeEntities.First().RelationalEntity2.State); }
public void Two_different_mixed_type_elements_returns_false() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1), new Tuple <string, object>("b", "c") }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", 2), new Tuple <string, object>("b", "d") }; Assert.IsFalse(U.PrimaryKeysEqual(s1, s2)); }
public void One_element_equal_integer_and_long_returns_true() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1L) }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1) }; Assert.IsTrue(U.PrimaryKeysEqual(s1, s2)); }
public void Two_equal_mixed_type_elements_returns_true() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1), new Tuple <string, object>("b", "c") }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1), new Tuple <string, object>("b", "c") }; Assert.IsTrue(U.PrimaryKeysEqual(s1, s2)); }
public void Two_different_string_elements_returns_false() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", "b"), new Tuple <string, object>("c", "d") }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", "e"), new Tuple <string, object>("c", "f") }; Assert.IsFalse(U.PrimaryKeysEqual(s1, s2)); }
public void One_equal_string_element_returns_true() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", "b") }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", "b") }; Assert.IsTrue(U.PrimaryKeysEqual(s1, s2)); }
public void Two_different_numeric_elements_returns_false() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1), new Tuple <string, object>("b", 2) }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("a", 3), new Tuple <string, object>("b", 4) }; Assert.IsFalse(U.PrimaryKeysEqual(s1, s2)); }
public void Same_number_of_elements_different_keys_returns_false() { Tuple <string, object>[] s1 = new Tuple <string, object>[] { new Tuple <string, object>("a", 1L), new Tuple <string, object>("b", "c") }; Tuple <string, object>[] s2 = new Tuple <string, object>[] { new Tuple <string, object>("c", 1), new Tuple <string, object>("d", "c") }; Assert.IsFalse(U.PrimaryKeysEqual(s1, s2)); }