public void EditDeliveryPersonShouldReturnUnprocessableEntityIfModelStateIsInvalid()
        {
            // Arrange
            var mock = new Mock <IDeliveryPersonService>();

            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            Controller.ModelState.AddModelError("", "");
            var mockDeliveryPerson = Builder <DeliveryPersonEditModel> .CreateNew().Build();

            // Act
            var result = Controller.Edit(mockDeliveryPerson);

            // Assert
            Assert.AreEqual(422, (int)result.StatusCode);
        }
        public void ListDeliveryPersonsShouldReturnOkIfServiceListReturnsData()
        {
            // Arrange
            var mock = new Mock <IDeliveryPersonService>();

            mock.Setup <IEnumerable <DeliveryPersonViewModel> >(_ => _.List(0))
            .Returns(Builder <DeliveryPersonViewModel> .CreateListOfSize(100).Build());
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();

            // Act
            var result = Controller.List(0);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemple #3
0
        public BasicAuthenticationHandler(
            IOptionsMonitor <AuthenticationSchemeOptions> options,
            ILoggerFactory logger,
            UrlEncoder encoder,
            ISystemClock clock,
            Resources resources,
            IUserService userService,
            IPersonService personService,
            IDeliveryPersonService deliveryPersonService,
            IOrganizationService organizationService)
            : base(options, logger, encoder, clock)
        {
            _userService           = userService;
            _personService         = personService;
            _deliveryPersonService = deliveryPersonService;
            _organizationService   = organizationService;

            _resources = resources;
        }
        public void AddDeliveryPersonShouldReturnInternalServerErrorIfServiceAddReturnsFalse()
        {
            // Arrange
            var mock = new Mock <IDeliveryPersonService>();

            mock.Setup <bool>(_ => _.Add(It.IsAny <DeliveryPersonAddModel>()))
            .Returns(false);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            var mockDeliveryPerson = Builder <DeliveryPersonAddModel> .CreateNew().Build();

            // Act
            var result = Controller.Add(mockDeliveryPerson);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
        public void DeleteDeliveryPersonShouldReturnNotFoundIfServiceReturnsFalse()
        {
            // Arrange
            var mock   = new Mock <IDeliveryPersonService>();
            var mockId = Guid.NewGuid();

            mock.Setup <bool>(_ => _.Delete(mockId))
            .Returns(false);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();

            // Act
            var result = Controller.Delete(mockId);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
        public void EditDeliveryPersonShouldReturnNotFoundIfServiceReturnsFalse()
        {
            // Arrange
            var mock = new Mock <IDeliveryPersonService>();

            mock.Setup <bool>(_ => _.Edit(It.IsAny <DeliveryPersonEditModel>()))
            .Returns(false);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            var mockDeliveryPerson = Builder <DeliveryPersonEditModel> .CreateNew().Build();

            // Act
            var result = Controller.Edit(mockDeliveryPerson);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
        public void GetDeliveryPersonByIdShouldReturnNotFoundIfServiceReturnsNull()
        {
            // Arrange
            var mock   = new Mock <IDeliveryPersonService>();
            var mockId = Guid.NewGuid();

            mock.Setup <DeliveryPersonViewModel>(_ => _.Get(mockId))
            .Returns <DeliveryPersonViewModel>(null);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();

            // Act
            var result = Controller.Get(mockId);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
        public void ListDeliveryPersonsShouldReturnTheSameDataIfServiceListReturnsData()
        {
            // Arrange
            var mock        = new Mock <IDeliveryPersonService>();
            var mockContent = Builder <DeliveryPersonViewModel> .CreateListOfSize(100).Build();

            mock.Setup <IEnumerable <DeliveryPersonViewModel> >(_ => _.List(0))
            .Returns(mockContent);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();

            // Act
            var result = Controller.List(0);
            IEnumerable <DeliveryPersonViewModel> content;

            result.TryGetContentValue <IEnumerable <DeliveryPersonViewModel> >(out content);

            // Assert
            Assert.AreEqual(mockContent, content);
        }
        public void GetDeliveryPersonByIdShouldReturnOkAndTheSameViewModelIfServiceReturnsData()
        {
            // Arrange
            var mock         = new Mock <IDeliveryPersonService>();
            var mockId       = Guid.NewGuid();
            var mockCustomer = Builder <DeliveryPersonViewModel> .CreateNew().Build();

            mock.Setup <DeliveryPersonViewModel>(_ => _.Get(mockId))
            .Returns(mockCustomer);
            Service    = mock.Object;
            Controller = new DeliveryPersonsController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();

            // Act
            var result = Controller.Get(mockId);
            DeliveryPersonViewModel content;

            result.TryGetContentValue <DeliveryPersonViewModel>(out content);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual(mockCustomer, content);
        }
 public DeliveryPersonController(IDeliveryPersonService DeliveryPersonService) :
     base(DeliveryPersonService)
 {
 }
 public DeliveryPersonsController(IDeliveryPersonService service)
 {
     this.Service = service;
 }