Exemple #1
0
        public void GetCertificateAsync_DirectoryNamespaceQueried()
        {
            var files       = new[] { "file.cert" };
            var contentPath = "";
            var thumbprint  = "abc";

            var ioFacade = Substitute.For <IIoFacade>();

            ioFacade.GetContentPath().Returns(contentPath);
            ioFacade.GetDirectoryFiles(contentPath, Arg.Any <string>()).Returns(files);


            var rdr = new FileCertificateReader(ioFacade);

            try
            {
                var _ = rdr.GetCertificateAsync(thumbprint).Result;

                throw new InvalidOperationException("Test failed");
            }
            catch (Exception ex)
                when(
                    ex.Message == "The system cannot find the file specified." || // Windows
                    ex.Message.StartsWith("Could not find file")                  // macOS
                    )
                {
                    ioFacade.Received().GetContentPath();
                    ioFacade.Received().GetDirectoryFiles(contentPath, Arg.Any <string>());
                }
        }
Exemple #2
0
        public void GetCertificateAsync_EmptyThumbprint_NullReturned()
        {
            var thumbprint = "";

            var ioFacade = Substitute.For <IIoFacade>();

            var rdr    = new FileCertificateReader(ioFacade);
            var result = rdr.GetCertificateAsync(thumbprint).Result;

            result.Should().BeNull();
            ioFacade.DidNotReceive().GetContentPath();
            ioFacade.DidNotReceive().GetDirectoryFiles(Arg.Any <string>(), Arg.Any <string>());
        }
Exemple #3
0
        public void GetCertificateAsync_NoFiles_NullReturned()
        {
            var files       = new string[0];
            var contentPath = "";
            var thumbprint  = "abc";

            var ioFacade = Substitute.For <IIoFacade>();

            ioFacade.GetContentPath().Returns(contentPath);
            ioFacade.GetDirectoryFiles(Arg.Any <string>(), Arg.Any <string>()).Returns(files);


            var rdr    = new FileCertificateReader(ioFacade);
            var result = rdr.GetCertificateAsync(thumbprint).Result;

            result.Should().BeNull();
            ioFacade.Received().GetContentPath();
            ioFacade.Received().GetDirectoryFiles(Arg.Any <string>(), Arg.Any <string>());
        }