public void PublishApiRequestAddedNotificationWithFalseAcceptanceWhenOutsideApprovedRegions() { var mediator = new Mock <IMediator>(); var approvedRegions = Options.Create(new ApprovedRegionsSettings { Enabled = true, Regions = new List <string> { "approved_region" } }); var sut = new ProcessApiRequests(Context, mediator.Object, Mock.Of <IGeocodeService>(), approvedRegions) { NewRequestId = () => Guid.NewGuid() }; sut.Process(new RequestApiViewModel { ProviderData = "non_approved_region" }); mediator.Verify(x => x.Publish(It.Is <ApiRequestProcessedNotification>(y => y.Acceptance == false)), Times.Once); }
public void AssignCorrectValuesToRequestsLatitiudeAndLongitudeWhenIGeocoderReturnedAdressIsNotNull() { var requestId = Guid.NewGuid(); var latitude = 20.013; var longitude = 40.058; var geocoder = new Mock <IGeocodeService>(); geocoder.Setup(service => service.GetCoordinatesFromAddress(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(() => Task.FromResult(new Coordinates(latitude, longitude))); var sut = new ProcessApiRequests(Context, Mock.Of <IMediator>(), geocoder.Object, Options.Create(new ApprovedRegionsSettings())) { NewRequestId = () => requestId }; sut.Process(new RequestApiViewModel()); var request = Context.Requests.Single(r => r.RequestId == requestId); request.Latitude.ShouldBe(latitude); request.Longitude.ShouldBe(longitude); }
public void PublishApiRequestAddedNotificationWithTheCorrectRequestId() { var requestId = Guid.NewGuid(); var mediator = new Mock <IMediator>(); var sut = new ProcessApiRequests(Context, mediator.Object, Mock.Of <IGeocodeService>(), Options.Create(new ApprovedRegionsSettings())) { NewRequestId = () => requestId }; sut.Process(new RequestApiViewModel()); mediator.Verify(x => x.Publish(It.Is <ApiRequestProcessedNotification>(y => y.RequestId == requestId)), Times.Once); }
public void InvokeISendRequestStatusToGetASmokeAlarmWithAnAcceptanceOfTrue_WhenApprovedRegionsAreDisabled() { var viewModel = new RequestApiViewModel { ProviderRequestId = "1" }; var backgroundJobClient = new Mock <IBackgroundJobClient>(); var sut = new ProcessApiRequests(Context, Mock.Of <IGeocodeService>(), Options.Create(new ApprovedRegionsSettings()), backgroundJobClient.Object); sut.Process(viewModel); backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job => (bool)job.Args[2]), It.IsAny <EnqueuedState>())); }
public void InvokeIGeocoderWithTheCorrectParameters() { var requestId = Guid.NewGuid(); var geoCoder = new Mock <IGeocodeService>(); var viewModel = new RequestApiViewModel { Address = "address", City = "city", State = "state", Zip = "zip" }; var sut = new ProcessApiRequests(Context, Mock.Of <IMediator>(), geoCoder.Object, Options.Create(new ApprovedRegionsSettings())) { NewRequestId = () => requestId }; sut.Process(viewModel); geoCoder.Verify(x => x.GetCoordinatesFromAddress(viewModel.Address, viewModel.City, viewModel.State, viewModel.Zip, string.Empty), Times.Once); }
public void InvokeISendRequestStatusToGetASmokeAlarmWithTheCorrectProviderRequestIdAndStatus() { var viewModel = new RequestApiViewModel { ProviderRequestId = "1" }; var backgroundJobClient = new Mock <IBackgroundJobClient>(); var sut = new ProcessApiRequests(Context, Mock.Of <IGeocodeService>(), Options.Create(new ApprovedRegionsSettings()), backgroundJobClient.Object); sut.Process(viewModel); backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job => job.Method.Name == nameof(ISendRequestStatusToGetASmokeAlarm.Send) && job.Args[0].ToString() == viewModel.ProviderRequestId && job.Args[1].ToString() == GasaStatus.New), It.IsAny <EnqueuedState>())); }
public void InvokeISendRequestStatusToGetASmokeAlarmWithAnAcceptanceOfFalse_WhenApprovedRegionsAreEnabledAndRegionIsNotApproved() { var viewModel = new RequestApiViewModel { ProviderRequestId = "1", ProviderData = "region" }; var backgroundJobClient = new Mock <IBackgroundJobClient>(); var sut = new ProcessApiRequests(Context, Mock.Of <IGeocodeService>(), Options.Create(new ApprovedRegionsSettings { Enabled = true, Regions = new List <string> { "UnapprovedRegion" } }), backgroundJobClient.Object); sut.Process(viewModel); backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job => (bool)job.Args[2] == false), It.IsAny <EnqueuedState>())); }
public void AddRequest() { var requestId = Guid.NewGuid(); var dateAdded = DateTime.UtcNow; const string postalCode = "11111"; var viewModel = new RequestApiViewModel { ProviderRequestId = "ProviderRequestId", Status = "new", Name = "Name", Address = "Address", City = "City", State = "state", Zip = postalCode, Phone = "111-111-1111", Email = "*****@*****.**", ProviderData = "ProviderData" }; var sut = new ProcessApiRequests(Context, Mock.Of <IMediator>(), Mock.Of <IGeocodeService>(), Options.Create(new ApprovedRegionsSettings())) { NewRequestId = () => requestId, DateTimeUtcNow = () => dateAdded }; sut.Process(viewModel); var request = Context.Requests.Single(x => x.RequestId == requestId); Assert.Equal(request.RequestId, requestId); Assert.Equal(request.OrganizationId, 1); Assert.Equal(request.ProviderRequestId, viewModel.ProviderRequestId); Assert.Equal(request.ProviderData, viewModel.ProviderData); Assert.Equal(request.Address, viewModel.Address); Assert.Equal(request.City, viewModel.City); Assert.Equal(request.DateAdded, dateAdded); Assert.Equal(request.Email, viewModel.Email); Assert.Equal(request.Name, viewModel.Name); Assert.Equal(request.State, viewModel.State); Assert.Equal(request.Zip, viewModel.Zip); Assert.Equal(request.Status, RequestStatus.Unassigned); Assert.Equal(request.Source, RequestSource.Api); }
public void PublishApiRequestAddedNotificationWithTheCorrectProviderRequestId() { const string providerRequestId = "ProviderRequestId"; var requestId = Guid.NewGuid(); var viewModel = new RequestApiViewModel { ProviderRequestId = providerRequestId }; var mediator = new Mock <IMediator>(); var sut = new ProcessApiRequests(Context, mediator.Object, Mock.Of <IGeocoder>()) { NewRequestId = () => requestId }; sut.Process(viewModel); mediator.Verify(x => x.Publish(It.Is <ApiRequestProcessedNotification>(y => y.ProviderRequestId == providerRequestId)), Times.Once); }
public void AssignCorrectValuesToRequestsLatitiudeAndLongitudeWhenIGeocoderReturnedAdressIsNull() { var requestId = Guid.NewGuid(); var geocoder = new Mock <IGeocodeService>(); geocoder.Setup(service => service.GetCoordinatesFromAddress(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(null); var sut = new ProcessApiRequests(Context, geocoder.Object, Options.Create(new ApprovedRegionsSettings()), Mock.Of <IBackgroundJobClient>()) { NewRequestId = () => requestId }; sut.Process(new RequestApiViewModel()); var request = Context.Requests.Single(r => r.RequestId == requestId); request.Latitude.ShouldBe(0); request.Longitude.ShouldBe(0); }
public void NotSaveRequestNotInvokeIGeocodeServiceAndNotNotEnqueueISendRequestStatusToGetASmokeAlarm_WhenRequestExists() { const string providerRequestId = "1"; var model = new RequestApiViewModel { ProviderRequestId = providerRequestId }; Context.Requests.Add(new Request { ProviderRequestId = providerRequestId }); Context.SaveChanges(); var geocodeService = new Mock <IGeocodeService>(); var backgroundJobClient = new Mock <IBackgroundJobClient>(); var sut = new ProcessApiRequests(Context, geocodeService.Object, Mock.Of <IOptions <ApprovedRegionsSettings> >(), backgroundJobClient.Object); sut.Process(model); Assert.Equal(Context.Requests.Count(x => x.ProviderRequestId == providerRequestId), 1); geocodeService.Verify(x => x.GetCoordinatesFromAddress(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job => job.Method.Name == nameof(ISendRequestStatusToGetASmokeAlarm.Send)), It.IsAny <EnqueuedState>()), Times.Never); }