Esempio n. 1
0
        public void RevokeKey_CallsInternalManager()
        {
            // Arrange
            var            keyToRevoke            = new Guid("a11f35fc-1fed-4bd4-b727-056a63b70932");
            DateTimeOffset minRevocationDate      = DateTimeOffset.UtcNow;
            DateTimeOffset?actualRevocationDate   = null;
            var            mockInternalKeyManager = new Mock <IInternalXmlKeyManager>();

            mockInternalKeyManager
            .Setup(o => o.RevokeSingleKey(keyToRevoke, It.IsAny <DateTimeOffset>(), "Here's some reason text."))
            .Callback <Guid, DateTimeOffset, string>((innerKeyId, innerRevocationDate, innerReason) =>
            {
                actualRevocationDate = innerRevocationDate;
            });

            var options = Options.Create(new KeyManagementOptions()
            {
                AuthenticatedEncryptorConfiguration = new Mock <AlgorithmConfiguration>().Object,
                XmlRepository = new Mock <IXmlRepository>().Object,
                XmlEncryptor  = null
            });
            var keyManager = new XmlKeyManager(options, SimpleActivator.DefaultWithoutServices, NullLoggerFactory.Instance, mockInternalKeyManager.Object);

            // Act
            keyManager.RevokeKey(keyToRevoke, "Here's some reason text.");

            // Assert
            Assert.InRange(actualRevocationDate.Value, minRevocationDate, DateTimeOffset.UtcNow);
        }
Esempio n. 2
0
        public void RevokeKey_CallsInternalManager()
        {
            // Arrange - mocks
            var            keyToRevoke            = new Guid("a11f35fc-1fed-4bd4-b727-056a63b70932");
            DateTimeOffset minRevocationDate      = DateTimeOffset.UtcNow;
            DateTimeOffset?actualRevocationDate   = null;
            var            mockInternalKeyManager = new Mock <IInternalXmlKeyManager>();

            mockInternalKeyManager
            .Setup(o => o.RevokeSingleKey(keyToRevoke, It.IsAny <DateTimeOffset>(), "Here's some reason text."))
            .Callback <Guid, DateTimeOffset, string>((innerKeyId, innerRevocationDate, innerReason) =>
            {
                actualRevocationDate = innerRevocationDate;
            });

            // Arrange - services
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IXmlRepository>(new Mock <IXmlRepository>().Object);
            serviceCollection.AddSingleton <IAuthenticatedEncryptorConfiguration>(new Mock <IAuthenticatedEncryptorConfiguration>().Object);
            serviceCollection.AddSingleton <IInternalXmlKeyManager>(mockInternalKeyManager.Object);
            var services   = serviceCollection.BuildServiceProvider();
            var keyManager = new XmlKeyManager(services);

            // Act
            keyManager.RevokeKey(keyToRevoke, "Here's some reason text.");

            // Assert
            Assert.InRange(actualRevocationDate.Value, minRevocationDate, DateTimeOffset.UtcNow);
        }
        public void RevokeKey_CallsInternalManager()
        {
            // Arrange - mocks
            var keyToRevoke = new Guid("a11f35fc-1fed-4bd4-b727-056a63b70932");
            DateTimeOffset minRevocationDate = DateTimeOffset.UtcNow;
            DateTimeOffset? actualRevocationDate = null;
            var mockInternalKeyManager = new Mock<IInternalXmlKeyManager>();
            mockInternalKeyManager
                .Setup(o => o.RevokeSingleKey(keyToRevoke, It.IsAny<DateTimeOffset>(), "Here's some reason text."))
                .Callback<Guid, DateTimeOffset, string>((innerKeyId, innerRevocationDate, innerReason) =>
                {
                    actualRevocationDate = innerRevocationDate;
                });

            // Arrange - services
            var serviceCollection = new ServiceCollection();
            serviceCollection.AddSingleton<IXmlRepository>(new Mock<IXmlRepository>().Object);
            serviceCollection.AddSingleton<IAuthenticatedEncryptorConfiguration>(new Mock<IAuthenticatedEncryptorConfiguration>().Object);
            serviceCollection.AddSingleton<IInternalXmlKeyManager>(mockInternalKeyManager.Object);
            var services = serviceCollection.BuildServiceProvider();
            var keyManager = new XmlKeyManager(services);

            // Act
            keyManager.RevokeKey(keyToRevoke, "Here's some reason text.");

            // Assert
            Assert.InRange(actualRevocationDate.Value, minRevocationDate, DateTimeOffset.UtcNow);
        }