Esempio n. 1
0
        public void PostCaseValidType()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Returns(oneType);
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as OkObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(typeDTO, value);
        }
Esempio n. 2
0
        public void PostCaseErrorInDB()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new DataAccessException("Error: Could not add entity to DB"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Could not add entity to DB");
            Assert.AreEqual(okResult.StatusCode, 500);
        }
Esempio n. 3
0
        public void PostCaseInvalidTypeEmptyFields()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new BusinessLogicException("Error: Type had empty fields"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Type had empty fields");
            Assert.AreEqual(okResult.StatusCode, 400);
        }
Esempio n. 4
0
        public void PostCaseInvalidTypeAlreadyRegistered()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new BusinessLogicException("Error: Type with same name associated to this topic already registered"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Type with same name associated to this topic already registered");
            Assert.AreEqual(okResult.StatusCode, 400);
        }