public void SubscribeToParcel_IsOk() { string trackingId = "ABCD12345"; string url = "url"; Mock <IWebhookRepository> webMock = new Mock <IWebhookRepository>(); Mock <IParcelRepository> parcelMock = new Mock <IParcelRepository>(); parcelMock.Setup(foo => foo.GetByTrackingId(trackingId)).Returns(new Data.Parcel()); Data.Webhook webhook = new Data.Webhook() { CreatedAt = DateTime.Now, TrackingId = trackingId, Url = url }; webMock.Setup(foo => foo.Create(webhook)); IWebhookLogic webhookLogic = new WebhookLogic(mapper, webMock.Object, parcelMock.Object, NullLogger <WebhookLogic> .Instance); webhookLogic.SubscribeToParcel(trackingId, url); }
public void SubscribeToParcel(string trackingId, string url) { try { logger.LogDebug($"Checking if Parcel with trackingId {trackingId} exists"); parcelRepository.GetByTrackingId(trackingId); // if it doesnt throw an error it found a parcel DateTime currentTime = DateTime.Now; Data.Webhook webhook = new Data.Webhook() { TrackingId = trackingId, Url = url, CreatedAt = currentTime }; logger.LogDebug($"Creating entry for webhook with trackingId: {trackingId}, url: {url}, createdAt: {currentTime}"); webhookRepository.Create(webhook); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } }