示例#1
0
        public void BinaryEvent_NoData_Success()
        {
            BinaryCloudEvent evnt = CloudEvent.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), (byte[])null);

            evnt.Should().NotBeNull();
            evnt.Should().BeOfType <BinaryCloudEvent>();

            CloudEvent newEvnt = JsonConvert.DeserializeObject <CloudEvent>(JsonConvert.SerializeObject(evnt));

            newEvnt.Should().NotBeNull();
            newEvnt.Should().BeOfType <CloudEvent>();

            var jobj = JObject.FromObject(newEvnt);

            // Can explicitly deserialize to binary even without data present
            BinaryCloudEvent evnt2 = jobj.ToObject <BinaryCloudEvent>();

            evnt2.Should().NotBeNull();
            evnt2.Data.Should().BeNull();

            // Without a type provided this should deserialize to a generic event
            var evnt3 = CloudEvent.Deserialize(jobj.ToString());

            evnt3.Should().NotBeNull();
            evnt3.Should().BeOfType <CloudEvent>();
        }
示例#2
0
        public void BinaryEvent_ContainsData_Success(string data)
        {
            BinaryCloudEvent evnt = CloudEvent.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), Encoding.UTF8.GetBytes(data));

            evnt.Should().NotBeNull();
            evnt.Should().BeOfType <BinaryCloudEvent>();

            var jobj = JObject.FromObject(evnt);

            // Can explicitly deserialize to binary
            BinaryCloudEvent evnt2 = jobj.ToObject <BinaryCloudEvent>();

            evnt2.Should().NotBeNull();
            evnt2.Data.Should().NotBeNull();

            // Without a type provided this should deserialize to a binary event
            var evnt3 = CloudEvent.Deserialize(jobj.ToString());

            evnt3.Should().NotBeNull();
            evnt3.Should().BeOfType <BinaryCloudEvent>();

            CloudEvent evnt4 = JsonConvert.DeserializeObject <CloudEvent>(jobj.ToString());

            evnt4.Should().NotBeNull();
            evnt4.Should().BeOfType <BinaryCloudEvent>();
        }
示例#3
0
        public void TestStringFilesV02(string fileName)
        {
            var json = File.ReadAllText($@"./V10Tests/samples/string/{fileName}");
            var evnt = CloudEvent.Deserialize(json);

            evnt.Should().BeOfType <StringCloudEvent>();
        }
示例#4
0
        /// <inheritdoc/>
        public async Task <List <CloudEvent> > Get(string after, DateTime?from, DateTime?to, string subject, List <string> source, List <string> type, int size)
        {
            List <CloudEvent> searchResult = new List <CloudEvent>();
            int index = 0;

            using NpgsqlConnection conn = new NpgsqlConnection(_connectionString);
            await conn.OpenAsync();

            NpgsqlCommand pgcom = new NpgsqlCommand(getEventSql, conn);

            pgcom.Parameters.AddWithValue("_subject", NpgsqlDbType.Varchar, subject);
            pgcom.Parameters.AddWithValue("_after", NpgsqlDbType.Varchar, after);
            pgcom.Parameters.AddWithValue("_from", NpgsqlDbType.TimestampTz, from ?? (object)DBNull.Value);
            pgcom.Parameters.AddWithValue("_to", NpgsqlDbType.TimestampTz, to ?? (object)DBNull.Value);
            pgcom.Parameters.AddWithValue("_source", NpgsqlDbType.Array | NpgsqlDbType.Text, source ?? (object)DBNull.Value);
            pgcom.Parameters.AddWithValue("_type", NpgsqlDbType.Array | NpgsqlDbType.Text, type ?? (object)DBNull.Value);

            using (NpgsqlDataReader reader = pgcom.ExecuteReader())
            {
                while (reader.Read() && index < size)
                {
                    CloudEvent cloudEvent = CloudEvent.Deserialize(reader[0].ToString());
                    cloudEvent.Time = cloudEvent.Time.Value.ToUniversalTime();
                    searchResult.Add(cloudEvent);
                    ++index;
                }
            }

            return(searchResult);
        }
示例#5
0
        public void TestJsonFiles(string fileName)
        {
            var json = File.ReadAllText($@"./V10Tests/samples/json/{fileName}");
            var evnt = CloudEvent.Deserialize(json);

            CloudEvent newEvnt = JsonConvert.DeserializeObject <CloudEvent>(JsonConvert.SerializeObject(evnt));

            newEvnt.Should().BeOfType <JsonCloudEvent>();
        }
示例#6
0
        public void TestNoDataFiles(string fileName)
        {
            var json = File.ReadAllText($@"./V10Tests/samples/none/{fileName}");
            var evnt = CloudEvent.Deserialize(json);

            evnt.Should().BeOfType <CloudEvent>();
            evnt.Should().NotBeOfType <JsonCloudEvent>();
            evnt.Should().NotBeOfType <BinaryCloudEvent>();
            evnt.Should().NotBeOfType <StringCloudEvent>();
        }
        /// <inheritdoc/>
        public async Task <List <CloudEvent> > Get(string after, DateTime?from, DateTime?to, string subject, List <string> source, List <string> type, int size)
        {
            List <CloudEvent> searchResult = new List <CloudEvent>();
            int index = 0;

            try
            {
                await _conn.OpenAsync();

                NpgsqlCommand pgcom = new NpgsqlCommand(getEventSql, _conn);
                pgcom.Parameters.AddWithValue("_subject", NpgsqlDbType.Varchar, subject);
                pgcom.Parameters.AddWithValue("_after", NpgsqlDbType.Varchar, after);
                pgcom.Parameters.AddWithValue("_from", NpgsqlDbType.TimestampTz, from ?? (object)DBNull.Value);
                pgcom.Parameters.AddWithValue("_to", NpgsqlDbType.TimestampTz, to ?? (object)DBNull.Value);
                pgcom.Parameters.AddWithValue("_source", NpgsqlDbType.Array | NpgsqlDbType.Text, source ?? (object)DBNull.Value);
                pgcom.Parameters.AddWithValue("_type", NpgsqlDbType.Array | NpgsqlDbType.Text, type ?? (object)DBNull.Value);

                using (NpgsqlDataReader reader = pgcom.ExecuteReader())
                {
                    while (reader.Read() && index < size)
                    {
                        CloudEvent cloudEvent = CloudEvent.Deserialize(reader[0].ToString());
                        cloudEvent.Time = cloudEvent.Time.Value.ToUniversalTime();
                        searchResult.Add(cloudEvent);
                        ++index;
                    }
                }

                return(searchResult);
            }
            catch (Exception e)
            {
                Console.WriteLine($" PostgresRepository // Get // Exception {JsonSerializer.Serialize(e)}");
                throw;
            }
            finally
            {
                await _conn.CloseAsync();
            }
        }