Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void Update_ShouldNotValidate_WhenWorkerNameIsNull()
        {
            //Arrange
            var workerMock = new Mock <IWorkerService>();

            workerMock.Setup(x => x.Update(It.IsAny <string>(), It.IsAny <WorkerDto>()));
            var controller = new DownTimeAlerterController(workerMock.Object);

            controller.ModelState.AddModelError("test", "test error");

            //Act
            controller.Update(It.IsAny <string>(), new DownTimeAlerterViewModel());

            //Assert
            workerMock.Verify(x => x.Update(It.IsAny <string>(), It.IsAny <WorkerDto>()), Times.Never);
            Assert.IsFalse(controller.ModelState.IsValid);
        }