Пример #1
0
        public void ShouldReturnInputAsString()
        {
            Text text    = new TextOf("val");
            Text notNull = new NotNull(text);

            notNull.String().Should().Be("val");
        }
 public string IntoUser()
 {
     try
     {
         if (_user != null && File.Exists(_jsonPath))
         {
             string returnValue = "";
             var    pathInput   = new TextOf(new InputOf(new Uri(_jsonPath))).AsString();
             User   data        = JsonConvert.DeserializeObject <User>(pathInput, new JsonSerializerSettings {
                 TypeNameHandling = TypeNameHandling.All
             });
             data.ToDictionary().TryGetValue(_key, out returnValue).ToString();
             return(returnValue);
         }
         else if (_userName != null && File.Exists(_jsonPath))
         {
             string returnValue = "";
             var    pathInput   = new TextOf(new InputOf(new Uri(_jsonPath))).AsString();
             User   data        = JsonConvert.DeserializeObject <User>(pathInput, new JsonSerializerSettings {
                 TypeNameHandling = TypeNameHandling.All
             });
             data.ToDictionary().TryGetValue(_key, out returnValue).ToString();
             return(returnValue);
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
Пример #3
0
        public void ShouldReturnStringOfStream()
        {
            MemoryStream memoryStream = new MemoryStream(Encoding.ASCII.GetBytes("Some ValueItem Here"));
            Text         value        = new TextOf(memoryStream);

            value.String().Should().Be("Some ValueItem Here");
        }
Пример #4
0
        public void CopiesComplexContent()
        {
            var dom     = new XDocument();
            var content =
                new TextOf(
                    "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                    + "<?some-pi test?>"
                    + "<target id=\"BBA3CBB0-00F0-43DD-9F74-87C53D35270C\" name=\"j1046rfa_11\">"
                    + "<body><accessibility><readonly>false</readonly><reason /></accessibility><type>default</type><spatials><cartesian machine=\"BEFC5DE8-C579-44A6-ACDF-65293C39C87F\"><translation x=\"-4150.784755\" y=\"-1819.545936\" z=\"955.4282165\" /><rotation rx=\"-2.949491294\" ry=\"-0.8920227643\" rz=\"-3.120333533\" /><configuration><joints><joint name=\"j1\" state=\"irrelevant\"><turn hasvalue=\"true\">0</turn></joint><joint name=\"j2\" state=\"irrelevant\"><turn hasvalue=\"false\">0</turn></joint><joint name=\"j3\" state=\"negative\"><turn hasvalue=\"false\">0</turn></joint><joint name =\"j4\" state=\"irrelevant\"><turn hasvalue=\"true\">0</turn></joint><joint name=\"j5\" state=\"positive\"><turn hasvalue=\"false\">0</turn></joint><joint name=\"j6\" state=\"irrelevant\"><turn hasvalue=\"true\">0</turn></joint></joints><overhead>negative</overhead></configuration></cartesian><axial machine=\"F399FDD7-B9FF-4D5F-8A65-C5EC35D306BE\"><axes><axis name=\"j1\">-4871</axis></axes></axial></spatials><parameters><motiontype>ptp</motiontype><speed>70</speed><acceleration>100</acceleration><zone>C_DIS</zone><referenceframe>b4</referenceframe><toolframe>t2</toolframe><storagetype>local</storagetype><processtype /></parameters><postolpcommands /></body><foot /></target>"
                    );
            var xml = XDocument.Parse(content.AsString());

            new Xambler(
                new Joined <IDirective>(
                    new ManyOf <IDirective>(
                        new AddDirective("target")
                        ),
                    new CopyOfDirective(xml.Root.Element("body"))
                    )
                ).Apply(dom);

            var nav = dom.CreateNavigator();

            Assert.True(
                nav.SelectSingleNode("/target/body/accessibility/readonly").Value == "false"
                );
        }
Пример #5
0
        public void ComparesText()
        {
            var txt = new TextOf("Wonderful text!");

            Assert.True(
                new TextNotIllegal(txt).Equals(txt));
        }
        public void SendsBody()
        {
            var port = new AwaitedPort(new TestPort()).Value();
            var body = "";

            using (var server =
                       new HttpMock(port,
                                    new FkWire(req =>
            {
                body =
                    new TextOf(
                        new Body.Of(req)
                        ).AsString();
                return(new Response.Of(200, "OK"));
            })
                                    ).Value()
                   )
            {
                new AspNetCoreWire(
                    new AspNetCoreClients(),
                    new TimeSpan(0, 1, 0)
                    ).Response(
                    new Get(
                        new Scheme("http"),
                        new Host("localhost"),
                        new Port(server.Port),
                        new TextBody("very important content")
                        )
                    ).Wait(30000);
            }
            Assert.Equal(
                "very important content",
                body
                );
        }
Пример #7
0
 public void ComplexExampleForDocu()
 {
     var brix = new BxBlock("rootBlock",
                            new BxBlock("Block1",
                                        new BxBlockArray("BlockArrayName", "BlockArrayItemName",
                                                         new BxBlock(
                                                             new BxProp("Prop-Inside-a-empty-block", "the Value with special chars §$%%&/><|öä#ü'*#\"")
                                                             )
                                                         )
                                        ),
                            new BxBlock("Block2",
                                        new BxArray("Array", "arrayItemName", "first", "second", "third")
                                        ),
                            new BxBlock("Block3",
                                        new BxMap(
                                            "BxMap", "thefirstValue",
                                            "bxMapKey", "second entry"
                                            )
                                        )
                            );
     var json    = brix.Print(new JsonMedia()).ToString();
     var xml     = brix.Print(new XmlMedia()).ToString();
     var rebuild = new TextOf(new BytesOf(brix.Print(new RebuildMedia()))).AsString();
     var yaml    = brix.Print(new YamlMedia()).ToString();
 }
        public void FormBodyWorksWithKestrel()
        {
            var body = "";
            var port = new AwaitedPort(new TestPort()).Value();
            var host = WebHost.CreateDefaultBuilder();

            host.UseUrls($"http://{Environment.MachineName.ToLower()}:{port}");
            host.ConfigureServices(svc =>
            {
                svc.AddSingleton <Action <HttpRequest> >(req => // required to instantiate HtAction from dependecy injection
                {
                    body = new TextOf(req.Body).AsString();
                });
                svc.AddMvc().AddApplicationPart(
                    typeof(HtAction).Assembly
                    ).AddControllersAsServices();
            });
            host.Configure(app =>
            {
                app.UseMvc();
            });

            using (var built = host.Build())
            {
                built.RunAsync();
                try
                {
                    new Verified(
                        new AspNetCoreWire(
                            new AspNetCoreClients(),
                            new TimeSpan(0, 1, 0)
                            ),
                        new ExpectedStatus(200)
                        ).Response(
                        new Post(
                            new Scheme("http"),
                            new Host("localhost"),
                            new Port(port),
                            new Path("action"),
                            new FormParams(
                                new MapOf(
                                    "key-1-name", "this is a test",
                                    "key-2-name", "test&+=xyz"
                                    )
                                )
                            )
                        );
                }
                finally
                {
                    built.StopAsync();
                }
            }

            Assert.Equal(
                "key-1-name=this+is+a+test&key-2-name=test%26%2B%3Dxyz",
                body
                );
        }
Пример #9
0
        public void ShouldThrowExceptionForNullTextValue()
        {
            Text   text    = new TextOf((string)null);
            Text   notNull = new NotNull(text);
            Action action  = () => notNull.String();

            action.ShouldThrowExactly <Exception>().WithMessage("NULL instead of a valid result string");
        }
Пример #10
0
        public void PassLegalText()
        {
            var txt = new TextOf("Well formed text");

            Assert.Equal(
                txt.AsString(),
                new TextNotIllegal(txt).AsString());
        }
Пример #11
0
        public void ShouldReturnProvidedValue()
        {
            //Arrange
            TextOf subject = new TextOf("TheValue");

            //Act
            string actual = subject;

            //Assert
            actual.Should().Be("TheValue");
        }
Пример #12
0
        public void ShouldReturnValueAsString()
        {
            //arrange
            string expected = "any string";
            TextOf subject  = new TextOf(expected);

            //act
            string actual = subject;

            //assert
            actual.Should().Be(expected);
        }
Пример #13
0
        public void ShouldReturnArrayOfBytes()
        {
            //Arrange
            Text text = new TextOf("Brian");
            Utf8ByteArrayFromText subject = new Utf8ByteArrayFromText(text);

            //Act
            byte[] actual = subject;

            //Assert
            actual.Should().BeEquivalentTo(Encoding.UTF8.GetBytes("Brian"));
        }
Пример #14
0
        public void ShouldFormatTextIntoString()
        {
            //Arrange
            Text       textToFormat = new TextOf("any text {0} {1}");
            FormatText subject      = new FormatText(textToFormat, new TextOf("Brian"), new TextOf("Peg"));

            //Act
            string actual = subject;

            //Assert
            actual.Should().Be("any text Brian Peg");
        }
Пример #15
0
        public void ShouldReturnTimeIntervalAsText()
        {
            //Arrange
            TimeInterval       interval = new Seconds(60 * 10 + 12);
            Text               format   = new TextOf(@"mm\:ss");
            TimeIntervalToText subject  = new TimeIntervalToText(interval, format);

            //Act
            string actual = subject;

            //Assert
            actual.Should().Be("10:12");
        }
Пример #16
0
        public void ShouldReturnFalseIfNotEqual()
        {
            //Arrange
            Text         text1   = new TextOf("value");
            Text         text2   = new TextOf("not value");
            AreEqualText subject = new AreEqualText(text1, text2);

            //Act
            bool actual = subject;

            //Assert
            actual.Should().BeFalse();
        }
Пример #17
0
        public void RejectsIllegalTxt()
        {
            var txt = new TextOf(Convert.ToChar(0x0E));

            try
            {
                new TextNotIllegal(txt).AsString();
                Assert.True(false, "Expected an Exception, should not get here.");
            }
            catch (Exception ex)
            {
                Assert.Contains(
                    "is in the restricted XML range",
                    ex.Message);
            }
        }
Пример #18
0
        public async Task TestMethod1()
        {
            Text  json = new TextOf(@"{
    ""name"":""Quinn Fyzxs"",
    ""birthday"":""19061209""
    ""contact_info"":[
        {
            ""type"":""phone"",
            ""value"":""5551234567""
        }
    ]
}");
            IUser user = new User(json);

            Bool isMinor = (await user.Age()).IsMinor();
        }
Пример #19
0
        /// <summary>
        /// Props which are read into memory from internal xml document props.cat in the given comb.
        /// Props are read from memory.
        /// Props are updated into the comb.
        /// </summary>
        public SandboxProps(IMnemonic mem, string scope, string id)
        {
            this.id          = id;
            this.scope       = scope;
            this.mem         = mem;
            this.memoryProps = new Solid <IProps>(() =>
            {
                var stringProps =
                    new TextOf(
                        new BytesOf(
                            this.mem
                            .Contents()
                            .Bytes(
                                new Normalized($"{scope}/{id}/props.cat").AsString(),
                                () => new byte[0]
                                )
                            ),
                        Encoding.UTF8
                        ).AsString();

                var cachedProps = new RamProps();
                Parallel.ForEach(stringProps.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries), (stringProp) =>
                {
                    var parts = stringProp.Split(':');
                    if (parts.Length != 2)
                    {
                        throw new ApplicationException($"A property of {scope}/{id} has an invalid format: {stringProp}");
                    }
                    var name   = XmlConvert.DecodeName(parts[0].Trim());
                    var values = parts[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = XmlConvert.DecodeName(values[i]);
                    }
                    cachedProps.Refined(name, values);
                });
                return(cachedProps);
            });
        }
Пример #20
0
        public void WorksWithEmptySpacesAfterNodeEnding()
        {
            var dom     = new XDocument();
            var content =
                new TextOf("<state><item>success</item>   </state>");
            var xml = XDocument.Parse(content.AsString());

            new Xambler(
                new Joined <IDirective>(
                    new ManyOf <IDirective>(
                        new AddDirective("root")
                        ),
                    new CopyOfDirective(xml.FirstNode)
                    )
                ).Apply(dom);

            var nav = dom.CreateNavigator();

            Assert.Equal(
                "success",
                nav.SelectSingleNode("/root/state/item").Value
                );
        }
Пример #21
0
        public void ShouldReturnStringOfBytes()
        {
            Text value = new TextOf(Encoding.ASCII.GetBytes("Some ValueItem Here"));

            value.String().Should().Be("Some ValueItem Here");
        }
Пример #22
0
        public void ShouldReturnInputFromString()
        {
            Text value = new TextOf("Some ValueItem Here");

            value.String().Should().Be("Some ValueItem Here");
        }
Пример #23
0
        public void ShouldReturnInputFromText()
        {
            Text value = new TextOf(new DelayedText(() => "Some ValueItem Here"));

            value.String().Should().Be("Some ValueItem Here");
        }