예제 #1
0
        public static T RetrievePayloadAs <T>(this DthMessage message)
            where T : JToken
        {
            Assert.NotNull(message);
            AssertType <T>(message.Payload, "Payload");

            return((T)message.Payload);
        }
예제 #2
0
        /// <summary>
        /// Throws if the message is not generated in communication between given server and client
        /// </summary>
        public static DthMessage EnsureSource(this DthMessage message, DthTestServer server, DthTestClient client)
        {
            if (message.HostId != server.HostId)
            {
                throw new Exception($"{nameof(message.HostId)} doesn't match the one of server. Expected {server.HostId} but actually {message.HostId}.");
            }

            return(message);
        }
예제 #3
0
        public static JObject RetrieveDependencyDiagnosticsCollection(this DthMessage message)
        {
            Assert.NotNull(message);
            Assert.Equal("DependencyDiagnostics", message.MessageType);

            var payload = message.Payload as JObject;

            Assert.NotNull(payload);

            return(payload);
        }
예제 #4
0
        public static DthMessage EnsureNotContainDependency(this DthMessage message, string dependencyName)
        {
            Assert.NotNull(message);
            Assert.Equal("Dependencies", message.MessageType);

            var payload = message.Payload as JObject;

            Assert.NotNull(payload);

            Assert.True(payload["Dependencies"][dependencyName] == null, $"Unexpected dependency {dependencyName} exists.");

            return(message);
        }
예제 #5
0
        private static bool MatchesFramework(FrameworkName targetFramework, DthMessage msg)
        {
            if (msg.Payload.Type != JTokenType.Object)
            {
                return(false);
            }

            var frameworkObj = msg.Payload["Framework"];

            if (frameworkObj == null || !frameworkObj.HasValues)
            {
                return(false);
            }

            return(string.Equals(frameworkObj.Value <string>("FrameworkName"), targetFramework.FullName, StringComparison.OrdinalIgnoreCase));
        }
        private static bool MatchesFramework(FrameworkName targetFramework, DthMessage msg)
        {
            if (msg.Payload.Type != JTokenType.Object)
            {
                return false;
            }

            var frameworkObj = msg.Payload["Framework"];

            if (frameworkObj == null || !frameworkObj.HasValues)
            {
                return false;
            }

            return string.Equals(frameworkObj.Value<string>("FrameworkName"), targetFramework.FullName, StringComparison.OrdinalIgnoreCase);
        }
예제 #7
0
        public static JObject RetrieveDependency(this DthMessage message, string dependencyName)
        {
            Assert.NotNull(message);
            Assert.Equal("Dependencies", message.MessageType);

            var payload = message.Payload as JObject;

            Assert.NotNull(payload);

            var dependency = payload["Dependencies"][dependencyName] as JObject;

            Assert.NotNull(dependency);
            Assert.Equal(dependencyName, dependency["Name"].Value <string>());

            return(dependency);
        }
예제 #8
0
        public static JObject RetrieveCompilationDiagnostics(this DthMessage message, string frameworkShortName)
        {
            Assert.NotNull(message);
            Assert.Equal(DthMessageTypes.AllDiagnostics, message.MessageType);

            Assert.True(message.Payload is JArray);
            var payload = (JArray)message.Payload;

            foreach (var each in payload)
            {
                Assert.True(each is JObject);
                var diagnosticsOfFramework = (JObject)each;

                if (string.Equals(diagnosticsOfFramework["Framework"]["ShortName"].Value <string>(),
                                  frameworkShortName,
                                  StringComparison.OrdinalIgnoreCase))
                {
                    return(diagnosticsOfFramework);
                }
            }

            return(null);
        }