public void When_PackageCollection_Updates_PackageList_Updates()
        {
            var packages = PackageSets.Instance.Outdated();
            var current  = packages.ToList().First();
            var latest   = packages.ToList().Last();

            SetPackages(packages);
            Factory.AddOperation = new MockAddOperation(Factory, latest);

            PackageCollection.Instance.SetListPackageInfos(packages);
            var package = PackageCollection.Instance.GetPackageByName(current.Name);

            onPackageChangedEvent = newpackages =>
            {
                package = PackageCollection.Instance.GetPackageByName(current.Name);

                Assert.IsTrue(package.Current.PackageId == latest.PackageId);

                var packageItem      = Container.Query(null, "package").Build().First();
                var label            = packageItem.Q <Label>("packageName");
                var version          = packageItem.Q <Label>("packageVersion");
                var state            = packageItem.Q <Label>("packageState");
                var hasOutdatedClass = state.ClassListContains(PackageItem.GetIconStateId(PackageState.Outdated));
                Assert.IsTrue(latest.Name == string.Format("com.unity.{0}", label.text));
                Assert.IsTrue(latest.Version == version.text);
                Assert.IsFalse(hasOutdatedClass);
            };

            package.AddSignal.OnOperation += operation =>
            {
                operation.OnOperationSuccess += packageInfo =>
                {
                    PackageCollection.Instance.OnPackagesChanged += onPackageChangedEvent;
                };
            };

            package.Update();
        }
        public void When_PackageCollection_Update_Fails_Package_Stay_Current()
        {
            var packages = PackageSets.Instance.Outdated();
            var current  = packages.ToList().First();
            var latest   = packages.ToList().Last();

            SetPackages(packages);

            var error = MakeError(ErrorCode.Unknown, "Fake error");

            Factory.AddOperation            = new MockAddOperation(Factory, latest);
            Factory.AddOperation.ForceError = error;

            PackageCollection.Instance.SetListPackageInfos(packages);
            var package = PackageCollection.Instance.GetPackageByName(current.Name);

            package.AddSignal.OnOperation += operation =>
            {
                operation.OnOperationError     += operationError => { Assert.IsTrue(error == operationError); };
                operation.OnOperationFinalized += () =>
                {
                    Assert.IsTrue(package.Current.PackageId ==
                                  current.PackageId); // Make sure package hasn't been upgraded

                    var packageItem      = Container.Query(null, "package").Build().First();
                    var label            = packageItem.Q <Label>("packageName");
                    var version          = packageItem.Q <Label>("packageVersion");
                    var state            = packageItem.Q <Label>("packageState");
                    var hasOutdatedClass = state.ClassListContains(PackageItem.GetIconStateId(PackageState.Outdated));
                    Assert.IsTrue(current.Name == string.Format("com.unity.{0}", label.text));
                    Assert.IsTrue(current.Version == version.text);
                    Assert.IsTrue(hasOutdatedClass);
                };
            };

            package.Update();
        }