Example #1
0
        public async void PostCannotAddDeliveryForSameOrderTest()
        {
            var controller = new DeliveryController(deliveryService, mapper);;
            var model      = new CreateDeliveryViewModel()
            {
                OrderId = 1,
            };

            var response = await controller.Post(model);

            var okResult = response as BadRequestObjectResult;

            Assert.NotNull(okResult);
            Assert.Equal(400, okResult.StatusCode);
            Assert.NotNull(okResult.Value);
        }
Example #2
0
        public async void PostCannotAddDeliveryForForExpiredEndTimeTest()
        {
            var controller = new DeliveryController(deliveryService, mapper);;
            var model      = new CreateDeliveryViewModel()
            {
                OrderId   = 5,
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(-5)
            };

            var response = await controller.Post(model);

            var okResult = response as BadRequestObjectResult;

            Assert.NotNull(okResult);
            Assert.Equal(400, okResult.StatusCode);
            Assert.NotNull(okResult.Value);
        }
Example #3
0
        public async void PostWithRelatedDataTest()
        {
            var relatedDeliveryService = new DeliveryService(dbSqlite);

            dbSqlite.Partners.Add(new Partner()
            {
                Name     = "Ikea",
                Password = "******"
            });
            dbSqlite.Users.Add(new User
            {
                FirstName = "John",
                LastName  = "Doe",
                Email     = "*****@*****.**",
                Address   = "Test Street, London",
                Phone     = "0845345",
                Password  = "******"
            });
            dbSqlite.SaveChanges();

            var controller = new DeliveryController(relatedDeliveryService, mapper);
            var model      = new CreateDeliveryViewModel()
            {
                OrderId     = 30,
                RecipientId = 1,
                PartnerId   = 1,
                StartTime   = DateTime.Now.AddDays(2).AddHours(7),
                EndTime     = DateTime.Now.AddDays(2).AddHours(10),
            };
            var response = await controller.Post(model);

            var okResult = response as OkObjectResult;

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
            Assert.NotNull(okResult.Value);

            var delivery = okResult.Value as DeliveryViewModel;

            Assert.NotEqual(0, delivery.Id);
            Assert.NotNull(delivery.AccessWindow);
            Assert.NotNull(delivery.Recipient);
            Assert.NotNull(delivery.Order);
        }