コード例 #1
0
        public static void ToWorkbookProtection___Should_return_corresponding_WorkbookProtection___When_called()
        {
            // Arrange
            var systemUnderTest = A.Dummy <WorksheetProtection>();

            var expected = new WorkbookProtection
            {
                ClearTextPassword = systemUnderTest.ClearTextPassword,
            };

            // Act
            var actual = systemUnderTest.ToWorkbookProtection();

            // Assert
            actual.AsTest().Must().BeEqualTo(expected);
        }
コード例 #2
0
        /// <summary>
        /// Applies the configured workbook protection.
        /// </summary>
        /// <param name="workbook">The workbook.</param>
        /// <param name="workbookProtection">The workbook protection.  If null then no protection is applied.</param>
        /// <returns>
        /// The specified workbook with the specified workbook protection applied.
        /// </returns>
        public static Workbook SetWorkbookProtection(
            this Workbook workbook,
            WorkbookProtection workbookProtection)
        {
            if (workbook == null)
            {
                throw new ArgumentNullException(nameof(workbook));
            }

            var result = workbook;

            if (workbookProtection == null)
            {
                return(result);
            }

            result.Protect(ProtectionType.Structure, workbookProtection.ClearTextPassword);

            return(result);
        }