public void UpdateEventWithValidParametersCheckEventIsSentToRepository() { Guid mockEventId = Guid.NewGuid(); Guid userId = Guid.NewGuid(); EventRepositoryMock <ScheduledEvent> .ThrowException = false; EventRepositoryMock <ScheduledEvent> .EventId = mockEventId; EventRepositoryMock <ScheduledEvent> .OwnerId = userId; EventRepositoryMock <ScheduledEvent> .Evt = null; IEvent evt = new ScheduledEvent() { ID = mockEventId, Name = "Test Update", Time = "2015-05-24T17:02:39Z", Active = true }; try { using (EventFacade facade = new EventFacade(mockConnect.Object)) facade.UpdateEvent(userId, evt); } catch (Exception ex) { Assert.Fail("Unexpected exception escaped call to UpdateEvent method in the EventFacade. Exception: {0}", ex.Message); } Assert.AreEqual(evt, EventRepositoryMock <ScheduledEvent> .Evt); }
public void UpdateEventWithEventIdSetToNinesReturnInvalidIEventObjectException() { Guid userId = Guid.NewGuid(); EventRepositoryMock <ScheduledEvent> .ThrowException = false; EventRepositoryMock <ScheduledEvent> .OwnerId = userId; try { using (EventFacade facade = new EventFacade(mockConnect.Object)) { IEvent evt = new ScheduledEvent() { ID = new Guid("99999999-9999-9999-9999-999999999999"), Name = "Test Update", Active = true }; facade.UpdateEvent(userId, evt); } } catch (InvalidIEventObjectException) { Assert.Pass(); } catch (Exception ex) { Assert.Fail("Unexpected exception escaped call to UpdateEvent method in the EventFacade. Exception: {0}", ex.Message); } Assert.Fail("No Exception was bubbled up."); }
//Create a newEvent //Update Event Info public APIResponse Post(Guid userId, ScheduledEvent evt) { try { if (evt.ID == new Guid()) { using (UserFacade userFacade = new UserFacade()) { Guid result = userFacade.CreateEvent(userId, evt); APIResponse response = new APIResponse(APIResponse.ReponseStatus.success, new { EventId = result }); return(response); } } else { using (EventFacade eventFacade = new EventFacade()) eventFacade.UpdateEvent(userId, evt); APIResponse response = new APIResponse(APIResponse.ReponseStatus.success, null); return(response); } } catch (Exception ex) { APIResponse response = new APIResponse(APIResponse.ReponseStatus.error, new { Error = ex.Message }); return(response); } }
public void UpdateEventWhenExceptionHappensInRepositoryCausesExceptionToBubbleUp() { EventRepositoryMock <ScheduledEvent> .ThrowException = true; Guid userId = Guid.NewGuid(); try { using (EventFacade facade = new EventFacade(mockConnect.Object)) { IEvent evt = new ScheduledEvent() { ID = Guid.NewGuid(), Name = "Test Update", Active = true }; facade.UpdateEvent(userId, evt); } } catch (Exception) { Assert.Pass(); } Assert.Fail("Error Message did not bubble up as expected"); }