Example #1
0
        public async void CannotSendInvalidCapsuleDeliveryDetails()
        {
            // Arrange
            var message = new Message()
            {
                Id = int.MaxValue
            };
            var capsule = new Capsule(Guid.NewGuid().ToString());

            capsule.AddMessage(message);
            var delivery = new Delivery(capsule);

            var capsuleSrvMock = new Mock <ICapsuleService>();

            capsuleSrvMock.Setup(srv => srv.GetCapsuleByUserAsync()).Returns(() => Task <Capsule> .Run(() => capsule));

            var deliverySrvMock = new Mock <IDeliveryService>();

            deliverySrvMock.Setup(srv => srv.DeliverCapsuleAsync(It.IsAny <Delivery>())).Verifiable();

            var controller = new DeliveryController(capsuleService: capsuleSrvMock.Object, deliveryService: deliverySrvMock.Object);

            controller.ModelState.AddModelError("error", "error");

            // Act
            ViewResult result = await controller.SendCapsule(delivery) as ViewResult;


            // Assert
            Assert.IsType <ViewResult>(result);
            Assert.Equal("Index", result?.ViewName);
            deliverySrvMock.Verify(srv => srv.DeliverCapsuleAsync(It.IsAny <Delivery>()), Times.Never);
            Assert.False(result?.ViewData?.ModelState.IsValid);
        }
Example #2
0
        public async void CanSendCapsuleDelivery()
        {
            // Arrange
            var message = new Message()
            {
                Id = int.MaxValue
            };
            var capsule = new Capsule(Guid.NewGuid().ToString());

            capsule.AddMessage(message);
            var delivery = new Delivery(capsule);

            delivery.When   = DateTime.Now.AddDays(+1);
            delivery.ToWhom = "Random User";

            var capsuleSrvMock = new Mock <ICapsuleService>();

            capsuleSrvMock.Setup(srv => srv.GetCapsuleByUserAsync()).Returns(() => Task <Capsule> .Run(() => capsule));

            var deliverySrvMock = new Mock <IDeliveryService>();

            deliverySrvMock.Setup(srv => srv.DeliverCapsuleAsync(It.IsAny <Delivery>())).Returns(() => Task <Capsule> .Run(() => { return; }));

            var controller = new DeliveryController(capsuleService: capsuleSrvMock.Object, deliveryService: deliverySrvMock.Object);

            // Act
            RedirectToActionResult result = await controller.SendCapsule(delivery) as RedirectToActionResult;

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Delivery", result?.ControllerName);
            Assert.Equal(nameof(controller.Success), result?.ActionName);
            deliverySrvMock.Verify(srv => srv.DeliverCapsuleAsync(It.IsAny <Delivery>()), Times.Once);
        }