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); }
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); }
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); }
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); }