public async Task Post(Func <List <TEntity> > SetupList, Func <TKey, TEntity> CreateEntity, Func <TEntity, bool> TestEditEntity) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var iEntitiesCount = oRepository.Object.Entities.Count(); var oEntityLastOld = oRepository.Object.Entities.OrderByDescending(x => x.Id).FirstOrDefault(); // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); dynamic z = iEntitiesCount; dynamic zz = 0; TEntity oEntity = CreateEntity(zz); // Act IHttpActionResult result = await controller.Post(oEntity) as IHttpActionResult; var oEntityNew = oRepository.Object.Entities.OrderByDescending(x => x.Id).FirstOrDefault(); // Assert //HttpResponseMessage response2 = result;// await result.ExecuteAsync(); //if (response2.IsSuccessStatusCode) //{ // TEntity resultEntity = await response2.Content.ReadAsAsync<TEntity>(); //} dynamic oEntityLastOldId = oEntityLastOld.Id; Assert.AreEqual(oEntityLastOldId + 1, oEntity.Id); Assert.AreEqual(iEntitiesCount + 1, oRepository.Object.Entities.Count()); Assert.IsTrue(TestEditEntity(oEntityNew)); }
public async Task Put(Func <List <TEntity> > SetupList, Func <TEntity, TEntity> EditEntity, Func <TEntity, bool> TestEditEntity) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var oEntity = oRepository.Object.Entities.FirstOrDefault(); var oEntityId = oEntity.Id; // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); HttpConfiguration configuration = new HttpConfiguration(); HttpRequestMessage request = new HttpRequestMessage(); controller.Request = request; controller.Request.Properties["MS_HttpConfiguration"] = configuration; var oEntityDelta = EditEntity(oEntity); // Act IHttpActionResult result = await controller.Put(oEntity.Id, oEntityDelta) as IHttpActionResult; var oEntityNew = oRepository.Object.Entities.FirstOrDefault(); // Assert Assert.AreEqual(oEntityId, oEntityNew.Id); Assert.IsTrue(TestEditEntity(oEntityNew)); }
public async void GetById(Func <List <TEntity> > SetupList) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var oEntity = oRepository.Object.Entities.FirstOrDefault(); // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); // Act IHttpActionResult result = await controller.Get(oEntity.Id); // Assert Assert.IsNotNull(result); //Assert.AreEqual(oEntity, result.ToString); }
public void Get(Func <List <TEntity> > SetupList) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var iEntitiesCount = oRepository.Object.Entities.Count(); // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); // Act IQueryable <TEntity> result = controller.Get() as IQueryable <TEntity>; List <TEntity> lEntitiesController = result.ToList() as List <TEntity>; // Assert Assert.IsNotNull(result); Assert.AreEqual(iEntitiesCount, lEntitiesController.Count); }
public async void EditPost(Func <List <TEntity> > SetupList, ParamsFunc TestEditEntity) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var oEntity = oRepository.Object.Entities.FirstOrDefault(); var oEntityLastOldId = oEntity.Id; // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); TestEditEntity(oEntity); // Act ViewResult result = await controller.Edit(oEntityLastOldId) as ViewResult; // Assert Assert.AreEqual(oEntityLastOldId, oEntity.Id); }
public async void Index(Func <List <TEntity> > SetupList) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var iEntitiesCount = oRepository.Object.Entities.Count(); // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); // Act ViewResult result = await controller.Index() as ViewResult; List <TEntity> lEntitiesController = result.Model as List <TEntity>; // Assert Assert.IsNotNull(result); Assert.AreEqual(iEntitiesCount, lEntitiesController.Count); }
public async Task Delete(Func <List <TEntity> > SetupList) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var iEntitiesCount = oRepository.Object.Entities.Count(); var oEntityLastOld = oRepository.Object.Entities.OrderByDescending(x => x.Id).FirstOrDefault(); var oEntityLastOldId = oEntityLastOld.Id; // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); // Act IHttpActionResult result = await controller.Delete(oEntityLastOld.Id) as IHttpActionResult; // Assert Assert.AreEqual(iEntitiesCount - 1, oRepository.Object.Entities.Count()); }
public async void Create(Func <List <TEntity> > SetupList, Func <TEntity> TestCreator) { var lEntities = SetupList(); var oRepository = GenericMethods.SetupRepository <TKey, TEntity, IRepository <TKey, TEntity> >(lEntities); var oUnitOfWork = GenericMethods.SetupUnitOfWork <TKey, TEntity, IRepository <TKey, TEntity> >(oRepository); var iEntitiesCount = oRepository.Object.Entities.Count(); var oEntityLastOld = oRepository.Object.Entities.OrderByDescending(x => x.Id).FirstOrDefault(); // Arrange TController controller = (TController)Activator.CreateInstance(typeof(TController), oUnitOfWork.Object); TEntity oEntity = TestCreator(); // Act ViewResult result = await controller.Create(oEntity) as ViewResult; // Assert dynamic z = oEntityLastOld.Id; Assert.AreEqual(z + 1, oEntity.Id); Assert.AreEqual(iEntitiesCount + 1, oRepository.Object.Entities.Count()); }