public void GetAllTypesCaseNotEmpty() { var types = new List <Type>(); types.Add(oneType); types.Add(anotherType); var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.GetAll()).Returns(types); var typeController = new TypeController(typeLogicMock.Object); var typeModels = new List <TypeDTO>(); foreach (Type type in types) { TypeDTO tm = new TypeDTO(type); typeModels.Add(tm); } var result = typeController.Get(); var okResult = result as OkObjectResult; var value = okResult.Value as List <TypeDTO>; typeLogicMock.VerifyAll(); for (int i = 0; i < typeModels.Count; i++) { Assert.AreEqual(value[i], typeModels[i]); } }
public void GetAllTypesCaseErrorInDB() { var types = new List <Type>(); types.Add(oneType); types.Add(anotherType); var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.GetAll()).Throws( new DataAccessException("Error: could not get Table's elements")); var typeController = new TypeController(typeLogicMock.Object); var typeModels = new List <TypeDTO>(); foreach (Type type in types) { TypeDTO tm = new TypeDTO(type); typeModels.Add(tm); } var result = typeController.Get(); var okResult = result as ObjectResult; var value = okResult.Value; typeLogicMock.VerifyAll(); Assert.AreEqual(value, "Error: could not get Table's elements"); Assert.AreEqual(okResult.StatusCode, 500); }
public void GetTypeByIdCaseErrorInDB() { var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws( new DataAccessException("Error: could not retrieve Entity")); var typeController = new TypeController(typeLogicMock.Object); var result = typeController.Get(oneType.Id); var okResult = result as ObjectResult; var value = okResult.Value; typeLogicMock.VerifyAll(); Assert.AreEqual(value, "Error: could not retrieve Entity"); Assert.AreEqual(okResult.StatusCode, 500); }
public void GetTypeByIdCaseNotExist() { var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws( new BusinessLogicException("Error: Invalid ID, Type does not exist")); var typeController = new TypeController(typeLogicMock.Object); var result = typeController.Get(oneType.Id); var okResult = result as ObjectResult; var value = okResult.Value; typeLogicMock.VerifyAll(); Assert.AreEqual(value, "Error: Invalid ID, Type does not exist"); Assert.AreEqual(okResult.StatusCode, 404); }
public void GetTypeByIdCaseExist() { var typeDTO = new TypeDTO(oneType); var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(oneType); var typeController = new TypeController(typeLogicMock.Object); var result = typeController.Get(oneType.Id); var okResult = result as OkObjectResult; var value = okResult.Value as TypeDTO; typeLogicMock.VerifyAll(); Assert.AreEqual(typeDTO, value); }
public void GetAllTypesCaseEmpty() { var types = new List <Type>(); var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict); typeLogicMock.Setup(m => m.GetAll()).Returns(types); var typeController = new TypeController(typeLogicMock.Object); var result = typeController.Get(); var okResult = result as OkObjectResult; var value = okResult.Value as List <TypeDTO>; typeLogicMock.VerifyAll(); for (int i = 0; i < types.Count; i++) { Assert.AreEqual(value[i], types[i]); } }