public string Get(IChatMessageEnvelope request) { try { if (Tack == null) { throw new InvalidOperationException(ExceptionMessage_ITackCannotBeNull); } else { //NOTE: Define the query request.Query = (chatMessageQueryRepo, chatMessageEnvelopeParam) => { IChatMessageEnvelope nextChatMessage = chatMessageQueryRepo.GetLatestChatMessage(chatMessageEnvelopeParam); return(nextChatMessage); }; IChatMessageEnvelope responseEnvelope = (IChatMessageEnvelope)Tack.GET(request); string responseString = _marshaller.MarshallPayloadJSON(responseEnvelope); return(responseString); } } catch (InvalidOperationException ex) { throw new InvalidOperationException(ex.Message, ex); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public IChatMessageEnvelope GetByID(IChatMessageEnvelope request) { try { if (Tack == null) { throw new InvalidOperationException(ExceptionMessage_ITackCannotBeNull); } else { //NOTE: Define the query request.Query = (chatMessageQueryRepo, chatMessageEnvelopeParam) => { IChatMessageEnvelope nextChatMessage = chatMessageQueryRepo.GetChatMessageByID(chatMessageEnvelopeParam); return(nextChatMessage); }; return((IChatMessageEnvelope)Tack.GET(request)); } } catch (InvalidOperationException ex) { throw new InvalidOperationException(ex.Message, ex); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public void TestITackCRUD() { IBoards boards = GetMockedIBoards(); IEnvelope envelope = _erector.Container.Resolve <IEnvelope>(); envelope.ServiceRoute = "ChatMessage"; IChatMessageEnvelope chatMessageEnvelope = _erector.Container.Resolve <IChatMessageEnvelope>(); chatMessageEnvelope.ServiceRoute = "ChatMessage"; //Boards cannot be null. ITack nullBoardsTack = new Tack(null); try { IEnvelope envelopeNullBoard = nullBoardsTack.GET(envelope); Assert.Fail(); } catch (InvalidOperationException ex) { string message = ex.Message; Assert.AreEqual(message, nullBoardsTack.ExceptionMessage_BoardsCannotBeNull); } ITack tack = new Tack(boards); //Create IEnvelope createEnvelope = tack.POST(envelope); Assert.IsNotNull(createEnvelope); Assert.AreEqual(createEnvelope.ServiceRoute, envelope.ServiceRoute); IEnvelope createChatMessageEnvelope = tack.POST(chatMessageEnvelope); Assert.IsNotNull(createChatMessageEnvelope); Assert.AreEqual(createChatMessageEnvelope.ServiceRoute, envelope.ServiceRoute); Assert.IsTrue(createChatMessageEnvelope.GetType() == typeof(ChatMessageEnvelope)); //Read IEnvelope readEnvelope = tack.GET(envelope); Assert.IsNotNull(readEnvelope); Assert.AreEqual(readEnvelope.ServiceRoute, envelope.ServiceRoute); IEnvelope readChatMessageEnvelope = tack.GET(chatMessageEnvelope); Assert.IsNotNull(readChatMessageEnvelope); Assert.AreEqual(readChatMessageEnvelope.ServiceRoute, envelope.ServiceRoute); Assert.IsTrue(readChatMessageEnvelope.GetType() == typeof(ChatMessageEnvelope)); //Update IEnvelope updateEnvelope = tack.PUT(envelope); Assert.IsNotNull(updateEnvelope); Assert.AreEqual(updateEnvelope.ServiceRoute, envelope.ServiceRoute); IEnvelope updateChatMessageEnvelope = tack.PUT(chatMessageEnvelope); Assert.IsNotNull(updateChatMessageEnvelope); Assert.AreEqual(updateChatMessageEnvelope.ServiceRoute, envelope.ServiceRoute); Assert.IsTrue(updateChatMessageEnvelope.GetType() == typeof(ChatMessageEnvelope)); //Delete IEnvelope deleteEnvelope = tack.DELETE(envelope); Assert.IsNotNull(deleteEnvelope); Assert.AreEqual(deleteEnvelope.ServiceRoute, envelope.ServiceRoute); IEnvelope deleteChatMessageEnvelope = tack.DELETE(chatMessageEnvelope); Assert.IsNotNull(deleteChatMessageEnvelope); Assert.AreEqual(deleteChatMessageEnvelope.ServiceRoute, envelope.ServiceRoute); Assert.IsTrue(deleteChatMessageEnvelope.GetType() == typeof(ChatMessageEnvelope)); }