public void Update_ShouldValidate_WhenUpdateWorker() { //Arrange var provider = base.BuildServiceProvider(); var workerService = provider.GetService <IWorkerService>(); var controller = new DownTimeAlerterController(workerService); var createModel = new DownTimeAlerterViewModel() { Name = "test", Email = "*****@*****.**", Interval = 1000, Url = "google.com", NotificationType = (int)NotificationType.Email }; var updateModel = new DownTimeAlerterViewModel() { Name = "test2", Email = "*****@*****.**", Interval = 2000, Url = "google.com", NotificationType = (int)NotificationType.Email }; //Act controller.Create(createModel); controller.Update(createModel.Name, updateModel); //Assert Assert.AreEqual(1, workerService.List().Count()); Assert.AreEqual(updateModel.Name, workerService.Get(updateModel.Name).Name); }
public void Create_ShouldNotValidate_WhenCreateWorkerModelIsNull() { //Arrange¬ var workerMock = new Mock <IWorkerService>(); workerMock.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <WorkerDto>())); var controller = new DownTimeAlerterController(workerMock.Object); controller.ModelState.AddModelError("test", "test error"); //Act controller.Create(new DownTimeAlerterViewModel()); //Assert workerMock.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <WorkerDto>()), Times.Never); Assert.IsFalse(controller.ModelState.IsValid); }
public void Delete_ShouldValidate_WhenDeleteWorker() { //Arrange var provider = base.BuildServiceProvider(); var workerService = provider.GetService <IWorkerService>(); var controller = new DownTimeAlerterController(workerService); var createModel = new DownTimeAlerterViewModel() { Name = "test", Email = "*****@*****.**", Interval = 1000, Url = "google.com", NotificationType = (int)NotificationType.Email }; //Act controller.Create(createModel); controller.Delete(createModel.Name); //Assert Assert.IsNull(workerService.Get(createModel.Name)); }