public void ContractController_GetAll_ShouldReturnCorrectInt() { var result = _controller.GetAll(); Assert.AreEqual(1, _mockService.CallCount); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <IEnumerable <ContractListItem> >)); }
public void GetAllContractes() { var mock = new Mock <IRepository <Contract> >(); mock.Setup(repo => repo.GetAll()).Returns(GetAllTest()); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <Contract>()).Returns(mock.Object); _contractController = new ContractController(factoryMock.Object); var json = _contractController.GetAll(); var contract = json.Value as List <Contract>; Assert.NotNull(json); Assert.NotNull(contract); Assert.AreEqual(contract.Count, 2); //var mock1 = new Mock<IRepository<Contract>>(); //mock1.Setup(repo => repo.GetAll().FirstOrDefault()).Returns(GetFirstOrDefaultTest(1)); //var factoryMock1 = new Mock<IRepositoryFactory>(); //factoryMock1.Setup(f => f.GetRepository<Contract>()).Returns(mock1.Object); //_contractController = new ContractController(factoryMock1.Object); //json = _contractController.GetAll(); //contract = json.Value as List<Contract>; //Assert.AreEqual(); }
public void Create() { var memoryStore = new List <Contract>(); Contract contractStub = new Contract { Id = 1 }; var mock = new Mock <IRepository <Contract> >(); mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable()); mock.Setup(repo => repo.Create(It.IsAny <Contract>())).Returns((Contract contract) => { contract.Id = 1; memoryStore.Add(contract); return(contract); }); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <Contract>()).Returns(mock.Object); _contractController = new ContractController(factoryMock.Object); var emptyJson = _contractController.GetAll(); Assert.IsNotNull(emptyJson); var emptyStore = emptyJson.Value as List <Contract>; Assert.IsNotNull(emptyStore); Assert.AreEqual(emptyStore.Count, 0); var json = _contractController.Create(contractStub); Assert.IsNotNull(json); var result = json.Value as Contract; Assert.NotNull(result); Assert.AreEqual(result.Id, 1); Assert.AreEqual(result.Address, contractStub.Address); var notEmptyJson = _contractController.GetAll(); Assert.IsNotNull(notEmptyJson); var notEmptyStore = notEmptyJson.Value as List <Contract>; Assert.IsNotNull(notEmptyStore); Assert.AreEqual(notEmptyStore.Count, 1); }