Exemplo n.º 1
0
        public void Given_InvalidContentType_When_DataIsSet_Should_ThrowException()
        {
            var content = "hello world";
            var data    = Encoding.UTF8.GetBytes(content);

            var ev = new BinaryEvent();

            ev.ContentType = "text/plain";
            Action action = () => ev.Data = data;

            action.Should().Throw <InvalidDataTypeException>();

            ev.ContentType = "text/json";
            action         = () => ev.Data = data;
            action.Should().Throw <InvalidDataTypeException>();

            ev.ContentType = "application/json";
            action         = () => ev.Data = data;
            action.Should().Throw <InvalidDataTypeException>();

            ev.ContentType = "application/json-seq";
            action         = () => ev.Data = data;
            action.Should().Throw <InvalidDataTypeException>();

            ev.ContentType = "application/cloudevents+json";
            action         = () => ev.Data = data;
            action.Should().Throw <InvalidDataTypeException>();

            ev.ContentType = "application/geo+json-seq";
            action         = () => ev.Data = data;
            action.Should().Throw <InvalidDataTypeException>();
        }
Exemplo n.º 2
0
        public void Given_NoRequiredProperties_When_Serialised_Should_ThrowException()
        {
            var ev = new BinaryEvent();

            Action action = () => JsonConvert.SerializeObject(ev);

            action.Should().Throw <JsonSerializationException>();

            ev.EventType = null;
            ev.Source    = (new Uri("http://localhost")).ToString();
            ev.EventId   = Guid.NewGuid().ToString();
            action       = () => JsonConvert.SerializeObject(ev);
            action.Should().Throw <JsonSerializationException>();

            ev.EventType = "com.example.someevent";
            ev.Source    = null;
            ev.EventId   = Guid.NewGuid().ToString();
            action       = () => JsonConvert.SerializeObject(ev);
            action.Should().Throw <JsonSerializationException>();

            ev.EventType = "com.example.someevent";
            ev.Source    = (new Uri("http://localhost")).ToString();
            ev.EventId   = null;
            action       = () => JsonConvert.SerializeObject(ev);
            action.Should().Throw <JsonSerializationException>();
        }
Exemplo n.º 3
0
        public void Given_Version_Should_HaveVersion()
        {
            var version = "v1";

            var ev = new BinaryEvent(version);

            ev.CloudEventsVersion.Should().Be(version);
        }
Exemplo n.º 4
0
        public void Given_RequiredProperties_When_Serialised_Should_BeOk()
        {
            var ev = new BinaryEvent();

            ev.EventType = "com.example.someevent";
            ev.Source    = (new Uri("http://localhost")).ToString();
            ev.EventId   = Guid.NewGuid().ToString();

            var    serialised = string.Empty;
            Action action     = () => serialised = JsonConvert.SerializeObject(ev);

            action.Should().NotThrow <Exception>();
        }
Exemplo n.º 5
0
        public void Given_ValidContentType_When_DataIsSet_Should_BeOk()
        {
            var content = "hello world";
            var data    = Encoding.UTF8.GetBytes(content);

            var ev = new BinaryEvent();

            ev.ContentType = "application/octet-stream";
            ev.Data        = data;

            var result = Encoding.UTF8.GetString(ev.Data);

            result.Should().Be(content);
        }
Exemplo n.º 6
0
        public void MapWorldOutputs()
        {
            // Rescale data from world to wrapper
            m_kernel.Run(Visual, School.VisualFOV, Scene.Width, Scene.Height, Viewport.Width, Viewport.Height);
            m_grayscaleKernel.Run(School.VisualFOV, School.VisualFOV, Viewport.Width * Viewport.Height);

            // Copy of structured data
            Event.CopyToMemoryBlock(School.Data, 0, 0, 1);
            BallPosX.CopyToMemoryBlock(School.Data, 0, 1, 1);
            BallPosY.CopyToMemoryBlock(School.Data, 0, 2, 1);
            PaddlePosX.CopyToMemoryBlock(School.Data, 0, 3, 1);
            PaddlePosY.CopyToMemoryBlock(School.Data, 0, 4, 1);
            BinaryEvent.CopyToMemoryBlock(School.Data, 0, 5, 1);

            //schoolWorld.VisualFOV.Dims = VisualFOF.Dims;
            School.DataLength.Fill(6);
        }
Exemplo n.º 7
0
        public async Task AddEvent(string eventName, string eventListName, string path)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Loaded data
            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);

            //Load
            EventArray.Load(path, ref entry);

            bool eventExists = false;

            for (int i = 0; i < entry.Events.Length; i++)
            {
                if (entry.Events[i].EventName == eventName)
                {
                    eventExists = true;
                    break;
                }
            }

            if (!eventExists)
            {
                //Modify
                List <BinaryEvent> eventEntries = entry.Events.ToList();
                BinaryEvent        eventEntry   = new BinaryEvent(eventName, -1, new BinaryEventSchedule[0]);
                eventEntries.Add(eventEntry);
                entry.Events = eventEntries.ToArray();
                //Save
                EventArray.Save(path, entry);

                eb.Title = "**🗓️ " + eventName + " has been added to the " + eventListName + " events list!**";
                eb.WithColor(Color.Green);
            }
            else
            {
                eb.Title = "**🚫 The event " + eventName + " already exists!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
Exemplo n.º 8
0
        public void Given_Data_When_Serialised_Should_BeBase64EncodedData()
        {
            var content = "hello world";
            var data    = Encoding.UTF8.GetBytes(content);
            var encoded = Convert.ToBase64String(data);

            var ev = new BinaryEvent();

            ev.EventType   = "com.example.someevent";
            ev.Source      = (new Uri("http://localhost")).ToString();
            ev.EventId     = Guid.NewGuid().ToString();
            ev.ContentType = "application/octet-stream";
            ev.Data        = data;

            var serialised   = JsonConvert.SerializeObject(ev);
            var deserialised = JsonConvert.DeserializeObject <JObject>(serialised);

            deserialised["data"].Should().NotBeNull();
            deserialised["data"].ToString().Should().Be(encoded);
        }
Exemplo n.º 9
0
        // not native name
        private static void LogBinaryEvent(MessageData mdata, DWMessage packet)
        {
            var data = packet.ByteBuffer.ReadBlob();
            var type = packet.ByteBuffer.ReadUInt32();

            var e = new BinaryEvent()
            {
                data = data,
                type = (int)type
            };

            Database.ABlobEvents.Insert(e);

            Log.Debug("Inserted a binary event of type " + type);

            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)8);
            reply.ByteBuffer.Write(0);
            reply.ByteBuffer.Write(0);
        }
Exemplo n.º 10
0
        public void Given_NoVersion_Should_HaveDefaultCloudEventsVersion()
        {
            var ev = new BinaryEvent();

            ev.CloudEventsVersion.Should().Be(CloudEventsVersion.Version01);
        }