예제 #1
0
        public void ProcessRequestTest_POST()
        {
            // Arrange
            EAEPMessage message = new EAEPMessage("host1", "app1", "event1");

            var store = new Mock<IEAEPMonitorStore>();
            store
                .Setup(x => x.PushMessages(It.Is<EAEPMessages>
                        (ms => ms[0].Host == message.Host && ms[0].Application == message.Application && ms[0].Event == message.Event)
                    ))
                .Verifiable();

            var request = new Mock<IServiceRequest>();
            request.SetupGet(x => x.Method).Returns("POST");
            request.SetupGet(x => x.ResourceName).Returns("event");
            request.SetupGet(x => x.Body).Returns(message.ToString());

            var response = new Mock<IServiceResponse>();
            response.SetupProperty(x => x.StatusCode);

            EventService target = new EventService(store.Object);

            // Act
            target.ProcessRequest(request.Object, response.Object, null);

            // Assert
            store.VerifyAll();
            Assert.AreEqual(Constants.HTTP_200_OK, response.Object.StatusCode);
        }
예제 #2
0
파일: SearchPage.cs 프로젝트: adambird/eaep
        private void WriteResultItem(StreamWriter targetWriter, string template, EAEPMessage message)
        {
            Hashtable values = new Hashtable();
            values.Add("message", ReplaceCRLFwithHTMLLineBreaks(message.ToString()));
            values.Add("host", CreateSearchLink(EAEPMessage.FIELD_HOST, message.Host, message.Host));
            values.Add("app", CreateSearchLink(EAEPMessage.FIELD_APPLICATION, message.Application, message.Application));
            values.Add("event", CreateSearchLink(EAEPMessage.FIELD_EVENT, message.Event, message.Event));
            values.Add("timestamp", message.TimeStamp.ToString(EAEPMessage.TIMESTAMP_FORMAT));

            StringBuilder parameters = new StringBuilder();
            StringWriter parametersWriter = new StringWriter(parameters);
            foreach (string parameter in message.ParameterKeys)
            {
                // only write out if not a reserved parameter name, displayed above
                if (EAEPMessage.ParamNameIsValid(parameter))
                {
                    parametersWriter.WriteLine(CreateSearchLink(parameter, message[parameter], string.Format("{0}={1}", parameter, message[parameter])));
                }
            }
            values.Add("params", parameters.ToString());

            targetWriter.WriteLine(TemplateParser.Parse(template, values));
        }
예제 #3
0
        public void WithParamValueWithParamDelimiter_SerializesThenDeserializesWithoutError_AndWithOriginalValue()
        {
            // arrange
            var paramValueWithDelimiter = @"start of value=end of value after delimiter";
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");

            // act
            message["param"] = paramValueWithDelimiter;

            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.AreEqual(paramValueWithDelimiter, deserializedMessage["param"]);
        }
예제 #4
0
        public void WithParamValueWithEndOfMessageCharacters_SerializesThenDeserializesWithoutError_AndWithOriginalValue()
        {
            // arrange
            var paramValueWithEndOfMessageCharacters = @"start of value---end of value after end of message";
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");

            // actl
            message["param"] = paramValueWithEndOfMessageCharacters;

            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.AreEqual(paramValueWithEndOfMessageCharacters, deserializedMessage["param"]);
        }
예제 #5
0
        public void WithParamValueContainingNewLine_SerializesThenDeserializesWithoutError_AndWithOriginalValue()
        {
            // arrange
            var paramValueWithNewLine = @"this value
            is on more than one line";
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");

            // act
            message["param"] = paramValueWithNewLine;

            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.AreEqual(paramValueWithNewLine, deserializedMessage["param"]);
        }
예제 #6
0
        public void WithComplexParameterValue_EaepMessageSerializes_AndDeserializesOk()
        {
            // arrange
            var paramValue = "This=Parameter Is\r\nComplex";
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");

            // act
            message["param"] = paramValue;

            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.AreEqual(paramValue, deserializedMessage["param"]);
        }
예제 #7
0
        public void ToStringTest()
        {
            // Arrange
            var message = new EAEPMessage
                          {
                              Version = "1.0",
                              Host = "app1",
                              Application = "ecommerce",
                              Event = "purchase",
                              TimeStamp =
                                  DateTime.ParseExact("12-03-2007-12:33:59.123", EAEPMessage.TIMESTAMP_FORMAT,
                                                      CultureInfo.InvariantCulture)
                          };
            message["value"] = "25.00";
            message["currency"] = "EUR";
            message["user"] = "******";

            const string expectedString = "EAEP 1.0 12-03-2007-12:33:59.123\r\napp1 ecommerce purchase\r\nvalue=25.00\r\ncurrency=EUR\r\nuser=user%40company.com\r\n" + EAEPMessage.END_OF_MESSAGE + "\r\n";

            // Act / Assert
            Assert.AreEqual(expectedString, message.ToString());
        }
예제 #8
0
        public void SerializeAndDeserialize_EaepMessage_WithNullParameterValue()
        {
            // arrange
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");
            message["param"] = null;

            // act
            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.IsTrue(string.IsNullOrEmpty(deserializedMessage["param"]));
        }
예제 #9
0
        public void LoadSerialisedTest()
        {
            // Arrange
            var expectedMessage = new EAEPMessage("host1", "app1", "loadpage")
                                  {
                                      TimeStamp = DateTime.Now
                                  };
            expectedMessage["user"] = "******";

            // Act
            var actualMessage = new EAEPMessage(expectedMessage.ToString());

            // Assert
            Assert.AreEqual(expectedMessage, actualMessage);
        }
예제 #10
0
        public void ExampleMessage_EaepMessageSerializesOk()
        {
            var paramValue = @"Jim Parker, 447974326623, 1 pax, GVA-Landry,
            newcastle - 6465 - 13:35, paid";
            var message = new EAEPMessage(DateTime.UtcNow, "host", "app", "event");

            // act
            message["param"] = paramValue;

            var serialized = message.ToString();

            var deserializedMessage = new EAEPMessage(serialized);

            // assert
            Assert.AreEqual(paramValue, deserializedMessage["param"]);
        }
예제 #11
0
        public void LogEvent()
        {
            //  arrange
            const string application = "signUp";
            const string host = "local";
            const string eventName = "buttonClick";

            var timeStamp = new DateTime(2000, 1, 1);

            var expectedMessage = new EAEPMessage(timeStamp,
                host,
                application,
                eventName);

            expectedMessage.Parameters["name1"] = "value1";
            expectedMessage.Parameters["name2"] = "value2";

            var expectedBytes = Encoding.UTF8.GetBytes(expectedMessage.ToString());
            var mockMulticaster = new Mock<IMulticastSender>();
            var broadcaster = new EAEPBroadcaster(host, application, mockMulticaster.Object);

            //  act
            broadcaster.LogEvent(timeStamp,
                eventName,
                new EventParameter("name1", "value1"),
                new EventParameter("name2", "value2"));

            //  assert
            mockMulticaster.Verify(m => m.Send(expectedBytes), Times.Once());
        }
예제 #12
0
        public void PushMessage(EAEPMessage message)
        {
            try
            {
                using (SqlConnection connection = GetConnection())
                {
                    SqlTransaction transaction = connection.BeginTransaction();
                    log.Debug("Initiated Push Message transaction");

                    try
                    {
                        long messageID = 0;

                        using (SqlCommand pushMessageCommand = new SqlCommand(PUSH_MESSAGE_SQL, connection, transaction))
                        {
                            pushMessageCommand.CommandTimeout = Configuration.DefaultQueryTimeout;

                            pushMessageCommand.Parameters.AddWithValue("@message", message.ToString());
                            pushMessageCommand.Parameters.AddWithValue("@timestamp", message.TimeStamp);
                            SqlParameter idParam = pushMessageCommand.Parameters.Add("@id", SqlDbType.BigInt);
                            idParam.Direction = ParameterDirection.Output;

                            pushMessageCommand.ExecuteNonQuery();

                            messageID = (long)idParam.Value;
                        }

                        using (SqlCommand pushFieldCommand = new SqlCommand(PUSH_FIELD_SQL, connection, transaction))
                        {
                            pushFieldCommand.CommandTimeout = Configuration.DefaultQueryTimeout;

                            pushFieldCommand.Parameters.Add("@messageID", SqlDbType.BigInt);
                            pushFieldCommand.Parameters.Add("@field", SqlDbType.NVarChar);
                            pushFieldCommand.Parameters.Add("@value", SqlDbType.NVarChar);

                            PushField(pushFieldCommand, messageID, EAEPMessage.FIELD_APPLICATION, message.Application);
                            PushField(pushFieldCommand, messageID, EAEPMessage.FIELD_HOST, message.Host);
                            PushField(pushFieldCommand, messageID, EAEPMessage.FIELD_EVENT, message.Event);

                            foreach (string field in message.ParameterKeys)
                            {
                                PushField(pushFieldCommand, messageID, field, message[field]);
                            }
                        }

                        transaction.Commit();
                        log.Debug("Committed Push Message transaction");
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        log.Error("Error persisting message", ex);
                    }
                }
            }
            catch (SqlException ex)
            {
                log.Warn(ex);
                throw new MessagePersistanceException(ex.Message);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new MessagePersistanceException(ex.Message);
            }
        }