コード例 #1
0
        // todo: add in tests
        public DataStoreInstance AddOrUpdate(DataStoreInstance instance)
        {
            // todo: better error handling here
            // todo: add in test
            if (instance == null)
            {
                throw new Exception("You cannot create a blank instance");
            }

            // todo: better error handling here
            // todo: add in test
            if (string.IsNullOrEmpty(instance.Name) || string.IsNullOrEmpty(instance.Description))
            {
                throw new Exception("You need a Name and Description to add an instance");
            }

            if (!instance.Exists(this))
            {
                instance.Add(this);
            }
            else
            {
                instance.Update(this);
            }

            // Ensure that the cached instance reflects any changes made
            _instanceCache[instance.Name] = instance.Get(this);

            return GetCachedInstance(instance.Name);
        }
コード例 #2
0
        private DataStoreInstance GetCachedInstance(string name)
        {
            if (!_instanceCache.ContainsKey(name))
            {
                var instance = new DataStoreInstance(name).Get(this);
                _instanceCache.Add(name, instance);
            }

            return _instanceCache[name];
        }
コード例 #3
0
        // CreateInstance()
        public DataStoreInstance CreateInstance(string name, string description)
        {
            var instance = new DataStoreInstance
            {
                DateCreated = DateTime.UtcNow,
                Description = description,
                Name = name
            };

            AddOrUpdate(instance);

            return instance.Get(this);
        }
コード例 #4
0
        public void Delete(DataStoreInstance instance)
        {
            // todo: better error handling here
            if (instance == null)
            {
                throw new Exception("You need to provide an instance to delete");
            }

            // We need to drop all keys belonning to this instance
            instance.DeleteAllKeys(this);
            instance.Delete(this);
        }
コード例 #5
0
ファイル: TbInstances.cs プロジェクト: DevFluff/DataStore
 // Helper methods
 private static void AreTheSame(DataStoreInstance instance1, DataStoreInstance instance2)
 {
     Assert.AreEqual(instance1.Description, instance2.Description);
     Assert.AreEqual(instance1.DateCreated, instance2.DateCreated);
     Assert.AreEqual(instance1.Id, instance2.Id);
     Assert.AreEqual(instance1.Name, instance2.Name);
 }
コード例 #6
0
ファイル: TbInstances.cs プロジェクト: DevFluff/DataStore
        public void GetAll_Succeeds_WhenCalled()
        {
            _dataStore.CreateInstance(GenerateInstanceName(), _instanceDescription);
            _dataStore.CreateInstance(GenerateInstanceName(), _instanceDescription);
            _dataStore.CreateInstance(GenerateInstanceName(), _instanceDescription);

            var instances = new DataStoreInstance().GetAll(_dataStore);

            Assert.Greater(instances.Count, 3);
        }