public void GetWorkers_Test() { //Arrange IQueryable <WorkersModel> worker = new List <WorkersModel> { new WorkersModel { Id = 1, Name = "Diana", Surname = "Vahomskaya", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Admin", Place = "לעס", Culture = "ru" } }.AsQueryable(); var MoqSet = new Mock <DbSet <WorkersModel> >(); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.Provider).Returns(worker.Provider); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.Expression).Returns(worker.Expression); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.ElementType).Returns(worker.ElementType); MoqSet.As <IQueryable <WorkersModel> >().Setup(m => m.GetEnumerator()).Returns(worker.GetEnumerator()); var MoqContext = new Mock <WorkersContext>(); MoqContext.Setup(c => c.WorkersTable).Returns(MoqSet.Object); //Act var MoqRepo = new SQLrequest(MoqContext.Object, new Logger <SQLrequest>(new LoggerFactory())); var GetWorkers = MoqRepo.GetWorkers_workers(); var GetWorkersId = MoqRepo.GetWorkers(1); var GetWorkersLogin = MoqRepo.GetLogin("di_vahomik"); var result = MoqRepo.NewWorkers(new WorkersModel { Id = 6, Name = "Diana", Surname = "Vahomskaya", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Admin", Place = "לעס", Culture = "ru" }); //Assert Assert.AreEqual(1, GetWorkers.Count()); Assert.IsNotNull(GetWorkersId); Assert.IsNotNull(GetWorkersLogin); Assert.True(result); }
public void Edit_Worker_Test() { //Arrange DbContextOptions <WorkersContext> opt; var builder = new DbContextOptionsBuilder <WorkersContext>(); builder.UseInMemoryDatabase(databaseName: "database_test"); opt = builder.Options; var MoqContext = new WorkersContext(opt); var MoqRepo = new SQLrequest(MoqContext, new Logger <SQLrequest>(new LoggerFactory())); MoqRepo.Create(new WorkersModel { Id = 2, Name = "Mariya", Surname = "Polovinkina", Email = "*****@*****.**", Login = "******", Password = "******", Role = "Worker", Place = "לודאפמם", Culture = "ru" }); if (MoqRepo.GetWorkers(2) != null) { var WorkerEdit = MoqRepo.GetWorkers(2); WorkerEdit.Name = "Dima"; MoqRepo.Edit(WorkerEdit); } var worker = MoqRepo.GetWorkers_workers(); var workerEdit = MoqRepo.GetWorkers(2); Assert.AreEqual(2, worker.Count()); Assert.AreEqual("Dima", workerEdit.Name); }