summaryrefslogtreecommitdiffstats
path: root/src/main.test/Tests/EncryptionTests/EncryptionTest.cs
blob: d370eb09411c52d091fb6a61a8da9f23edddf7ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PKISharp.WACS.Services.Serialization;

namespace PKISharp.WACS.UnitTests.Tests.EcnryptionTests
{
    [TestClass]
    public class EncryptionTests
    {
        [TestMethod]
        public void TurnOnOff()
        {
            // Create encrypted value
            var plain = "---BLA---";
            var plainString = new ProtectedString(plain);
            var encrypted = plainString.DiskValue(true);
            Assert.IsTrue(encrypted != null);

            // Read back
            var log = new Mock.Services.LogService(false);
            var readBack = new ProtectedString(encrypted ?? "", log);
            Assert.AreEqual(plain, readBack.Value);

            // Turn off encryption
            var turnOff = new ProtectedString(encrypted ?? "", log);
            var turnOffValue = turnOff.DiskValue(false);
            Assert.IsTrue(turnOffValue != null);

            // Read back turned off value
            var readBack2 = new ProtectedString(turnOffValue ?? "", log);
            Assert.AreEqual(readBack2.Value, plain);
        }
    }
}