Exemple #1
0
        public void NoTransformViewChanges()
        {
            var package = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msi");

            using (var db = new InstallPackage(package, DatabaseOpenMode.ReadOnly))
            {
                var view = new TransformView(db);
                Assert.AreEqual <int>(0, view.Tables.Count);
            }
        }
Exemple #2
0
        public void TransfomViewChanges()
        {
            var package = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msi");
            var patch   = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msp");

            using (var db = new InstallPackage(package, DatabaseOpenMode.ReadOnly))
            {
                var applicator = new PatchApplicator(db);
                applicator.Add(patch);

                applicator.Apply(true);

                var view = new TransformView(db);

                // Despite Orca showing 5 tables, the _TransformView table does not show the created, empty "Patch" table.
                Assert.AreEqual <int>(4, view.Tables.Count);

                Assert.AreEqual <TableOperation>(TableOperation.Modify, view.GetTableOperation("Media"));
                Assert.AreEqual <RowOperation>(RowOperation.None, view.GetRowOperation("Media", "1"));
                Assert.AreEqual <RowOperation>(RowOperation.Insert, view.GetRowOperation("Media", "100"));

                Assert.AreEqual <TableOperation>(TableOperation.Create, view.GetTableOperation("PatchPackage"));
                Assert.AreEqual <RowOperation>(RowOperation.Insert, view.GetRowOperation("PatchPackage", "{FF63D787-26E2-49CA-8FAA-28B5106ABD3A}"));

                Assert.AreEqual <TableOperation>(TableOperation.Modify, view.GetTableOperation("Property"));
                Assert.AreEqual <RowOperation>(RowOperation.None, view.GetRowOperation("Property", "ProductCode"));
                Assert.AreEqual <RowOperation>(RowOperation.Modify, view.GetRowOperation("Property", "ProductVersion"));
                Assert.AreEqual <RowOperation>(RowOperation.Insert, view.GetRowOperation("Property", "Example.PatchCode"));
                Assert.AreEqual <RowOperation>(RowOperation.Insert, view.GetRowOperation("Property", "Example.AllowRemoval"));

                Assert.AreEqual <TableOperation>(TableOperation.Modify, view.GetTableOperation("Registry"));
                Assert.AreEqual <RowOperation>(RowOperation.Modify, view.GetRowOperation("Registry", "reg302A797C45AD3AD1EC816DDC58DF65F3"));

                // Negative assertions.
                Assert.AreEqual <TableOperation>(TableOperation.None, view.GetTableOperation("File"));
                Assert.AreEqual <RowOperation>(RowOperation.None, view.GetRowOperation(null, null));
                Assert.AreEqual <RowOperation>(RowOperation.None, view.GetRowOperation("File", null));
                Assert.AreEqual <RowOperation>(RowOperation.None, view.GetRowOperation("File", "product.wxs"));
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TableInfo"/> class.
        /// </summary>
        /// <param name="name">The name of the table.</param>
        /// <param name="path">The full path to the <see cref="Database"/> containing the table.</param>
        /// <param name="transform">The <see cref="TransformView"/> containing information about operations performed on the table.</param>
        /// <param name="patches">A list of patches applied to the <see cref="Database"/> containing the table.</param>
        /// <param name="transforms">A list of transformed applied to the <see cref="Database"/> containing the table.</param>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is null or an empty string.</exception>
        internal TableInfo(string name, string path, TransformView transform, IEnumerable <string> patches, IEnumerable <string> transforms)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            this.Table = name;
            this.Path  = path;

            if (null != transform)
            {
                this.Operation = transform.GetTableOperation(name);
            }
            else
            {
                this.Operation = TableOperation.None;
            }

            if (null != patches)
            {
                this.Patch = new List <string>(patches).AsReadOnly();
            }
            else
            {
                // Parameter binding requires non-null list.
                this.Patch = TableInfo.Empty;
            }

            if (null != transforms)
            {
                this.Transform = new List <string>(transforms).AsReadOnly();
            }
            else
            {
                this.Transform = TableInfo.Empty;
            }
        }
Exemple #4
0
 public void TransformViewNullArguments()
 {
     var view = new TransformView(null);
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Record"/> class.
        /// </summary>
        /// <param name="record">The <see cref="Deployment.WindowsInstaller.Record"/> from which to copy values.</param>
        /// <param name="columns">The <see cref="ColumnCollection"/> for a <see cref="Deployment.WindowsInstaller.View"/>.</param>
        /// <param name="transform">The <see cref="TransformView"/> containing information about operations performed on this record.</param>
        /// <param name="path">The path to the package that contains the record.</param>
        internal Record(Deployment.WindowsInstaller.Record record, ColumnCollection columns, TransformView transform = null, string path = null)
        {
            // Internal constructor will assume valid parameters.

            // Shared reference to the column collection.
            this.Columns = columns;

            this.Path = path;

            // Cache the data from the record.
            var primaryKeys = new List <string>();

            this.Data = new List <object>(columns.Count);
            for (int i = 0; i < columns.Count; ++i)
            {
                // Windows Installer uses 1-based indices.
                var offset = i + 1;

                var type = columns[i].Type;
                if (type.IsEnum)
                {
                    var value = record.GetNullableInteger(offset);
                    this.Data.Add(new AttributeColumn(type, value));

                    if (columns[i].IsPrimaryKey)
                    {
                        primaryKeys.Add(null != value ? value.Value.ToString(CultureInfo.InvariantCulture) : string.Empty);
                    }
                }
                else if (typeof(Stream) == type)
                {
                    var buffer = CopyStream(record, offset);
                    this.Data.Add(buffer);

                    // Binary column types cannot be primary keys.
                }
                else
                {
                    var data = record[offset];
                    this.Data.Add(data);

                    if (columns[i].IsPrimaryKey)
                    {
                        primaryKeys.Add(null != data ? data.ToString() : string.Empty);
                    }
                }
            }

            if (0 < primaryKeys.Count)
            {
                this.PrimaryKey = primaryKeys.Join(Record.KeySeparator);
            }

            // Can only reliably get row operations performed on rows in a single table.
            if (null != transform && 1 == columns.TableNames.Count())
            {
                var tableName = columns.TableNames[0];
                this.Operation = transform.GetRowOperation(tableName, this.PrimaryKey);
            }
            else
            {
                this.Operation = RowOperation.None;
            }
        }