コード例 #1
0
        public RefreshObjectEventArgs(DatabaseEntity o)
        {
            Object = o;

            if (o == null)
            {
                throw new ArgumentException("You cannot create a refresh on a null object", "o");
            }

            Exists = Object.Exists();
        }
コード例 #2
0
ファイル: ObjectSaverButton.cs プロジェクト: HicServices/RDMP
        public void CheckForUnsavedChangesAnOfferToSave()
        {
            // If there is no object or it does not exist don't try to save it
            if (_o == null || !_o.Exists())
            {
                return;
            }

            if (_isEnabled)
            {
                if (_activator.YesNo("Save Changes To '" + _o + "'?", "Save Changes"))
                {
                    Save();
                }
                else
                {
                    _o.RevertToDatabaseState();
                }
            }
        }
コード例 #3
0
        public void TestAllSupported()
        {
            //load all DatabaseEntity types
            MEF mef = new MEF();

            mef.Setup(new SafeDirectoryCatalog(TestContext.CurrentContext.TestDirectory));

            var types = mef.GetAllTypes()
                        .Where(t => typeof(DatabaseEntity).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).ToArray();

            var methods = typeof(UnitTests).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            var method  = methods.Single(m => m.Name.Equals("WhenIHaveA") && !m.GetParameters().Any());

            List <Type> notSupported = new List <Type>();

            foreach (Type t in types)
            {
                //ignore these types too
                if (SkipTheseTypes.Contains(t.Name) || t.Name.StartsWith("Spontaneous") || typeof(SpontaneousObject).IsAssignableFrom(t))
                {
                    continue;
                }

                DatabaseEntity instance = null;

                try
                {
                    //ensure that the method supports the Type
                    var generic = method.MakeGenericMethod(t);
                    instance = (DatabaseEntity)generic.Invoke(this, null);
                }
                catch (TargetInvocationException exception)
                {
                    if (exception.InnerException is TestCaseNotWrittenYetException)
                    {
                        notSupported.Add(t);
                    }
                    else
                    {
                        throw;
                    }
                }

                //if the instance returned by MakeGenericMethod does not pass checks that's a dealbreaker!
                if (instance != null)
                {
                    try
                    {
                        //and that it returns an instance
                        Assert.IsNotNull(instance);
                        Assert.IsTrue(instance.Exists());
                        Assert.AreEqual(ChangeDescription.NoChanges, instance.HasLocalChanges().Evaluation, "Type was '" + t.Name + "'");
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Implementation of WhenIHaveA<" + t.Name + "> is flawed", e);
                    }
                }
            }

            Assert.IsEmpty(notSupported, "The following Types were not supported by WhenIHaveA<T>:" + Environment.NewLine + string.Join(Environment.NewLine, notSupported.Select(t => t.Name)));
        }