public void ConstructorTest()
 {
     var actual = new FutureJsonSchema("123ABC");
     Assert.False(actual.Resolved);
     Assert.AreEqual("123ABC", actual.Id);
     Assert.IsNull(actual.Maximum);
     Assert.IsNull(actual.Type);
 }
        public void ResolvePassTest()
        {
            var actual = new FutureJsonSchema("123ABC");
            var sucess = new JsonSchema { Id = "123ABC", Maximum = 12.5, Minimum = 5.3 };

            actual.Resolve(sucess);

            Assert.True(actual.Resolved);
            Assert.AreEqual(12.5, actual.Maximum.Value);
            Assert.AreEqual(5.3, actual.Minimum.Value);
        }
Esempio n. 3
0
        public override JsonSchema GetSchema(string id)
        {
            JsonSchema alreadyPresent = LoadedSchemas.FirstOrDefault(js => js.Id == id);

            if (alreadyPresent != null)
            {
                return(alreadyPresent);
            }

            var future = new FutureJsonSchema(id);

            LoadedSchemas.Add(future);
            return(future);
        }
        public void ResolveFailTest()
        {
            var actual = new FutureJsonSchema("123ABC");
            var wrongId = new JsonSchema { Id = "Go Fish" };
            var wrongType = new FutureJsonSchema("123ABC");
            var sucess = new JsonSchema { Id = "123ABC" };

            Assert.Throws(typeof(ArgumentException), () => actual.Resolve(wrongId));
            Assert.Throws(typeof(ArgumentException), () => actual.Resolve(wrongType));
            Assert.Throws(typeof(ArgumentNullException), () => actual.Resolve(null));

            actual.Resolve(sucess);

            Assert.Throws(typeof(InvalidOperationException), () => actual.Resolve(sucess));
        }
        public void TestAddResolveFuture()
        {
            var resolver = new FutureJsonSchemaResolver();
            Assert.AreEqual(0, resolver.LoadedSchemas.Count);

            var futureSchema1 = new FutureJsonSchema("1");
            var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" };
            var futureSchema2 = new FutureJsonSchema("2");
            var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" };

            resolver.LoadedSchemas.Add(futureSchema1);
            resolver.LoadedSchemas.Add(futureSchema2);

            Assert.AreEqual(2, resolver.LoadedSchemas.Count);

            resolver.LoadedSchemas.Add(schema2);
            Assert.AreEqual(2, resolver.LoadedSchemas.Count);

            var resolvedFuture2 = resolver.GetSchema("2") as FutureJsonSchema;
            var resolvedFuture1 = resolver.GetSchema("1") as FutureJsonSchema;

            Assert.NotNull(resolvedFuture1);
            Assert.NotNull(resolvedFuture2);
            Assert.AreSame(resolvedFuture1, futureSchema1);
            Assert.AreSame(resolvedFuture2, futureSchema2);
            Assert.IsFalse(resolvedFuture1.Resolved);
            Assert.IsTrue(resolvedFuture2.Resolved);
            Assert.AreEqual("Title For 2", resolvedFuture2.Title);
            Assert.IsNull(resolvedFuture1.Title);

            resolver.LoadedSchemas.Add(schema1);
            Assert.AreEqual(2, resolver.LoadedSchemas.Count);

            resolvedFuture2 = resolver.GetSchema("2") as FutureJsonSchema;
            resolvedFuture1 = resolver.GetSchema("1") as FutureJsonSchema;

            Assert.NotNull(resolvedFuture1);
            Assert.NotNull(resolvedFuture2);
            Assert.AreSame(resolvedFuture1, futureSchema1);
            Assert.AreSame(resolvedFuture2, futureSchema2);
            Assert.IsTrue(resolvedFuture1.Resolved);
            Assert.IsTrue(resolvedFuture2.Resolved);
            Assert.AreEqual("Title For 2", resolvedFuture2.Title);
            Assert.AreEqual("Title For 1", resolvedFuture1.Title);
        }