Beispiel #1
0
        public static string CreateMessageJson()
        {
            var id   = Guid.NewGuid();
            var from = DataUtil.CreateNode();
            var pp   = DataUtil.CreateNode();
            var to   = DataUtil.CreateNode();

            string randomKey1    = "randomString1";
            string randomKey2    = "randomString2";
            string randomString1 = DataUtil.CreateRandomString(DataUtil.CreateRandomInt(50));
            string randomString2 = DataUtil.CreateRandomString(DataUtil.CreateRandomInt(50));

            var text = DataUtil.CreateRandomString(DataUtil.CreateRandomInt(50));

            return(string.Format(
                       "{{\"type\":\"application/vnd.lime.text+json\",\"content\":{{\"text\":\"{0}\"}},\"id\":\"{1}\",\"from\":\"{2}\",\"pp\":\"{3}\",\"to\":\"{4}\",\"metadata\":{{\"{5}\":\"{6}\",\"{7}\":\"{8}\"}}}}",
                       text,
                       id,
                       from,
                       pp,
                       to,
                       randomKey1,
                       randomString1,
                       randomKey2,
                       randomString2
                       ));
        }
Beispiel #2
0
        public void ToUri_RelativeInstance_ThrowsInvalidOperationException()
        {
            var resourceName = DataUtil.CreateRandomString(10);
            var relativePath = string.Format("/{0}", resourceName);
            var limeUri      = LimeUri.Parse(relativePath);

            // Act
            var uri = limeUri.ToUri();
        }
Beispiel #3
0
        public void Parse_OnlyNameString_ReturnsValidIdentity()
        {
            var name = DataUtil.CreateRandomString(10);

            var identity = Identity.Parse(name);

            Assert.AreEqual(name, identity.Name);
            Assert.IsNull(identity.Domain);
        }
Beispiel #4
0
        public void ToUriIdentity_AbsoluteInstance_ThrowsInvalidOperationException()
        {
            var identity     = DataUtil.CreateIdentity();
            var resourceName = DataUtil.CreateRandomString(10);
            var absolutePath = string.Format("{0}://{1}/{2}", LimeUri.LIME_URI_SCHEME, identity, resourceName);
            var limeUri      = LimeUri.Parse(absolutePath);

            // Act
            var uri = limeUri.ToUri(identity);
        }
Beispiel #5
0
        public void Parse_ValidRelativeString_ReturnsInstance()
        {
            var resourceName = DataUtil.CreateRandomString(10);
            var relativePath = string.Format("/{0}", resourceName);
            var actual       = LimeUri.Parse(relativePath);

            actual.Path.ShouldNotBe(null);
            actual.Path.ShouldBe(relativePath);
            actual.IsRelative.ShouldBe(true);
        }
Beispiel #6
0
        public void Parse_ValidAbsoluteString_ReturnsInstance()
        {
            var identity     = DataUtil.CreateIdentity();
            var resourceName = DataUtil.CreateRandomString(10);
            var absolutePath = string.Format("{0}://{1}/{2}", LimeUri.LIME_URI_SCHEME, identity, resourceName);
            var actual       = LimeUri.Parse(absolutePath);

            actual.Path.ShouldNotBe(null);
            actual.Path.ShouldBe(absolutePath);
            actual.IsRelative.ShouldBe(false);
        }
Beispiel #7
0
        public void Parse_OnlyDomain_ReturnsValidIdentity()
        {
            var domain = DataUtil.CreateRandomString(10);

            var identityString = string.Format("@{0}", domain);

            var identity = Identity.Parse(identityString);

            Assert.AreEqual(domain, identity.Domain);
            Assert.IsNull(identity.Name);
        }
Beispiel #8
0
        public void Parse_CompleteString_ReturnsValidIdentity()
        {
            var name   = DataUtil.CreateRandomString(10);
            var domain = DataUtil.CreateRandomString(10);

            var identityString = string.Format("{0}@{1}", name, domain);


            var identity = Identity.Parse(identityString);

            Assert.AreEqual(name, identity.Name);
            Assert.AreEqual(domain, identity.Domain);
        }
Beispiel #9
0
        public void ToString_OnlyDomainIdentity_ReturnsValidString()
        {
            string name   = null;
            var    domain = DataUtil.CreateRandomString(10);

            var identity1 = new Identity()
            {
                Name   = name,
                Domain = domain
            };

            var expectedResult = string.Format("@{0}", domain);

            Assert.AreEqual(identity1.ToString(), expectedResult);
        }
Beispiel #10
0
        public void ToString_OnlyNameIdentity_ReturnsValidString()
        {
            var    name   = DataUtil.CreateRandomString(10);
            string domain = null;

            var identity1 = new Identity()
            {
                Name   = name,
                Domain = domain
            };

            var expectedResult = name;

            Assert.AreEqual(identity1.ToString(), expectedResult);
        }
Beispiel #11
0
        public void ToString_CompleteIdentity_ReturnsValidString()
        {
            var name   = DataUtil.CreateRandomString(10);
            var domain = DataUtil.CreateRandomString(10);

            var identity1 = new Identity()
            {
                Name   = name,
                Domain = domain
            };

            var expectedResult = string.Format("{0}@{1}", name, domain);

            Assert.AreEqual(identity1.ToString(), expectedResult);
        }
Beispiel #12
0
        public void ToUri_AbsoluteInstance_ReturnsUri()
        {
            var identity     = DataUtil.CreateIdentity();
            var resourceName = DataUtil.CreateRandomString(10);
            var absolutePath = string.Format("{0}://{1}/{2}", LimeUri.LIME_URI_SCHEME, identity, resourceName);
            var limeUri      = LimeUri.Parse(absolutePath);

            // Act
            var uri = limeUri.ToUri();

            // Assert
            uri.Scheme.ShouldBe(LimeUri.LIME_URI_SCHEME);
            uri.UserInfo.ShouldBe(identity.Name);
            uri.Authority.ShouldBe(identity.Domain);
            uri.PathAndQuery.ShouldBe("/" + resourceName);
        }
Beispiel #13
0
        public void Equals_EqualsIdentitiesNullDomain_ReturnsTrue()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10),
                Domain = null
            };

            var identity2 = new Identity()
            {
                Name   = identity1.Name,
                Domain = null
            };

            Assert.AreEqual(identity1, identity2);
            Assert.AreEqual(identity2, identity1);
        }
Beispiel #14
0
        public void GetHashCode_EqualsIdentitiesDifferentCasing_ReturnsSameHash()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10).ToUpper(),
                Domain = DataUtil.CreateRandomString(10).ToUpper()
            };

            var identity2 = new Identity()
            {
                Name   = identity1.Name.ToLower(),
                Domain = identity1.Domain.ToLower()
            };


            Assert.AreEqual(identity1.GetHashCode(), identity2.GetHashCode());
        }
Beispiel #15
0
        public void GetHashCode_NotEqualsIdentities_ReturnsDifferentHash()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10),
                Domain = DataUtil.CreateRandomString(10)
            };

            var identity2 = new Identity()
            {
                Name   = new string(identity1.Name.Reverse().ToArray()) + DataUtil.CreateRandomString(5),
                Domain = new string(identity1.Domain.Reverse().ToArray()) + DataUtil.CreateRandomString(5),
            };


            Assert.AreNotEqual(identity1.GetHashCode(), identity2.GetHashCode());
        }
Beispiel #16
0
        public void Equals_EqualsIdentitiesDifferentCasing_ReturnsTrue()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10).ToUpper(),
                Domain = DataUtil.CreateRandomString(10).ToUpper()
            };

            var identity2 = new Identity()
            {
                Name   = identity1.Name.ToLower(),
                Domain = identity1.Domain.ToLower()
            };

            Assert.AreEqual(identity1, identity2);
            Assert.AreEqual(identity2, identity1);
        }
Beispiel #17
0
        public void GetHashCode_EqualsIdentities_ReturnsSameHash()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10),
                Domain = DataUtil.CreateRandomString(10)
            };

            var identity2 = new Identity()
            {
                Name   = identity1.Name,
                Domain = identity1.Domain
            };


            Assert.AreEqual(identity1.GetHashCode(), identity2.GetHashCode());
        }
Beispiel #18
0
        public void Equals_NotEqualsIdentities_ReturnsFalse()
        {
            var identity1 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10),
                Domain = DataUtil.CreateRandomString(10)
            };

            var identity2 = new Identity()
            {
                Name   = DataUtil.CreateRandomString(10),
                Domain = DataUtil.CreateRandomString(10)
            };


            Assert.AreNotEqual(identity1, identity2);
            Assert.AreNotEqual(identity2, identity1);
        }
Beispiel #19
0
 public void Parse_InvalidRelativeString_ThrowsArgumentException()
 {
     var resourceName = DataUtil.CreateRandomString(10);
     var invalidPath  = string.Format("\\{0}", resourceName);
     var actual       = LimeUri.Parse(invalidPath);
 }