Ejemplo n.º 1
0
        public async void SaveCapsuleIsNullBadRequest()
        {
            // Arrange
            var mock = new Mock <ICapsuleRepository>();
            CapsuleController controller = new CapsuleController(mock.Object);

            // Act
            BadRequestObjectResult result = await controller.SaveCapsule(null) as BadRequestObjectResult;

            // Assert
            Assert.Equal((int?)HttpStatusCode.BadRequest, result?.StatusCode);
            mock.Verify(rep => rep.GetCapsuleByUserAsync(It.IsAny <string>()), Times.Never);
            mock.Verify(rep => rep.SaveCapsuleAsync(It.IsAny <Models.Capsule>()), Times.Never);
            mock.Verify(rep => rep.CreateNewCapsuleAsync(It.IsAny <Models.Capsule>()), Times.Never);
        }
Ejemplo n.º 2
0
        public async void SaveCapsuleThrowsException()
        {
            // Arrange
            var mock = new Mock <ICapsuleRepository>();

            mock.Setup(rep => rep.GetCapsuleByUserAsync(It.IsAny <string>())).Throws <CapsuleDomainException>();
            CapsuleController controller = new CapsuleController(mock.Object);

            // Act & Assert
            Exception ex = await Assert.ThrowsAsync <CapsuleDomainException>(
                async() => await controller.SaveCapsule(new Models.Capsule("Random user"))
                );

            Assert.Equal(expected: typeof(CapsuleDomainException), actual: ex.GetType());
        }
Ejemplo n.º 3
0
        public async void SaveCapsuleOk(Models.Capsule[] capsules)
        {
            // Arrange
            var mock = new Mock <ICapsuleRepository>();

            Models.Capsule capsuleToSave = capsules[0];
            mock.Setup(rep => rep.GetCapsuleByUserAsync(It.IsAny <string>())).Returns(Task <Models.Capsule> .Run(() => capsuleToSave));
            CapsuleController controller = new CapsuleController(mock.Object);

            // Act
            OkObjectResult result = await controller.SaveCapsule(capsuleToSave) as OkObjectResult;

            // Assert
            Assert.Equal((int?)HttpStatusCode.OK, result?.StatusCode);
            mock.Verify(rep => rep.SaveCapsuleAsync(It.IsAny <Models.Capsule>()), Times.Once);
        }