Пример #1
0
        public void GenerateJsonRpcDoc_Valid_CreatesDoc()
        {
            // ARRANGE
            var info = new JsonRpcInfo
            {
                Contact = new JsonRpcContact
                {
                    Email = "*****@*****.**",
                    Name  = "test",
                    Url   = "www.test.dk"
                },
                Description        = "test",
                Title              = "test",
                Version            = "test",
                JsonRpcApiEndpoint = "/test"
            };

            var attribute = typeof(TestWebSocketService)
                            .GetAttribute <JsonRpcServiceAttribute>();
            // ACT
            var doc = DocGenerator.GenerateJsonRpcDoc(info);

            // ASSERT
            Assert.That(doc.Info.Description, Is.EqualTo(info.Description));
            Assert.That(doc.Info.Title, Is.EqualTo(info.Title));
            Assert.That(doc.Info.Version, Is.EqualTo(info.Version));
            Assert.That(doc.Info.JsonRpcApiEndpoint, Is.EqualTo(info.JsonRpcApiEndpoint));
            Assert.That(doc.Info.Contact.Email, Is.EqualTo(info.Contact.Email));
            Assert.That(doc.Info.Contact.Name, Is.EqualTo(info.Contact.Name));
            Assert.That(doc.Info.Contact.Url, Is.EqualTo(info.Contact.Url));
            Assert.That(doc.Services, Has.Count.EqualTo(1));
            var service = doc.Services.First();

            Assert.That(service.Description, Is.EqualTo(attribute.Description));
            Assert.That(service.Name, Is.EqualTo(attribute.Name));
            Assert.That(service.Path, Is.EqualTo(attribute.Path));
            Assert.That(service.Notifications, Has.Count.EqualTo(1));
            var notification = service.Notifications.First();

            Assert.That(notification.Name, Is.EqualTo("EventWithArgs"));
            Assert.That(notification.Description, Is.EqualTo("test"));
            Assert.That(notification.Parameters, Has.Count.EqualTo(1));
            var parameters = notification.Parameters.First();

            Assert.That(parameters.Name, Is.EqualTo(typeof(TestEventArgs).Name));
            Assert.That(parameters.Required, Is.True);
            Assert.That(parameters.Type, Is.EqualTo(typeof(TestEventArgs)));
            var schema = parameters.Schema;

            Assert.That(schema, Contains.Key("type"));
            Assert.That(schema["type"], Is.EqualTo("object"));
            Assert.That(schema, Contains.Key("$ref"));
            Assert.That(schema["$ref"], Is.EqualTo("#/definitions/TestEventArgs"));
        }