コード例 #1
0
        public void UnknownRequestResultsInNotFound()
        {
            var mock = new Mock <ICreateProductRequestJournal>();

            mock.Setup(m => m.Lookup(It.IsAny <Guid>())).Returns(() => default(JournalEntry <CreateProductRequest>));
            var controller = new CreateProductRequestQueueController(mock.Object);
            var response   = controller.Get(new Guid("12345678901234567890123456789012").ToString());
            var result     = Assert.IsType <NotFoundResult>(response);
        }
コード例 #2
0
        public void InvalidGuidResultsInBadRequest()
        {
            var mock          = new Mock <ICreateProductRequestJournal>();
            var controller    = new CreateProductRequestQueueController(mock.Object);
            var response      = controller.Get("ZZZ");
            var result        = Assert.IsType <BadRequestObjectResult>(response);
            var errorResponse = Assert.IsType <ErrorResponse>(result.Value);

            Assert.Equal("malformed request id", errorResponse.Error.Message.Text);
        }
コード例 #3
0
        public void PostRequestWithNullRequestResultsInBadRequest()
        {
            var mock = new Mock <ICreateProductRequestJournal>();

            mock.Setup(m => m.Book(It.IsAny <CreateProductRequest>())).Returns(new Guid("12345678901234567890123456789012"));
            var controller = new CreateProductRequestQueueController(mock.Object);

            var result = controller.Get(null);

            var acceptedResult = Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #4
0
        public void PendingRequestResultsInOk()
        {
            var mock = new Mock <ICreateProductRequestJournal>();

            mock.Setup(m => m.Lookup(It.IsAny <Guid>())).Returns(() =>
                                                                 new JournalEntry <CreateProductRequest>(new CreateProductRequest(), DateTime.UtcNow.AddSeconds(1),
                                                                                                         TransactionState.Started));
            var controller = new CreateProductRequestQueueController(mock.Object);
            var response   = controller.Get(new Guid("12345678901234567890123456789012").ToString());
            var result     = Assert.IsType <OkObjectResult>(response);
            var status     = Assert.IsType <Status>(result.Value);

            Assert.Null(status.Link);
            Assert.NotNull(status.PingAfterDateTime);
            Assert.Equal("pending", status.State);
            Assert.Equal("Your request currently being processed.", status.Message);
        }
コード例 #5
0
        public void CompletedRequestResultsInSeeOther()
        {
            var mock         = new Mock <ICreateProductRequestJournal>();
            var journalEntry = new JournalEntry <CreateProductRequest>(new CreateProductRequest(), DateTime.UtcNow.AddSeconds(1),
                                                                       TransactionState.Completed);

            journalEntry.SetResult("theid");
            mock.Setup(m => m.Lookup(It.IsAny <Guid>())).Returns(() => journalEntry);
            var mockUrlHelper = new Mock <IUrlHelper>(MockBehavior.Strict);

            mockUrlHelper
            .Setup(
                x => x.Action(
                    It.IsAny <UrlActionContext>()
                    )
                )
            .Returns("http://example.com/")
            .Verifiable();

            var controller = new CreateProductRequestQueueController(mock.Object)
            {
                Url = mockUrlHelper.Object,
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };
            var response = controller.Get(new Guid("12345678901234567890123456789012").ToString());
            var result   = Assert.IsType <ObjectResult>(response);

            Assert.Equal((int)HttpStatusCode.SeeOther, result.StatusCode);
            var status = Assert.IsType <Status>(result.Value);

            Assert.NotNull(status.Link);
            Assert.Null(status.PingAfterDateTime);
            Assert.Equal("done", status.State);
            Assert.Equal("Your request has been processed.", status.Message);
        }