public async Task CanWrite_IEnumerableOf_SerializableErrors()
        {
            // Arrange
            var server  = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client  = server.CreateClient();
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-xmlser"));

            // Act
            var response = await client.SendAsync(request);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var result = await response.Content.ReadAsStringAsync();

            XmlAssert.Equal("<ArrayOfSerializableErrorWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                            " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><SerializableErrorWrapper><key1>key1-error</key1>" +
                            "<key2>key2-error</key2></SerializableErrorWrapper><SerializableErrorWrapper><key3>key1-error</key3>" +
                            "<key4>key2-error</key4></SerializableErrorWrapper></ArrayOfSerializableErrorWrapper>",
                            result);
        }
Beispiel #2
0
        public async void TestAdd()
        {
            await this.SetUp();

            const string Expected     = @"expected_add.config";
            const string ExpectedMono = @"expected_add.mono.config";

            var item = new IsapiFiltersItem(null);

            item.Name = "my cgi";
            item.Path = "c:\\test.dll";
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal("my cgi", _feature.SelectedItem.Name);
            Assert.Equal("c:\\test.dll", _feature.SelectedItem.Path);
            Assert.Equal(6, _feature.Items.Count);
            XmlAssert.Equal(
                Helper.IsRunningOnMono()
                    ? Path.Combine("IsapiFilters", ExpectedMono)
                    : Path.Combine("IsapiFilters", Expected),
                Current);
        }
Beispiel #3
0
        public async Task CanWrite_IEnumerableOf_SerializableErrors()
        {
            // Arrange
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/IEnumerable/SerializableErrors");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs"));

            // Act
            var response = await Client.SendAsync(request);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var result = await response.Content.ReadAsStringAsync();

            XmlAssert.Equal(
                "<ArrayOfSerializableErrorWrapper xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                " xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.AspNetCore.Mvc.Formatters.Xml\"><SerializableErrorWrapper>" +
                "<key1>key1-error</key1><key2>key2-error</key2></SerializableErrorWrapper><SerializableErrorWrapper>" +
                "<key3>key1-error</key3><key4>key2-error</key4></SerializableErrorWrapper>" +
                "</ArrayOfSerializableErrorWrapper>",
                result);
        }
Beispiel #4
0
        public void TopxConversion_TestOpenbaarheid()
        {
            // Arrange
            var dossiers = GetDossier();

            // muteer de openbaarheid
            dossiers[0].Openbaarheid_DatumOfPeriode          = "1-1-2010| 1-1-2015";
            dossiers[0].Openbaarheid_OmschrijvingBeperkingen = "Geheim| Openbaar";


            var globals = new Globals()
            {
                BronArchief          = "a",
                DatumArchief         = Convert.ToDateTime("2018-12-13"),
                DoelArchief          = "b",
                IdentificatieArchief = "c",
                NaamArchief          = "d",
                OmschrijvingArchief  = "e"
            };

            var mockDataservice = new Mock <IDataService>();

            var converter = new Creator.Parser(globals, mockDataservice.Object);
            var recordinformationPackage = converter.ParseDataToTopx(dossiers)[0];
            var xmlHelper       = new Utility.XmlHelper();
            var xmlstreamActual = xmlHelper.GetXmlStringFromObject(recordinformationPackage);

            // Act
            var xmlCompare = File.ReadAllText(Path.Combine(Statics.AppPath(), @"TestResources\ExpectedOutput_Openbaarheid.xml"));

            var xmlhelper = new XmlHelper();

            // When
            xmlhelper.ValidateXmlString(xmlstreamActual);

            // Assert
            Assert.That(xmlhelper.ValidationErrors.Length, Is.EqualTo(0));
            XmlAssert.Equal(xmlCompare, xmlstreamActual);
        }
        public void TestEdit()
        {
            SetUp();
            const string Expected = @"expected_edit.config";
            var          document = XDocument.Load(Current);
            var          node     = document.Root.XPathSelectElement("/configuration/system.webServer/isapiFilters");
            var          element  = node?.FirstNode as XElement;

            element?.SetAttributeValue("path", "c:\\test.dll");
            document.Save(Expected);

            _feature.SelectedItem = _feature.Items[0];
            var item     = _feature.SelectedItem;
            var expected = "c:\\test.dll";

            item.Path = expected;
            _feature.EditItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal(expected, _feature.SelectedItem.Path);
            Assert.Equal(5, _feature.Items.Count);
            XmlAssert.Equal(Expected, Current);
        }
        public async Task ProducesAttribute_WithTypeAndContentType_UsesContentType()
        {
            // Arrange
            var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client = server.CreateClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
            var expectedContentType = MediaTypeHeaderValue.Parse("application/xml;charset=utf-8");
            var expectedOutput      = "<User xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                                      "xmlns=\"http://schemas.datacontract.org/2004/07/ContentNegotiationWebSite\">" +
                                      "<Address>One Microsoft Way</Address><Name>John</Name></User>";

            // Act
            var response = await client.GetAsync("http://localhost/Home/UserInfo_ProducesWithTypeAndContentType");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
            var actual = await response.Content.ReadAsStringAsync();

            XmlAssert.Equal(expectedOutput, actual);
        }
Beispiel #7
0
        public async Task Home_CreateUser_ReturnsXmlBasedOnAcceptHeader()
        {
            // Arrange
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/ReturnUser");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));

            // Act
            var response = await Client.SendAsync(request);

            // Assert
            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            XmlAssert.Equal("<User xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=" +
                            "\"http://schemas.datacontract.org/2004/07/MvcSample.Web.Models\"><About>I like playing Football" +
                            "</About><Address>My address</Address><Age>13</Age><Alive>true</Alive><Dependent><About i:nil=\"true\" />" +
                            "<Address>Dependents address</Address><Age>0</Age><Alive>false</Alive><Dependent i:nil=\"true\" />" +
                            "<GPA>0</GPA><Log i:nil=\"true\" /><Name>Dependents name</Name>" +
                            "<Profession i:nil=\"true\" /></Dependent><GPA>13.37</GPA><Log i:nil=\"true\" />" +
                            "<Name>My name</Name><Profession>Software Engineer</Profession></User>",
                            await response.Content.ReadAsStringAsync());
        }
        public void TestRevert()
        {
            SetUp();

            var site     = Path.Combine("Website1", "web.config");
            var expected = "expected_revert.site.config";
            var document = XDocument.Load(site);
            var node     = document.Root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files");

            node?.Remove();
            document.Save(expected);

            _feature.Revert();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(6, _feature.Items.Count);

            const string Original     = @"original.config";
            const string OriginalMono = @"original.mono.config";

            XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current);
            XmlAssert.Equal(expected, site);
        }
Beispiel #9
0
        public async void TestRemove()
        {
            await this.SetUp();

            var item = new HttpErrorsItem(null);

            item.Status = 455;
            item.Path   = "c:\\test.htm";
            _feature.AddItem(item);

            Assert.Equal(455U, _feature.SelectedItem.Status);
            Assert.Equal(10, _feature.Items.Count);
            _feature.Remove();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(9, _feature.Items.Count);

            const string Original     = @"original.config";
            const string OriginalMono = @"original.mono.config";

            XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current);
            XmlAssert.Equal(Path.Combine("HttpErrors", "expected_remove1.site.config"), Path.Combine("Website1", "web.config"));
        }
Beispiel #10
0
        public async Task XmlSerializerOutputFormatter_WhenDerivedClassIsReturned()
        {
            // Arrange
            var server  = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client  = server.CreateClient();
            var request = new HttpRequestMessage(
                HttpMethod.Post,
                "http://localhost/XmlSerializer/GetDerivedDummyClass?sampleInput=10");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));

            // Act
            var response = await client.SendAsync(request);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            XmlAssert.Equal(
                "<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"DerivedDummyClass\">" +
                "<SampleInt>10</SampleInt><SampleIntInDerived>50</SampleIntInDerived></DummyClass>",
                await response.Content.ReadAsStringAsync());
        }
        public async void TestRemove()
        {
            await this.SetUp();

            var item = new HandlersItem(null);

            item.Name = "test";
            item.Path = "*";
            _feature.AddItem(item);

            Assert.Equal("test", _feature.SelectedItem.Name);
            Assert.Equal(83, _feature.Items.Count);
            _feature.Remove();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(82, _feature.Items.Count);

            const string Expected     = @"expected_remove1.site.config";
            const string ExpectedMono = @"expected_remove1.site.mono.config";

            XmlAssert.Equal(Path.Combine("Handlers", Helper.IsRunningOnMono() ? ExpectedMono : Expected), Current);
            XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config"));
        }
Beispiel #12
0
        public async Task XmlSerializerFailsAndDataContractSerializerIsCalled()
        {
            // Arrange
            var server  = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client  = server.CreateClient();
            var request = new HttpRequestMessage(
                HttpMethod.Post,
                "http://localhost/DataContractSerializer/GetPerson?name=HelloWorld");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));

            // Act
            var response = await client.SendAsync(request);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            XmlAssert.Equal(
                "<Person xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "xmlns=\"http://schemas.datacontract.org/2004/07/FormatterWebSite\">" +
                "<Name>HelloWorld</Name></Person>",
                await response.Content.ReadAsStringAsync());
        }
Beispiel #13
0
        public async Task XmlDataContractSerializerOutputFormatterIsCalled()
        {
            // Arrange
            var server  = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client  = server.CreateClient();
            var request = new HttpRequestMessage(
                HttpMethod.Post,
                "http://localhost/Home/GetDummyClass?sampleInput=10");

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));

            // Act
            var response = await client.SendAsync(request);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            XmlAssert.Equal(
                "<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "xmlns=\"http://schemas.datacontract.org/2004/07/FormatterWebSite\">" +
                "<SampleInt>10</SampleInt></DummyClass>",
                await response.Content.ReadAsStringAsync());
        }
        public async void TestRemove()
        {
            await this.SetUp();

            var item = new IsapiCgiRestrictionItem(null);

            item.Description = "test";
            item.Path        = "c:\\test.dll";
            _feature.AddItem(item);

            Assert.Equal("test", _feature.SelectedItem.Description);
            Assert.Equal(5, _feature.Items.Count);
            _feature.Remove();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(4, _feature.Items.Count);

            const string Expected     = @"expected_remove1.site.config";
            const string ExpectedMono = @"expected_remove1.site.mono.config";

            XmlAssert.Equal(Path.Combine("IsapiCgiRestriction", Helper.IsRunningOnMono() ? ExpectedMono : Expected), Current);
            XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config"));
        }
Beispiel #15
0
        public async void TestRemove()
        {
            await this.SetUp();

            var item = new ResponseHeadersItem(null);

            item.Name  = "Server";
            item.Value = "Jexus";
            _feature.AddItem(item);

            Assert.Equal("Server", _feature.SelectedItem.Name);
            Assert.Equal(2, _feature.Items.Count);
            _feature.Remove();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(1, _feature.Items.Count);

            const string Original     = @"original.config";
            const string OriginalMono = @"original.mono.config";

            XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current);
            XmlAssert.Equal(Path.Combine("ResponseHeaders", "expected_remove1.site.config"), Path.Combine("Website1", "web.config"));
        }
        public async void TestAdd()
        {
            await this.SetUp();

            const string Expected     = @"expected_add.config";
            const string ExpectedMono = @"expected_add.mono.config";

            var item = new IpSecurityItem(null);

            item.Address = "12.0.0.0";
            item.Allowed = true;
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal("12.0.0.0", _feature.SelectedItem.Address);
            Assert.Equal(true, _feature.SelectedItem.Allowed);
            Assert.Equal(2, _feature.Items.Count);
            XmlAssert.Equal(
                Helper.IsRunningOnMono()
                    ? Path.Combine("IpSecurity", ExpectedMono)
                    : Path.Combine("IpSecurity", Expected),
                Current);
        }
        public async void TestRevert()
        {
            await SetUp();

            var item = new IsapiFiltersItem(null);

            item.Name = "test";
            item.Path = "c:\\test.dll";
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal("test", _feature.SelectedItem.Name);

            _feature.Revert();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(5, _feature.Items.Count);

            const string Expected     = @"expected_revert.site.config";
            const string ExpectedMono = @"expected_revert.site.mono.config";

            XmlAssert.Equal(Path.Combine("IsapiFilters", Helper.IsRunningOnMono() ? ExpectedMono : Expected), Current);
            XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config"));
        }
        public async void TestRemove()
        {
            await this.SetUp();

            var item = new MimeMapItem(null);

            item.FileExtension = ".xl1";
            item.MimeType      = "text/test";
            _feature.AddItem(item);

            Assert.Equal(".xl1", _feature.SelectedItem.FileExtension);
            Assert.Equal(375, _feature.Items.Count);
            _feature.Remove();
            Assert.Null(_feature.SelectedItem);
            Assert.Equal(374, _feature.Items.Count);

            const string Original     = @"original.config";
            const string OriginalMono = @"original.mono.config";

            XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current);
            XmlAssert.Equal(Path.Combine("MimeMap", "expected_remove1.site.config"), Path.Combine("Website1", "web.config"));
        }
        public void ExportToXml_ProducesCorrectPayload_Gcm()
        {
            // Arrange
            var masterKey  = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
            var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_GCM, ValidationAlgorithm.HMACSHA512, masterKey.ToSecret());

            // Act
            var retVal = descriptor.ExportToXml();

            // Assert
            Assert.Equal(typeof(AuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
            var expectedXml = $@"
                <descriptor>
                  <encryption algorithm='AES_192_GCM' />
                  <!-- some comment here -->
                  <masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
                    <value>{masterKey}</value>
                  </masterKey>
                </descriptor>";

            XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
        }
        public void TestAdd()
        {
            SetUp();
            const string Expected = @"expected_add.config";
            var          document = XDocument.Load(Current);
            var          node     = document.Root?.XPathSelectElement("/configuration/system.webServer/security/requestFiltering/verbs");
            var          element  = new XElement("add");

            element.SetAttributeValue("verb", "GET");
            element.SetAttributeValue("allowed", "false");
            node?.Add(element);
            document.Save(Expected);

            var item = new VerbsItem(null);

            item.Verb = "GET";
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal("GET", _feature.SelectedItem.Verb);
            Assert.Equal(2, _feature.Items.Count);
            XmlAssert.Equal(Expected, Current);
        }
        public async void TestMoveDown()
        {
            await SetUp();
            const string Expected = @"expected_up.config";
            const string ExpectedMono = @"expected_up.mono.config";

            _feature.SelectedItem = _feature.Items[0];
            var other = "PageHandlerFactory-ISAPI-4.0_64bit";
            Assert.Equal(other, _feature.Items[1].Name);
            var selected = "AXD-ISAPI-4.0_64bit";
            Assert.Equal(selected, _feature.Items[0].Name);
            _feature.MoveDown();
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal(selected, _feature.SelectedItem.Name);
            Assert.Equal(other, _feature.Items[0].Name);
            Assert.Equal(selected, _feature.Items[1].Name);
            XmlAssert.Equal(
                Helper.IsRunningOnMono()
                    ? Path.Combine("Handlers", ExpectedMono)
                    : Path.Combine("Handlers", Expected),
                Current);
        }
Beispiel #22
0
        public void TestRemoveGlobal()
        {
            SetUp();
            const string Expected = @"expected_removeglobal.config";

            var document = XDocument.Load(Current);

            document.Save(Expected);

            Assert.Equal(37, _feature.GlobalModules.Count);

            var item = new GlobalModule(null);

            item.Name  = "test";
            item.Image = "test";
            _feature.AddGlobal(item);
            Assert.Equal(38, _feature.GlobalModules.Count);

            _feature.RemoveGlobal(item);
            Assert.Equal(37, _feature.GlobalModules.Count);
            XmlAssert.Equal(Expected, Current);
        }
Beispiel #23
0
        public void TopXConversion_TestGeolocationMultipleRecords()
        {
            // Arrange
            var dossiers = GetDossier();

            // muteer de geolocation
            dossiers[0].Dekking_GeografischGebied = "Test1| Test2 | Test3";



            var globals = new Globals()
            {
                BronArchief          = "a",
                DatumArchief         = Convert.ToDateTime("2018-12-13"),
                DoelArchief          = "b",
                IdentificatieArchief = "c",
                NaamArchief          = "d",
                OmschrijvingArchief  = "e"
            };

            var mockDataservice = new Mock <IDataService>();

            var converter = new Creator.Parser(globals, mockDataservice.Object);
            var recordinformationPackage = converter.ParseDataToTopx(dossiers)[0];
            var xmlHelper       = new Utility.XmlHelper();
            var xmlstreamActual = xmlHelper.GetXmlStringFromObject(recordinformationPackage);

            // Act
            var xmlCompare = File.ReadAllText(Path.Combine(Statics.AppPath(), @"TestResources\ExpectedOutput_Geolocatie_array.xml"));

            var xmlhelper = new XmlHelper();

            // When
            xmlhelper.ValidateXmlString(xmlstreamActual);

            // Assert
            Assert.That(xmlhelper.ValidationErrors.Length, Is.EqualTo(0));
            XmlAssert.Equal(xmlCompare, xmlstreamActual);
        }
        public async void TestAdd()
        {
            await this.SetUp();

            const string Expected     = @"expected_add.config";
            const string ExpectedMono = @"expected_add.mono.config";

            var item = new ModulesItem(null);

            item.Name      = "test";
            item.Type      = "test";
            item.IsManaged = true;
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal("test", _feature.SelectedItem.Name);
            Assert.Equal(45, _feature.Items.Count);
            XmlAssert.Equal(
                Helper.IsRunningOnMono()
                    ? Path.Combine("Modules", ExpectedMono)
                    : Path.Combine("Modules", Expected),
                Current);
        }
Beispiel #25
0
        public async void TestEdit()
        {
            await this.SetUp();

            const string Expected     = @"expected_edit.config";
            const string ExpectedMono = @"expected_edit.mono.config";

            _feature.SelectedItem = _feature.Items[0];
            var item     = _feature.SelectedItem;
            var expected = "c:\\test.dll";

            item.Path = expected;
            _feature.EditItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal(expected, _feature.SelectedItem.Path);
            Assert.Equal(5, _feature.Items.Count);
            XmlAssert.Equal(
                Helper.IsRunningOnMono()
                    ? Path.Combine("IsapiFilters", ExpectedMono)
                    : Path.Combine("IsapiFilters", Expected),
                Current);
        }
        public async Task PostedSerializableError_IsBound(string acceptHeader)
        {
            // Arrange
            var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client = server.CreateClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
            var expectedXml    = "<Error><key1>key1-error</key1><key2>The input was not valid.</key2></Error>";
            var requestContent = new StringContent(expectedXml, Encoding.UTF8, acceptHeader);

            // Act
            var response = await client.PostAsync("http://localhost/SerializableError/LogErrors", requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.Content);
            Assert.NotNull(response.Content.Headers.ContentType);
            Assert.Equal(acceptHeader, response.Content.Headers.ContentType.MediaType);
            var responseData = await response.Content.ReadAsStringAsync();

            XmlAssert.Equal(expectedXml, responseData);
        }
        public async Task CanWrite_WrappedTypes(string url)
        {
            // Arrange
            var server  = TestHelper.CreateServer(_app, SiteName, _configureServices);
            var client  = server.CreateClient();
            var request = new HttpRequestMessage(HttpMethod.Get, url);

            request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml-dcs"));

            // Act
            var response = await client.SendAsync(request);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var result = await response.Content.ReadAsStringAsync();

            XmlAssert.Equal("<ArrayOfPersonWrapper xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                            " xmlns=\"http://schemas.datacontract.org/2004/07/XmlFormattersWebSite\"><PersonWrapper>" +
                            "<Age>35</Age><Id>10</Id><Name>Mike</Name></PersonWrapper><PersonWrapper><Age>35</Age><Id>" +
                            "11</Id><Name>Jimmy</Name></PersonWrapper></ArrayOfPersonWrapper>",
                            result);
        }
Beispiel #28
0
        public void TestAdd()
        {
            SetUp();
            const string Expected = @"expected_add.config";
            var          document = XDocument.Load(Current);
            var          node     = document.Root.XPathSelectElement("/configuration/system.webServer/caching/profiles/add");
            var          newNode  = new XElement("add",
                                                 new XAttribute("duration", "00:00:00"),
                                                 new XAttribute("extension", ".txt"));

            node?.AddAfterSelf(newNode);
            document.Save(Expected);

            var item = new CachingItem(null);

            item.Extension = ".txt";
            _feature.AddItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal(".txt", _feature.SelectedItem.Extension);
            Assert.Equal(2, _feature.Items.Count);
            XmlAssert.Equal(Expected, Current);
        }
Beispiel #29
0
        public void ExportToXml_ProducesCorrectPayload_Cbc()
        {
            // Arrange
            var masterKey  = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
            var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512, masterKey);

            // Act
            var retVal = descriptor.ExportToXml();

            // Assert
            Assert.Equal(typeof(AuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
            const string expectedXml = @"
                <descriptor>
                  <encryption algorithm='AES_192_CBC' />
                  <validation algorithm='HMACSHA512' />
                  <masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
                    <value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
                  </masterKey>
                </descriptor>";

            XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
        }
        public void TestEdit()
        {
            SetUp();

            var site     = Path.Combine("Website1", "web.config");
            var expected = "expected_edit1.site.config";
            var document = XDocument.Load(site);
            var node     = document.Root?.XPathSelectElement("/configuration/system.webServer");

            node?.Add(
                new XElement("security",
                             new XElement("authorization",
                                          new XElement("add",
                                                       new XAttribute("accessType", "Allow"),
                                                       new XAttribute("roles", "defenders")))));
            document.Save(expected);

            var item     = new AuthorizationRule(null);
            var original = "testers";

            item.Roles = original;
            _feature.AddItem(item);

            Assert.Equal(original, _feature.SelectedItem.Roles);
            Assert.Equal(2, _feature.Items.Count);
            var expectedValue = "defenders";

            item.Roles = expectedValue;
            _feature.EditItem(item);
            Assert.NotNull(_feature.SelectedItem);
            Assert.Equal(expectedValue, _feature.SelectedItem.Roles);
            Assert.Equal(2, _feature.Items.Count);

            const string Original     = @"original.config";
            const string OriginalMono = @"original.mono.config";

            XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current);
            XmlAssert.Equal(expected, site);
        }