public void TestCrudService() { int expectedId = 2; string readId = "Adan"; string updateId = "Sonny"; MockStorage ms = new MockStorage(); CrudService cs = new CrudService(ms); cs.Create("Adan"); //Adding to NameList cs.Create("Jae"); cs.Create("Tiana"); cs.Delete("test"); //Deleting from NameList Assert.AreEqual(expectedId, ms.NameList.Count); // compare 2 to the Namelist count Assert.AreEqual(readId, ms.Select()); //comparing Adan to value in Select function Assert.AreEqual(expectedId, ms.Update(readId, updateId)); // updating Adan to Sonny Assert.AreEqual(updateId, ms.NameList.Where(n => n == "Sonny").FirstOrDefault()); //Checking to if Sonny exist in NameList }
public virtual async Task <IActionResult> Create(TCreate vm) { if (!ModelState.IsValid) { vm = await GetCreateViewModel(default(TCreate)); return(View(vm)); } await crudService.Create(vm); return(RedirectToAction(nameof(Index))); }
public void Create_ReturnsCreatedElement() { var repositoryMock = new Mock <ICrudRepository>(); repositoryMock.Setup(_ => _.Create(It.IsAny <TestEntity>())).Returns(_entity); var service = new CrudService <TestEntity>(repositoryMock.Object); var result = service.Create(_entity); Assert.Equal(_entity.Id, result.Id); repositoryMock.Verify(_ => _.Create(It.IsAny <TestEntity>()), Times.Once); repositoryMock.Verify(_ => _.SaveChanges(), Times.Once); }
public void TestCrudService() { int expectedId = 3; string expectedString = "Tiana"; string newName = "John"; int count = 2; MockStorage ms = new MockStorage(); CrudService cs = new CrudService(ms); cs.Create("Tiana"); cs.Create("Adan"); cs.Create("Britto"); Assert.AreEqual(expectedString, ms.Read()); Assert.AreEqual(expectedId, ms.Update(expectedString, newName)); Assert.AreEqual(newName, ms.NameList.Where(n => n == "John").FirstOrDefault()); cs.Delete("Britto"); Assert.AreEqual(count, ms.NameList.Count); }