Esempio n. 1
0
        public void UpdateHeader_With_ValidCommand_ForFoundPatron_IsPublished_AndReturnsAcceptedResult_WithLocation()
        {
            Guid patronId          = MakeTestPatron();
            UpdatePatronHeader cmd = new UpdatePatronHeader("Patron Web Test", TestHelper.Now)
            {
                PatronId    = patronId,
                DisplayName = "Updated Patron Display Name",
                IsAnonymous = false,
                PatronType  = "Patron Updated"
            };

            cmdQueueMock.Setup(c => c.Publish(It.IsAny <UpdatePatronHeader>())).Verifiable();

            var mockUrlHelper = new Mock <IUrlHelper>(MockBehavior.Strict);
            Expression <Func <IUrlHelper, string> > urlSetup = m => m.Action(It.Is <UrlActionContext>(uac => uac.Action == "Get" && GetId(uac.Values) == patronId));

            mockUrlHelper.Setup(urlSetup).Returns("a/mock/url/for/testing").Verifiable();

            AcceptedResult result;

            using (var controller = new PatronController(cmdQueue, dbContextFactory)
            {
                Url = mockUrlHelper.Object
            })
            {
                result = controller.UpdateHeader(cmd.PatronId, cmd) as AcceptedResult;
            }

            Assert.IsType <AcceptedResult>(result);
            Assert.Equal(patronId, cmd.PatronId);
            mockUrlHelper.Verify(urlSetup, Times.Once());
            cmdQueueMock.Verify(c => c.Publish(It.IsAny <UpdatePatronHeader>()), Times.Once());
            Assert.Equal("a/mock/url/for/testing", result.Location);
        }
Esempio n. 2
0
        public void UpdateHeader_With_NullCommand_Returns_BadRequest()
        {
            BadRequestObjectResult result;

            using (PatronController controller = new PatronController(cmdQueue, dbContextFactory))
            {
                result = controller.UpdateHeader(Guid.NewGuid(), null) as BadRequestObjectResult;
            }

            cmdQueueMock.Verify(c => c.Publish(It.IsAny <ICommand>()), Times.Never());
            Assert.IsType <BadRequestObjectResult>(result);
            Assert.IsType <SerializableError>(result.Value);
        }
Esempio n. 3
0
        public void UpdateHeader_With_ValidCommand_ButPatronNotFound_Returns_NotFound()
        {
            NotFoundObjectResult result;
            UpdatePatronHeader   command;

            using (PatronController controller = new PatronController(cmdQueue, dbContextFactory))
            {
                command = new UpdatePatronHeader("Patron Web Test", TestHelper.Now)
                {
                    PatronId = Guid.NewGuid()
                };

                result = controller.UpdateHeader(command.PatronId, command) as NotFoundObjectResult;
            }

            cmdQueueMock.Verify(c => c.Publish(It.IsAny <ICommand>()), Times.Never());
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.IsType <Guid>(result.Value);
            Assert.Equal(command.PatronId, (Guid)result.Value);
        }
Esempio n. 4
0
        public void UpdateHeader_With_ModelStateError_Returns_BadRequest()
        {
            BadRequestObjectResult result;

            using (PatronController controller = new PatronController(cmdQueue, dbContextFactory))
            {
                controller.ModelState.AddModelError("DisplayName", "Display Name error is being tested.");
                var command = new UpdatePatronHeader("Patron Web Test", TestHelper.Now)
                {
                    PatronId    = Guid.NewGuid(),
                    DisplayName = string.Join(" - ", Enumerable.Repeat("A Really Long String", 1000))
                };

                result = controller.UpdateHeader(command.PatronId, command) as BadRequestObjectResult;
            }

            cmdQueueMock.Verify(c => c.Publish(It.IsAny <ICommand>()), Times.Never());
            Assert.IsType <BadRequestObjectResult>(result);
            Assert.IsType <SerializableError>(result.Value);
        }
Esempio n. 5
0
        public void UpdateHeader_With_ValidCommand_ButMismatchedPatronIds_Returns_BadRequest()
        {
            UpdatePatronHeader     command;
            BadRequestObjectResult result;
            Guid newPatronGuid          = Guid.NewGuid();
            Guid somethingDifferentGuid = Guid.NewGuid();

            using (PatronController controller = new PatronController(cmdQueue, dbContextFactory))
            {
                command = new UpdatePatronHeader("Patron Web Test", TestHelper.Now)
                {
                    PatronId = newPatronGuid
                };

                result = controller.UpdateHeader(somethingDifferentGuid, command) as BadRequestObjectResult;
            }

            cmdQueueMock.Verify(c => c.Publish(It.IsAny <ICommand>()), Times.Never());
            Assert.NotEqual(newPatronGuid, somethingDifferentGuid);
            Assert.IsType <BadRequestObjectResult>(result);
            Assert.IsType <SerializableError>(result.Value);
        }