Ejemplo n.º 1
0
        public void StringRepresentation()
        {
            var name = "path/to/file";

            var identity = new AssemblyIdentity(name);

            Assert.AreEqual(identity.ToString(), name);

            identity = identity.WithAnnotation(
                AssemblyIdentity.IsRetargetableKey,
                true);
            Assert.AreEqual(
                identity.ToString(),
                name + " { isRetargetable: 'True' }");

            identity = identity.WithAnnotation(
                AssemblyIdentity.VersionAnnotationKey,
                new Version(1, 2, 3, 4));
            Assert.AreEqual(
                identity.ToString(),
                name + " { isRetargetable: 'True', version: '1.2.3.4' }");
        }
Ejemplo n.º 2
0
        public void Equality()
        {
            // Generate identical assembly identities. Check that they are
            // indeed the same.
            for (int i = 0; i < 1000; i++)
            {
                var name   = rng.NextAsciiString(rng.Next(0, 100));
                var first  = new AssemblyIdentity(name);
                var second = new AssemblyIdentity(name);
                Assert.AreEqual(first, second);
                Assert.AreEqual(first.GetHashCode(), second.GetHashCode());

                int annotationCount = rng.Next(0, 20);
                for (int j = 0; j < annotationCount; j++)
                {
                    var key   = rng.NextAsciiString(rng.Next(0, 20));
                    var value = rng.NextAsciiString(rng.Next(0, 100));

                    string oldValue;
                    if (!first.TryGetAnnotation(key, out oldValue))
                    {
                        oldValue = null;
                    }

                    first = first.WithAnnotation(key, value);

                    if (oldValue != value)
                    {
                        Assert.AreNotEqual(first, second);
                    }

                    second = second.WithAnnotation(key, value);

                    Assert.AreEqual(first, second);
                    Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
                }
            }
        }