ACMESharp.Providers.IIS.IisProviderTests.TestHandleCreateAndCleanUpFiles C# (CSharp) Method

TestHandleCreateAndCleanUpFiles() private method

private TestHandleCreateAndCleanUpFiles ( ) : void
return void
        public void TestHandleCreateAndCleanUpFiles()
        {
            var r = new Random();
            var bn = new byte[10];
            var bv = new byte[10];
            r.NextBytes(bn);
            r.NextBytes(bv);
            var rn = BitConverter.ToString(bn);
            var rv = BitConverter.ToString(bv);

            var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer())
            {
                Token = "FOOBAR",
                FileUrl = $"http://foobar.acmetesting.zyborg.io/utest/{rn}",
                FilePath = $"utest/{rn}",
                FileContent = rv,
            };

            var awsParams = new AwsCommonParams();
            awsParams.InitParams(_handlerParams);

            var p = GetProvider();
            using (var h = p.GetHandler(c, _handlerParams))
            {
                var sites = IisHelper.ListDistinctHttpWebSites();
                Assert.IsNotNull(sites);
                var site = sites.First(x => x.SiteName == _handlerParams.WebSiteRef);
                Assert.IsNotNull(site);

                var fullPath = Environment.ExpandEnvironmentVariables(
                        Path.Combine(site.SiteRoot, c.FilePath));

                // Assert test file does not exist
                Assert.IsFalse(File.Exists(fullPath));

                // Create the record...
                h.Handle(c);

                // ...and assert it does exist
                Assert.IsTrue(File.Exists(fullPath));
                Assert.AreEqual(c.FileContent, File.ReadAllText(fullPath));

                // Clean up the record...
                h.CleanUp(c);

                // ...and assert it does not exist once more
                Assert.IsFalse(File.Exists(fullPath));
            }
        }