public async Task PostReturnsBadRequest_WhenIncomingStatusCannotBeMappedToRequestStatus()
        {
            var sut    = new RequestApiController(Mock.Of <IMediator>());
            var result = await sut.Post(new RequestViewModel { Status = "NotMappable" });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 2
0
        public async Task PostReturnsBadRequest_WhenStatusIsNotNew()
        {
            var sut    = new RequestApiController(Mock.Of <IMediator>(), null);
            var result = await sut.Post(new RequestApiViewModel { Status = "NotNew" });

            Assert.IsType <BadRequestResult>(result);
        }
Ejemplo n.º 3
0
        public void PostHasHttpPostAttribute()
        {
            var sut       = new RequestApiController(null);
            var attribute = sut.GetAttributesOn(x => x.Post(It.IsAny <RequestViewModel>())).OfType <HttpPostAttribute>().SingleOrDefault();

            Assert.NotNull(attribute);
        }
        public async Task PostReturnsBadRequest_WhenRequestIdIsNotAGuid()
        {
            var sut    = new RequestApiController(Mock.Of <IMediator>());
            var result = await sut.Post(new RequestViewModel { RequestId = "NotAGuid" });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 5
0
        public async Task PostReturnsBadRequestResultWhenAnErrorIsNotInternal()
        {
            var mediator  = new Mock <IMediator>();
            var outReason = "anythingReally";
            var pid       = "someIDValue";

            var error = new AddRequestError
            {
                ProviderId = pid,
                Reason     = outReason
            };

            mediator.Setup(x => x.SendAsync(It.IsAny <AddRequestCommandAsync>())).ReturnsAsync(error);

            var sut    = new RequestApiController(mediator.Object);
            var result = await sut.Post(new RequestViewModel()) as BadRequestObjectResult;

            Assert.NotNull(result);

            var resultObject = result.Value as AddRequestError;

            Assert.NotNull(resultObject);
            Assert.Equal(outReason, resultObject.Reason);
            Assert.Equal(pid, resultObject.ProviderId);
        }
Ejemplo n.º 6
0
        public async Task PostSendsAddRequestCommandAsyncWithCorrectData()
        {
            var mediator     = new Mock <IMediator>();
            var sut          = new RequestApiController(mediator.Object);
            var ourViewModel = new RequestViewModel
            {
                ProviderId   = "Crazy-Eights",
                ProviderData = "Go-Fish",
                Address      = "Address",
                City         = "Citty",
                State        = "Sttate",
                Zip          = "ZZiipp",
                Phone        = "Fone",
                Name         = "ONAMEO",
                Email        = "ANEMAILADDRESS",
                Status       = RequestStatus.Assigned.ToString()
            };

            await sut.Post(ourViewModel);

            mediator.Verify(x => x.SendAsync(It.Is <AddRequestCommandAsync>(y => y.Request.ProviderId == ourViewModel.ProviderId &&
                                                                            y.Request.Status == RequestStatus.Assigned &&
                                                                            y.Request.ProviderData == ourViewModel.ProviderData &&
                                                                            y.Request.State == ourViewModel.State &&
                                                                            y.Request.Address == ourViewModel.Address &&
                                                                            y.Request.City == ourViewModel.City &&
                                                                            y.Request.Phone == ourViewModel.Phone &&
                                                                            y.Request.Zip == ourViewModel.Zip &&
                                                                            y.Request.Name == ourViewModel.Name &&
                                                                            y.Request.Email == ourViewModel.Email)), Times.Once);
        }
        public async Task PostReturnsBadRequest_WhenProviderIdIsNull()
        {
            var sut    = new RequestApiController(Mock.Of <IMediator>());
            var result = await sut.Post(new RequestViewModel { ProviderId = null });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 8
0
        public async Task PostReturns202StatusCode()
        {
            var sut    = new RequestApiController(Mock.Of <IMediator>(), Mock.Of <IBackgroundJobClient>());
            var result = await sut.Post(new RequestApiViewModel { Status = "new" }) as StatusCodeResult;

            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(result.StatusCode, 202);
        }
Ejemplo n.º 9
0
        public void ControllerHasProducesAtttributeWithTheCorrectContentType()
        {
            var sut       = new RequestApiController(null);
            var attribute = sut.GetAttributes().OfType <ProducesAttribute>().SingleOrDefault();

            Assert.NotNull(attribute);
            Assert.Equal(attribute.ContentTypes.Select(x => x).First(), "application/json");
        }
Ejemplo n.º 10
0
        public void ControllerHasRouteAtttributeWithTheCorrectRoute()
        {
            var sut       = new RequestApiController(null);
            var attribute = sut.GetAttributes().OfType <RouteAttribute>().SingleOrDefault();

            Assert.NotNull(attribute);
            Assert.Equal(attribute.Template, "api/request");
        }
Ejemplo n.º 11
0
        public async Task PostReturnsBadRequest_WhenModelStateIsInvalid()
        {
            var sut = new RequestApiController(Mock.Of <IMediator>(), null);

            sut.AddModelStateError();
            var result = await sut.Post(new RequestApiViewModel());

            Assert.IsType <BadRequestResult>(result);
        }
Ejemplo n.º 12
0
        public async Task PostSendsRequestExistsByProviderIdQueryWithCorrectProviderRequestId()
        {
            const string providerRequestId = "ProviderRequestId";

            var mediator = new Mock <IMediator>();
            var sut      = new RequestApiController(mediator.Object, Mock.Of <IBackgroundJobClient>());
            await sut.Post(new RequestApiViewModel { Status = "new", ProviderRequestId = providerRequestId });

            mediator.Verify(x => x.SendAsync(It.Is <RequestExistsByProviderIdQuery>(y => y.ProviderRequestId == providerRequestId)), Times.Once);
        }
Ejemplo n.º 13
0
        public async Task PostReturnsHttpStatusCodeResultOf201()
        {
            var mediator = new Mock <IMediator>();
            var sut      = new RequestApiController(mediator.Object);

            var result = await sut.Post(new RequestViewModel()) as CreatedResult;

            Assert.NotNull(result);
            Assert.Equal(result.StatusCode, 201);
        }
        public async Task PostReturnsCreatedResult()
        {
            var mediator  = new Mock <IMediator>();
            var viewModel = new RequestViewModel {
                ProviderId = "ProviderId", RequestId = Guid.NewGuid().ToString()
            };

            var sut    = new RequestApiController(mediator.Object);
            var result = await sut.Post(viewModel);

            Assert.IsType <CreatedResult>(result);
        }
        public async Task PostSendsAddApiRequestCommandWithCorrectViewModel()
        {
            var viewModel = new RequestApiViewModel {
                Status = "new"
            };
            var mediator = new Mock <IMediator>();

            var sut = new RequestApiController(mediator.Object);
            await sut.Post(viewModel);

            mediator.Verify(x => x.SendAsync(It.Is <AddApiRequestCommand>(y => y.ViewModel == viewModel)), Times.Once);
        }
        public async Task PostSendsAddRequestCommandWithTheCorrectParameters()
        {
            var mediator  = new Mock <IMediator>();
            var viewModel = new RequestViewModel {
                ProviderId = "ProviderId", RequestId = Guid.NewGuid().ToString()
            };

            var sut = new RequestApiController(mediator.Object);
            await sut.Post(viewModel);

            mediator.Verify(x => x.SendAsync(It.Is <AddApiRequestCommand>((y => y.RequestViewModel == viewModel))));
        }
Ejemplo n.º 17
0
        public async Task PostReturnsBadRequest_WhenRequestAlreadyExists()
        {
            const string providerRequestId = "ProviderRequestId";

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <RequestExistsByProviderIdQuery>())).ReturnsAsync(true);

            var sut    = new RequestApiController(mediator.Object, null);
            var result = await sut.Post(new RequestApiViewModel { Status = "new", ProviderRequestId = providerRequestId });

            Assert.IsType <BadRequestResult>(result);
        }
Ejemplo n.º 18
0
        public async Task PostReturns202StatusCode()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <ValidatePhoneNumberRequestCommand>())).ReturnsAsync(new ValidatePhoneNumberResult {
                IsValid = true, PhoneNumberE164 = "0000"
            });

            var sut    = new RequestApiController(mediator.Object, Mock.Of <IBackgroundJobClient>());
            var result = await sut.Post(new RequestApiViewModel { Status = "new" }) as StatusCodeResult;

            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(result.StatusCode, 202);
        }
Ejemplo n.º 19
0
        public async Task PostSendsRequestExistsByProviderIdQueryWithCorrectProviderRequestId()
        {
            const string providerRequestId = "ProviderRequestId";

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <ValidatePhoneNumberRequestCommand>())).ReturnsAsync(new ValidatePhoneNumberResult {
                IsValid = true, PhoneNumberE164 = "0000"
            });

            var sut = new RequestApiController(mediator.Object, Mock.Of <IBackgroundJobClient>());
            await sut.Post(new RequestApiViewModel { Status = "new", ProviderRequestId = providerRequestId });

            mediator.Verify(x => x.SendAsync(It.Is <RequestExistsByProviderIdQuery>(y => y.ProviderRequestId == providerRequestId)), Times.Once);
        }
Ejemplo n.º 20
0
        public async Task PostEnqueuesProcessApiRequestsJobWithCorrectViewModel()
        {
            var viewModel = new RequestApiViewModel {
                Status = "new"
            };
            var mediator            = new Mock <IMediator>();
            var backgroundJobClient = new Mock <IBackgroundJobClient>();

            var sut = new RequestApiController(mediator.Object, backgroundJobClient.Object);
            await sut.Post(viewModel);

            backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job =>
                                                                 job.Method.Name == nameof(ProcessApiRequests.Process) &&
                                                                 job.Args[0] == viewModel), It.IsAny <EnqueuedState>()), Times.Once);
        }
Ejemplo n.º 21
0
        public async Task PostEnqueuesProcessApiRequestsJobWithCorrectViewModel()
        {
            var viewModel = new RequestApiViewModel {
                Status = "new"
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <ValidatePhoneNumberRequestCommand>())).ReturnsAsync(new ValidatePhoneNumberResult {
                IsValid = true, PhoneNumberE164 = "0000"
            });

            var backgroundJobClient = new Mock <IBackgroundJobClient>();

            var sut = new RequestApiController(mediator.Object, backgroundJobClient.Object);
            await sut.Post(viewModel);

            backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job =>
                                                                 job.Method.Name == nameof(ProcessApiRequests.Process) &&
                                                                 job.Args[0] == viewModel), It.IsAny <EnqueuedState>()), Times.Once);
        }